[SOLVED]Power a piston without redstone

Discussion in 'Plugin Development' started by travja, Sep 12, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    travja

    I basically need to power a piston without any nearby redstone.... is there a way to power the piston itself?
     
  2. Offline

    The_Coder

    Might want to start by sending a udate to that piston.
     
  3. Offline

    stirante

    Probably this:
    Code:
        public void extendPiston(Block block){
            PistonBaseMaterial block1 = (PistonBaseMaterial) block.getState();
            block1.setPowered(true);
        }
     
  4. Offline

    stelar7

    casting the piston to a PistonBaseMaterial and call the setPowered method migth work
     
  5. Offline

    travja

    I think I tried this stirante but I didn't include .getState() would that affect it?
     
  6. Offline

    stelar7

    yes, you need to cast the state/data or it would give an exception
     
  7. Offline

    travja

    I still get a ClassCastExeption on the line were I define the piston
     
  8. Offline

    skore87

    Pistons normally retract if there's no input. The only reason I'm sure of it is I was testing the retract a week ago for a piston-grief protection and the event would fire the next tick again if the event was cancelled. So wouldn't you need to continually set the power to the piston either with schedulers or preferably checking to see if it is the correct piston on the retract event?
     
  9. Offline

    travja

    I'm dropping an item under the piston, getting the relative, checking if it's a piston, if so, casting it to PistonBaseMaterial and then making it powered, all I want is for it to be powered enough to go down and then back up, it's just that it sends ClassCastException when I cast it to PistonBastMaterial even if I check if the relative.getType()== Material.PISTON_BASE
     
  10. Offline

    skore87

    Does this not work for you? I believe the piston base is castable from the materialdata, not just the state.

    Code:
    PistonBaseMaterial pistonBase = (PistonBaseMaterial) block.getState().getData();
     
  11. Offline

    travja

    That makes more sense, I'll try that.

    Also.. using the piston.setPowered(true) it doesn't seem to update, even if I run b.getState().update()

    Anyone know how I can update the piston so it shows as extended, cause piston.setPowered(true) isn't making it look powered...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  12. Offline

    skore87

    Just to see if it works, try placing a block on it while it is retracted and then make it extend via that method to see if it actually works and is just too fast to see?
     
  13. Offline

    travja

    Still not working..... there is no update even though I added debugging to check if it says it's powered... which it does say...

    Can someone help me?

    Anyone got any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  14. Offline

    Lolmewn

    If you know of plugins doing this you could ask the authors of those plugins how they did it.
     
  15. Offline

    travja

    Lolmewn I don't... that's why I'm posting here.

    Anyone know of anything that will work for this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  16. Offline

    travja

    Bump.. I need to figure this out...

    Bump this would be really nice to find out

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  17. Offline

    Giant

    what you could try is power the block that is below the piston, so it has an input?
     
    MM1990d likes this.
  18. Offline

    travja

    I'll try that!

    Umm.... there is no method to power the lower block...

    This is what I got to work
    Code:java
    1. piston.setPowered(true);
    2. b.setData(piston.getData());
    3. l.setType(Material.PISTON_EXTENSION);
    4. PistonExtensionMaterial pe = (PistonExtensionMaterial) l.getState().getData();
    5. l.setData(pe.getData());
    6. l.getState().update();
    7. b.getState().update();


    It plays the sound effect too! The piston is extended for a split second.... probably like 10 ticks so if you add a scheduler to it you can make it act like it was powered with a button.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page