From 26c1772bd8ebdfa18212312962ee5d78685ff0a6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 25 Mar 2011 14:54:58 -0700 Subject: [PATCH] added the MaterialData subclass Door By: sunkid --- .../src/main/java/org/bukkit/Material.java | 4 +- .../main/java/org/bukkit/block/BlockFace.java | 29 ++++++++++ .../main/java/org/bukkit/material/Door.java | 57 +++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/material/Door.java diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index 31ffb862f0..ee618b2eb0 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -67,14 +67,14 @@ public enum Material { FURNACE(61), BURNING_FURNACE(62), SIGN_POST(63, 1, Sign.class), - WOODEN_DOOR(64), + WOODEN_DOOR(64, Door.class), LADDER(65, Ladder.class), RAILS(66), COBBLESTONE_STAIRS(67), WALL_SIGN(68, 1, Sign.class), LEVER(69, Lever.class), STONE_PLATE(70), - IRON_DOOR_BLOCK(71), + IRON_DOOR_BLOCK(71, Door.class), WOOD_PLATE(72), REDSTONE_ORE(73), GLOWING_REDSTONE_ORE(74), diff --git a/paper-api/src/main/java/org/bukkit/block/BlockFace.java b/paper-api/src/main/java/org/bukkit/block/BlockFace.java index 63bc38d1cc..fb15fc911b 100644 --- a/paper-api/src/main/java/org/bukkit/block/BlockFace.java +++ b/paper-api/src/main/java/org/bukkit/block/BlockFace.java @@ -55,4 +55,33 @@ public enum BlockFace { public int getModZ() { return modZ; } + + public BlockFace getOppositeFace() { + switch (this) { + case NORTH: + return BlockFace.SOUTH; + case SOUTH: + return BlockFace.NORTH; + case EAST: + return BlockFace.WEST; + case WEST: + return BlockFace.EAST; + case UP: + return BlockFace.DOWN; + case DOWN: + return BlockFace.UP; + case NORTH_EAST: + return BlockFace.SOUTH_WEST; + case NORTH_WEST: + return BlockFace.SOUTH_EAST; + case SOUTH_EAST: + return BlockFace.NORTH_WEST; + case SOUTH_WEST: + return BlockFace.NORTH_EAST; + case SELF: + return BlockFace.SELF; + } + + return BlockFace.SELF; + } } diff --git a/paper-api/src/main/java/org/bukkit/material/Door.java b/paper-api/src/main/java/org/bukkit/material/Door.java new file mode 100644 index 0000000000..8da166efe3 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/material/Door.java @@ -0,0 +1,57 @@ +package org.bukkit.material; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; + +/** + * Represents the different types of coals. + * @author sunkid + */ +public class Door extends MaterialData { + public Door(final int type) { + super(type); + } + + public Door(final Material type) { + super(type); + } + + public Door(final int type, final byte data) { + super(type, data); + } + + public Door(final Material type, final byte data) { + super(type, data); + } + + /** + * Check to see if the door is open. + * @return true if the door has swung counterclockwise around its hinge. + */ + public boolean isOpen() { + return ((getData() & 0x4) == 0x4); + } + + /** + * @return whether this is the top half of the door + */ + public boolean isTopHalf() { + return ((getData() & 0x8) == 0x8); + } + + /** + * @return the location of the hinges + */ + 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; + } +}