13
0
geforkt von Mirrors/Paper

Retrofit Door in order to work with modern Minecraft doors.

By: Xor Boole <mcyoung@mit.edu>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2015-06-19 12:50:44 -04:00
Ursprung dc0588c29d
Commit bbdebc86a5
2 geänderte Dateien mit 49 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -255,12 +255,12 @@ public enum Material {
BIRCH_FENCE(189), BIRCH_FENCE(189),
JUNGLE_FENCE(190), JUNGLE_FENCE(190),
DARK_OAK_FENCE(191), DARK_OAK_FENCE(191),
ACACIA_FENCE(192), ACACIA_FENCE(192, Door.class),
SPRUCE_DOOR(193), SPRUCE_DOOR(193, Door.class),
BIRCH_DOOR(194), BIRCH_DOOR(194, Door.class),
JUNGLE_DOOR(195), JUNGLE_DOOR(195, Door.class),
ACACIA_DOOR(196), ACACIA_DOOR(196, Door.class),
DARK_OAK_DOOR(197), DARK_OAK_DOOR(197, Door.class),
// ----- Item Separator ----- // ----- Item Separator -----
IRON_SPADE(256, 1, 250), IRON_SPADE(256, 1, 250),
IRON_PICKAXE(257, 1, 250), IRON_PICKAXE(257, 1, 250),

Datei anzeigen

@ -6,10 +6,19 @@ import org.bukkit.block.BlockFace;
/** /**
* Represents a door. * 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 { 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() { public Door() {
super(Material.WOODEN_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() { public boolean isOpen() {
return ((getData() & 0x4) == 0x4); 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) { public void setOpen(boolean isOpen) {
setData((byte) (isOpen ? (getData() | 0x4) : (getData() & ~0x4))); 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 * Configure this part of the door to be either the top or the bottom half
* *
* @param isTopHalf True to make it the top half. * @param isTopHalf True to make it the top half.
* @deprecated Shouldn't be used anymore
*/ */
@Deprecated
public void setTopHalf(boolean isTopHalf) { public void setTopHalf(boolean isTopHalf) {
setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8))); setData((byte) (isTopHalf ? (getData() | 0x8) : (getData() & ~0x8)));
} }
/** /**
* @return BlockFace.SELF * @return BlockFace.SELF
* @deprecated Does not work (correctly) anymore * @deprecated This method should not be used; use hinge and facing accessors instead.
*/ */
@Deprecated @Deprecated
public BlockFace getHingeCorner() { public BlockFace getHingeCorner() {
byte d = getData(); return BlockFace.SELF;
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;
} }
@Override @Override
@ -108,13 +103,17 @@ public class Door extends MaterialData implements Directional, Openable {
/** /**
* Set the direction that this door should is facing. * Set the direction that this door should is facing.
* *
* Undefined if <code>isTopHalf()</code> is true.
*
* @param face the direction * @param face the direction
* @deprecated Does not work (correctly) anymore
*/ */
@Deprecated
public void setFacingDirection(BlockFace face) { public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x12); byte data = (byte) (getData() & 0x12);
switch (face) { switch (face) {
case WEST:
data |= 0x0;
break;
case NORTH: case NORTH:
data |= 0x1; data |= 0x1;
break; break;
@ -133,10 +132,10 @@ public class Door extends MaterialData implements Directional, Openable {
/** /**
* Get the direction that this door is facing. * Get the direction that this door is facing.
* *
* Undefined if <code>isTopHalf()</code> is true.
*
* @return the direction * @return the direction
* @deprecated Does not work (correctly) anymore
*/ */
@Deprecated
public BlockFace getFacing() { public BlockFace getFacing() {
byte data = (byte) (getData() & 0x3); byte data = (byte) (getData() & 0x3);
switch (data) { switch (data) {
@ -155,6 +154,26 @@ public class Door extends MaterialData implements Directional, Openable {
return null; // shouldn't happen 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 @Override
public Door clone() { public Door clone() {
return (Door) super.clone(); return (Door) super.clone();