From db8f237a2705a809d66652e76cf8cf00bc4f7e12 Mon Sep 17 00:00:00 2001 From: Peter Olson Date: Sat, 5 Jan 2013 19:41:28 -0800 Subject: Add inverted flag support to TrapDoor. Fixes BUKKIT-3390 --- src/main/java/org/bukkit/material/TrapDoor.java | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bukkit/material/TrapDoor.java b/src/main/java/org/bukkit/material/TrapDoor.java index 5041a5c1..54073224 100644 --- a/src/main/java/org/bukkit/material/TrapDoor.java +++ b/src/main/java/org/bukkit/material/TrapDoor.java @@ -43,6 +43,26 @@ public class TrapDoor extends SimpleAttachableMaterialData implements Openable { setData(data); } + /** + * Test if trapdoor is inverted + * @return true if inverted (top half), false if normal (bottom half) + */ + public boolean isInverted() { + return ((getData() & 0x8) != 0); + } + + /** + * Set trapdoor inverted state + * @param inv - true if inverted (top half), false if normal (bottom half) + */ + public void setInverted(boolean inv) { + int dat = getData() & 0x7; + if (inv) { + dat |= 0x8; + } + setData((byte) dat); + } + public BlockFace getAttachedFace() { byte data = (byte) (getData() & 0x3); @@ -65,7 +85,7 @@ public class TrapDoor extends SimpleAttachableMaterialData implements Openable { } public void setFacingDirection(BlockFace face) { - byte data = (byte) (getData() & 0x4); + byte data = (byte) (getData() & 0xC); switch (face) { case SOUTH: @@ -84,11 +104,11 @@ public class TrapDoor extends SimpleAttachableMaterialData implements Openable { @Override public String toString() { - return (isOpen() ? "OPEN " : "CLOSED ") + super.toString() + " with hinges set " + getAttachedFace(); + return (isOpen() ? "OPEN " : "CLOSED ") + super.toString() + " with hinges set " + getAttachedFace() + (isInverted() ? " inverted" : ""); } @Override public TrapDoor clone() { return (TrapDoor) super.clone(); } -} \ No newline at end of file +} -- cgit v1.2.3