How to close a fence gate?

Discussion in 'Plugin Development' started by olsyboy, Aug 24, 2015.

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

    olsyboy

    So, I can open a fence gate:
    Code:
    if(block.getType() == Material.SPRUCE_FENCE_GATE) {
                            bl.add(block.getLocation());
                            block.setData((byte) 4);
                        }
    But I have no idea how to close it!

    Thanks for any help!
     
  2. Search for the data value for a closed fence gate just you did it to open it?
     
  3. Offline

    olsyboy

    it is 0, but that does not work

    http://minecraft.gamepedia.com/Fence_Gate#Data_values

    My code is still not working, for some reason... I dont know how to get the '0' of bytes..

    Can anyone help?

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Aug 25, 2015
  4. Offline

    lubbs31

    Isn't it the durability... I might be wrong though.
     
  5. Offline

    olsyboy

    On the page I linked to earlier, it has data value to open or shut the gates.

    But I cannot shut them.
    I want them to stay in the same position, just open and shut.
     
  6. Offline

    finalblade1234

    @olsyboy
    I'm not 100% sure, but you could probably use BlockState:
    BlockState bS = yourblock.getState();bS.setRawData((byte) 0);bS.update();
     
  7. Offline

    teej107

    @olsyboy Perhaps casting the fence gate Block to an actual Gate will be easier because of its methods that it includes. http://jd.bukkit.org/org/bukkit/material/Gate.html
    I think your problem with the first attempt is that you didn't call #update() on the block. I don't know if that'll make a difference but you should call #update() after changing the Gate.
     
  8. Offline

    lilian58660

  9. Offline

    au2001

    @olsyboy Use Block#getState() then cast it to Openable if it can be casted.
    To open it, use: Openable#setOpen(true);
    And to close it:Openable#setOpen(false);

    It will work for any direction, because here if you put your gate in the other direction it will rotate it...
     
Thread Status:
Not open for further replies.

Share This Page