diff options
author | Xor Boole <mcyoung@mit.edu> | 2015-06-19 12:50:44 -0400 |
---|---|---|
committer | md_5 <git@md-5.net> | 2015-06-28 08:48:23 +1000 |
commit | 0facd12906843a2309c3fe0bfb6f5bc4fad63517 (patch) | |
tree | 5c7f946ee3e34e1c1e646f9b32eeb21f188afe3c /src/main/java | |
parent | d29af24528428c7763b3dd32e26e07e5d12fae68 (diff) | |
download | bukkit-0facd12906843a2309c3fe0bfb6f5bc4fad63517.tar bukkit-0facd12906843a2309c3fe0bfb6f5bc4fad63517.tar.gz bukkit-0facd12906843a2309c3fe0bfb6f5bc4fad63517.tar.lz bukkit-0facd12906843a2309c3fe0bfb6f5bc4fad63517.tar.xz bukkit-0facd12906843a2309c3fe0bfb6f5bc4fad63517.zip |
Retrofit Door in order to work with modern Minecraft doors.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 12 | ||||
-rw-r--r-- | src/main/java/org/bukkit/material/Door.java | 67 |
2 files changed, 49 insertions, 30 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 9321f8e1..3230f6d8 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -255,12 +255,12 @@ public enum Material { BIRCH_FENCE(189), JUNGLE_FENCE(190), DARK_OAK_FENCE(191), - ACACIA_FENCE(192), - SPRUCE_DOOR(193), - BIRCH_DOOR(194), - JUNGLE_DOOR(195), - ACACIA_DOOR(196), - DARK_OAK_DOOR(197), + ACACIA_FENCE(192, Door.class), + SPRUCE_DOOR(193, Door.class), + BIRCH_DOOR(194, Door.class), + JUNGLE_DOOR(195, Door.class), + ACACIA_DOOR(196, Door.class), + DARK_OAK_DOOR(197, Door.class), // ----- Item Separator ----- IRON_SPADE(256, 1, 250), IRON_PICKAXE(257, 1, 250), diff --git a/src/main/java/org/bukkit/material/Door.java b/src/main/java/org/bukkit/material/Door.java index 0c5b52f0..27bb6814 100644 --- a/src/main/java/org/bukkit/material/Door.java +++ b/src/main/java/org/bukkit/material/Door.java @@ -6,10 +6,19 @@ import org.bukkit.block.BlockFace; /** * Represents a door. * - * @deprecated No longer functions. Do not use. + * This class was previously deprecated, but has been retrofitted to + * work with modern doors. Some methods are undefined dependant on <code>isTopHalf()</code> + * due to Minecraft's internal representation of doors. */ -@Deprecated public class Door extends MaterialData implements Directional, Openable { + + // This class breaks API contracts on Directional and Openable because + // of the way doors are currently implemented. Beware! + + /** + * @deprecated Artifact of old API, equivalent to new <code>Door(Material.WOODEN_DOOR);</code> + */ + @Deprecated public Door() { super(Material.WOODEN_DOOR); } @@ -48,17 +57,15 @@ public class Door extends MaterialData implements Directional, Openable { } /** - * @deprecated Does not work (correctly) anymore + * Result is undefined if <code>isTopHalf()</code> is true. */ - @Deprecated public boolean isOpen() { return ((getData() & 0x4) == 0x4); } /** - * @deprecated Does not work (correctly) anymore + * Set whether the door is open. Undefined if <code>isTopHalf()</code> is true. */ - @Deprecated public void setOpen(boolean isOpen) { setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4))); } @@ -74,30 +81,18 @@ public class Door extends MaterialData implements Directional, Openable { * Configure this part of the door to be either the top or the bottom half * * @param isTopHalf True to make it the top half. - * @deprecated Shouldn't be used anymore */ - @Deprecated public void setTopHalf(boolean isTopHalf) { setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8))); } /** * @return BlockFace.SELF - * @deprecated Does not work (correctly) anymore + * @deprecated This method should not be used; use hinge and facing accessors instead. */ @Deprecated public BlockFace getHingeCorner() { - byte d = getData(); - - if ((d & 0x3) == 0x3) { - return BlockFace.NORTH_WEST; - } else if ((d & 0x1) == 0x1) { - return BlockFace.SOUTH_EAST; - } else if ((d & 0x2) == 0x2) { - return BlockFace.SOUTH_WEST; - } - - return BlockFace.NORTH_EAST; + return BlockFace.SELF; } @Override @@ -108,13 +103,17 @@ public class Door extends MaterialData implements Directional, Openable { /** * Set the direction that this door should is facing. * + * Undefined if <code>isTopHalf()</code> is true. + * * @param face the direction - * @deprecated Does not work (correctly) anymore */ - @Deprecated public void setFacingDirection(BlockFace face) { byte data = (byte) (getData() & 0x12); switch (face) { + case WEST: + data |= 0x0; + break; + case NORTH: data |= 0x1; break; @@ -133,10 +132,10 @@ public class Door extends MaterialData implements Directional, Openable { /** * Get the direction that this door is facing. * + * Undefined if <code>isTopHalf()</code> is true. + * * @return the direction - * @deprecated Does not work (correctly) anymore */ - @Deprecated public BlockFace getFacing() { byte data = (byte) (getData() & 0x3); switch (data) { @@ -155,6 +154,26 @@ public class Door extends MaterialData implements Directional, Openable { return null; // shouldn't happen } + /** + * Returns the side of the door the hinge is on. + * + * Undefined if <code>isTopHalf()</code> is false. + * + * @return false for left hinge, true for right hinge + */ + public boolean getHinge() { + return (getData() & 0x1) == 1; + } + + /** + * Set whether the hinge is on the left or right side. Left is false, right is true. + * + * Undefined if <code>isTopHalf()</code> is false. + */ + public void setHinge(boolean hinge) { + setData((byte) (hinge ? (getData() | 0x1) : (getData() & ~0x1))); + } + @Override public Door clone() { return (Door) super.clone(); |