diff options
author | ryanbennitt <ryanbennitt@googlemail.com> | 2016-01-11 18:07:51 +0000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-01-12 09:42:07 +1100 |
commit | f517b6e6a95a7a7f5498bce806a9b997e433f75b (patch) | |
tree | f15badb8ae7c28c1ff5cfb1b32582ee9058423ec /src/main | |
parent | f10a7a92f33995b08f63633b23de6ec80b50a609 (diff) | |
download | bukkit-f517b6e6a95a7a7f5498bce806a9b997e433f75b.tar bukkit-f517b6e6a95a7a7f5498bce806a9b997e433f75b.tar.gz bukkit-f517b6e6a95a7a7f5498bce806a9b997e433f75b.tar.lz bukkit-f517b6e6a95a7a7f5498bce806a9b997e433f75b.tar.xz bukkit-f517b6e6a95a7a7f5498bce806a9b997e433f75b.zip |
SPIGOT-1393: Fixed door direction mask
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/material/Door.java | 217 |
1 files changed, 187 insertions, 30 deletions
diff --git a/src/main/java/org/bukkit/material/Door.java b/src/main/java/org/bukkit/material/Door.java index 27bb6814..e02d8e66 100644 --- a/src/main/java/org/bukkit/material/Door.java +++ b/src/main/java/org/bukkit/material/Door.java @@ -1,6 +1,7 @@ package org.bukkit.material; import org.bukkit.Material; +import org.bukkit.TreeSpecies; import org.bukkit.block.BlockFace; /** @@ -9,6 +10,14 @@ import org.bukkit.block.BlockFace; * 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. + * + * @see Material.WOODEN_DOOR + * @see Material.IRON_DOOR_BLOCK + * @see Material.SPRUCE_DOOR + * @see Material.BIRCH_DOOR + * @see Material.JUNGLE_DOOR + * @see Material.ACACIA_DOOR + * @see Material.DARK_OAK_DOOR */ public class Door extends MaterialData implements Directional, Openable { @@ -37,6 +46,126 @@ public class Door extends MaterialData implements Directional, Openable { } /** + * Constructs the bottom half of a door of the given material type, facing the specified direction and set to closed + * + * @param type The type of material this door is made of. This must match the type of the block above. + * @param face The direction the door is facing. + * + * @see Material.WOODEN_DOOR + * @see Material.IRON_DOOR_BLOCK + * @see Material.SPRUCE_DOOR + * @see Material.BIRCH_DOOR + * @see Material.JUNGLE_DOOR + * @see Material.ACACIA_DOOR + * @see Material.DARK_OAK_DOOR + * + * @see BlockFace.WEST + * @see BlockFace.NORTH + * @see BlockFace.EAST + * @see BlockFace.SOUTH + */ + public Door(final Material type, BlockFace face) { + this(type, face, false); + } + + /** + * Constructs the bottom half of a door of the given material type, facing the specified direction and set to open + * or closed + * + * @param type The type of material this door is made of. This must match the type of the block above. + * @param face The direction the door is facing. + * @param isOpen Whether the door is currently opened. + * + * @see Material.WOODEN_DOOR + * @see Material.IRON_DOOR_BLOCK + * @see Material.SPRUCE_DOOR + * @see Material.BIRCH_DOOR + * @see Material.JUNGLE_DOOR + * @see Material.ACACIA_DOOR + * @see Material.DARK_OAK_DOOR + * + * @see BlockFace.WEST + * @see BlockFace.NORTH + * @see BlockFace.EAST + * @see BlockFace.SOUTH + */ + public Door(final Material type, BlockFace face, boolean isOpen) { + super(type); + setTopHalf(false); + setFacingDirection(face); + setOpen(isOpen); + } + + /** + * Constructs the top half of door of the given material type and with the hinge on the left or right + * + * @param type The type of material this door is made of. This must match the type of the block below. + * @param isHingeRight True if the hinge is on the right hand side, false if the hinge is on the left hand side. + * + * @see Material.WOODEN_DOOR + * @see Material.IRON_DOOR_BLOCK + * @see Material.SPRUCE_DOOR + * @see Material.BIRCH_DOOR + * @see Material.JUNGLE_DOOR + * @see Material.ACACIA_DOOR + * @see Material.DARK_OAK_DOOR + */ + public Door(final Material type, boolean isHingeRight) { + super(type); + setTopHalf(true); + setHinge(isHingeRight); + } + + /** + * Constructs the bottom half of a wooden door of the given species, facing the specified direction and set to + * closed + * + * @param species The species this wooden door is made of. This must match the species of the block above. + * @param face The direction the door is facing. + * + * @see TreeSpecies + * + * @see BlockFace.WEST + * @see BlockFace.NORTH + * @see BlockFace.EAST + * @see BlockFace.SOUTH + */ + public Door(final TreeSpecies species, BlockFace face) { + this(getWoodDoorOfSpecies(species), face, false); + } + + /** + * Constructs the bottom half of a wooden door of the given species, facing the specified direction and set to open + * or closed + * + * @param species The species this wooden door is made of. This must match the species of the block above. + * @param face The direction the door is facing. + * @param isOpen Whether the door is currently opened. + * + * @see TreeSpecies + * + * @see BlockFace.WEST + * @see BlockFace.NORTH + * @see BlockFace.EAST + * @see BlockFace.SOUTH + */ + public Door(final TreeSpecies species, BlockFace face, boolean isOpen) { + this(getWoodDoorOfSpecies(species), face, isOpen); + } + + /** + * Constructs the top half of a wooden door of the given species and with the hinge on the left or right + * + * @param species The species this wooden door is made of. This must match the species of the block below. + * @param isHingeRight True if the hinge is on the right hand side, false if the hinge is on the left hand side. + * + * @see TreeSpecies + */ + public Door(final TreeSpecies species, boolean isHingeRight) { + this(getWoodDoorOfSpecies(species), isHingeRight); + } + + /** * @param type the raw type id * @param data the raw data value * @deprecated Magic value @@ -57,6 +186,37 @@ public class Door extends MaterialData implements Directional, Openable { } /** + * Returns the item type of a wooden door for the given tree species. + * + * @param species The species of wood door required. + * @return The item type for the given species. + * + * @see Material.WOODEN_DOOR + * @see Material.SPRUCE_DOOR + * @see Material.BIRCH_DOOR + * @see Material.JUNGLE_DOOR + * @see Material.ACACIA_DOOR + * @see Material.DARK_OAK_DOOR + */ + public static Material getWoodDoorOfSpecies(TreeSpecies species) { + switch (species) { + default: + case GENERIC: + return Material.WOODEN_DOOR; + case BIRCH: + return Material.BIRCH_DOOR; + case REDWOOD: + return Material.SPRUCE_DOOR; + case JUNGLE: + return Material.JUNGLE_DOOR; + case ACACIA: + return Material.ACACIA_DOOR; + case DARK_OAK: + return Material.DARK_OAK_DOOR; + } + } + + /** * Result is undefined if <code>isTopHalf()</code> is true. */ public boolean isOpen() { @@ -108,23 +268,20 @@ public class Door extends MaterialData implements Directional, Openable { * @param face the direction */ public void setFacingDirection(BlockFace face) { - byte data = (byte) (getData() & 0x12); + byte data = (byte) (getData() & 0xC); switch (face) { - case WEST: - data |= 0x0; - break; - - case NORTH: - data |= 0x1; - break; - - case EAST: - data |= 0x2; - break; - - case SOUTH: - data |= 0x3; - break; + case WEST: + data |= 0x0; + break; + case NORTH: + data |= 0x1; + break; + case EAST: + data |= 0x2; + break; + case SOUTH: + data |= 0x3; + break; } setData(data); } @@ -139,19 +296,17 @@ public class Door extends MaterialData implements Directional, Openable { public BlockFace getFacing() { byte data = (byte) (getData() & 0x3); switch (data) { - case 0: - return BlockFace.WEST; - - case 1: - return BlockFace.NORTH; - - case 2: - return BlockFace.EAST; - - case 3: - return BlockFace.SOUTH; + case 0: + return BlockFace.WEST; + case 1: + return BlockFace.NORTH; + case 2: + return BlockFace.EAST; + case 3: + return BlockFace.SOUTH; + default: + throw new IllegalStateException("Unknown door facing (data: " + data + ")"); } - return null; // shouldn't happen } /** @@ -169,9 +324,11 @@ public class Door extends MaterialData implements Directional, Openable { * Set whether the hinge is on the left or right side. Left is false, right is true. * * Undefined if <code>isTopHalf()</code> is false. + * + * @param isHingeRight True if the hinge is on the right hand side, false if the hinge is on the left hand side. */ - public void setHinge(boolean hinge) { - setData((byte) (hinge ? (getData() | 0x1) : (getData() & ~0x1))); + public void setHinge(boolean isHingeRight) { + setData((byte) (isHingeRight ? (getData() | 0x1) : (getData() & ~0x1))); } @Override |