How to open a door?

Discussion in 'Plugin Development' started by DxDy, Apr 22, 2014.

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

    DxDy

    Now that the Door API is deprecated, how do I do it?

    Code:java
    1.  
    2.  
    3. byte dataValue = block.getState().getRawData();
    4.  
    5. if(designatedState) // << should the door be open?
    6. dataValue |= 1 << 1;
    7. else
    8. dataValue &= ~(1 << 1);
    9.  
    10. block.getState().setRawData(dataValue);
    11. block.setData(dataValue);
    12. block.getState().update();
    13.  


    Block is definitely the block at the bottom, which according to this should work.

    Any help would be appreciated.
     
  2. Offline

    Slikey

    DxDy likes this.
  3. Offline

    DxDy

    EDIT: Works now. Had forgotten to change the isOpen. Thanks for your help :)

    Thanks for the link.

    It actually worked to reconstruct the opening. However, when I try to close it:

    Code:java
    1. // Bukkit has: getData() & ~0x4
    2. // I have:
    3. dataValue = (byte) (dataValue & ~0x4);


    I'm kind of nonplussed on how this can't work ..
     
  4. Offline

    CoolJoni

    I have the same problem
     
  5. Offline

    Slikey

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

    & is the AND Operator and ~ inverts a byte

    if dataValue is 01011000 this will happen:
    0x4 = 0000 0100
    ~0x4 = 1111 1011
    dataValue & ~0x4 = 0101 1000 & 1111 1011 = 0101 1000

    in fact.. i don't know the value of dataValue..

    EDIT:
    Misunderstood your last post^^ Sorry. Glad it works.. :)
     
  6. Offline

    ZeusAllMighty11

    Or you could cast 'door' to the blockstate.. and set the status to powered or 'open'
     
  7. Offline

    xize

    best way is to cast Openable though, the Door cast is probably deprecated afaik.
     
Thread Status:
Not open for further replies.

Share This Page