13
0
geforkt von Mirrors/Paper

Fix MaterialData directions being incorrect. Fixes BUKKIT-3160

Prior to 49690f9, BlockFaces were mostly correct in their respective
MaterialData classes. However, a lot of things were not updated since
implementation and broke without being addressed.

This fixes any discrepancies with Block data.

By: feildmaster <admin@feildmaster.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-12-15 23:25:19 -06:00
Ursprung fb2cf30fbe
Commit 87f538df31
9 geänderte Dateien mit 130 neuen und 103 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@ import org.bukkit.block.BlockFace;
/** /**
* Represents the cocoa plant * Represents the cocoa plant
*/ */
public class CocoaPlant extends MaterialData implements Directional { public class CocoaPlant extends MaterialData implements Directional, Attachable {
public enum CocoaPlantSize { public enum CocoaPlantSize {
SMALL, SMALL,
@ -71,9 +71,14 @@ public class CocoaPlant extends MaterialData implements Directional {
setData((byte) dat); setData((byte) dat);
} }
public BlockFace getAttachedFace() {
return getFacing().getOppositeFace();
}
public void setFacingDirection(BlockFace face) { public void setFacingDirection(BlockFace face) {
int dat = getData() & 0xC; int dat = getData() & 0xC;
switch (face) { switch (face) {
default:
case SOUTH: case SOUTH:
break; break;
case WEST: case WEST:
@ -85,8 +90,6 @@ public class CocoaPlant extends MaterialData implements Directional {
case EAST: case EAST:
dat |= 0x3; dat |= 0x3;
break; break;
default:
break;
} }
setData((byte) dat); setData((byte) dat);
} }

Datei anzeigen

@ -1,6 +1,5 @@
package org.bukkit.material; package org.bukkit.material;
import org.bukkit.block.BlockFace;
import org.bukkit.Material; import org.bukkit.Material;
/** /**

Datei anzeigen

@ -5,7 +5,10 @@ import org.bukkit.block.BlockFace;
/** /**
* Represents a door. * Represents a door.
*
* @deprecated No longer functions. Do not use.
*/ */
@Deprecated
public class Door extends MaterialData implements Directional, Openable { public class Door extends MaterialData implements Directional, Openable {
public Door() { public Door() {
super(Material.WOODEN_DOOR); super(Material.WOODEN_DOOR);
@ -27,10 +30,18 @@ public class Door extends MaterialData implements Directional, Openable {
super(type, data); super(type, data);
} }
/**
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public boolean isOpen() { public boolean isOpen() {
return ((getData() & 0x4) == 0x4); return ((getData() & 0x4) == 0x4);
} }
/**
* @deprecated Does not work (correctly) anymore
*/
@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)));
} }
@ -46,14 +57,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 the location of the hinges * @return BlockFace.SELF
* @deprecated Does not work (correctly) anymore
*/ */
@Deprecated
public BlockFace getHingeCorner() { public BlockFace getHingeCorner() {
byte d = getData(); byte d = getData();
@ -70,14 +85,16 @@ public class Door extends MaterialData implements Directional, Openable {
@Override @Override
public String toString() { public String toString() {
return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + (isOpen() ? "an OPEN " : "a CLOSED ") + super.toString() + " with hinges " + getHingeCorner(); return (isTopHalf() ? "TOP" : "BOTTOM") + " half of " + super.toString();
} }
/** /**
* Set the direction that this door should is facing. * Set the direction that this door should is facing.
* *
* @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) {
@ -100,7 +117,9 @@ public class Door extends MaterialData implements Directional, Openable {
* Get the direction that this door is facing. * Get the direction that this door is facing.
* *
* @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) {

Datei anzeigen

@ -77,16 +77,16 @@ public class Rails extends MaterialData {
return BlockFace.SOUTH; return BlockFace.SOUTH;
case 0x6: case 0x6:
return BlockFace.NORTH_EAST; return BlockFace.NORTH_WEST;
case 0x7: case 0x7:
return BlockFace.SOUTH_EAST; return BlockFace.NORTH_EAST;
case 0x8: case 0x8:
return BlockFace.SOUTH_WEST; return BlockFace.SOUTH_EAST;
case 0x9: case 0x9:
return BlockFace.NORTH_WEST; return BlockFace.SOUTH_WEST;
} }
} }
@ -132,19 +132,19 @@ public class Rails extends MaterialData {
setData((byte) (isOnSlope ? 0x5 : 0x0)); setData((byte) (isOnSlope ? 0x5 : 0x0));
break; break;
case NORTH_EAST: case NORTH_WEST:
setData((byte) 0x6); setData((byte) 0x6);
break; break;
case SOUTH_EAST: case NORTH_EAST:
setData((byte) 0x7); setData((byte) 0x7);
break; break;
case SOUTH_WEST: case SOUTH_EAST:
setData((byte) 0x8); setData((byte) 0x8);
break; break;
case NORTH_WEST: case SOUTH_WEST:
setData((byte) 0x9); setData((byte) 0x9);
break; break;
} }

Datei anzeigen

@ -80,49 +80,49 @@ public class Sign extends MaterialData implements Attachable {
return BlockFace.SOUTH; return BlockFace.SOUTH;
case 0x1: case 0x1:
return BlockFace.WEST_NORTH_WEST; return BlockFace.SOUTH_SOUTH_WEST;
case 0x2: case 0x2:
return BlockFace.NORTH_WEST; return BlockFace.SOUTH_WEST;
case 0x3: case 0x3:
return BlockFace.NORTH_NORTH_WEST; return BlockFace.WEST_SOUTH_WEST;
case 0x4: case 0x4:
return BlockFace.WEST; return BlockFace.WEST;
case 0x5: case 0x5:
return BlockFace.NORTH_NORTH_EAST; return BlockFace.WEST_NORTH_WEST;
case 0x6: case 0x6:
return BlockFace.NORTH_EAST; return BlockFace.NORTH_WEST;
case 0x7: case 0x7:
return BlockFace.EAST_NORTH_EAST; return BlockFace.NORTH_NORTH_WEST;
case 0x8: case 0x8:
return BlockFace.NORTH; return BlockFace.NORTH;
case 0x9: case 0x9:
return BlockFace.EAST_SOUTH_EAST; return BlockFace.NORTH_NORTH_EAST;
case 0xA: case 0xA:
return BlockFace.SOUTH_EAST; return BlockFace.NORTH_EAST;
case 0xB: case 0xB:
return BlockFace.SOUTH_SOUTH_EAST; return BlockFace.EAST_NORTH_EAST;
case 0xC: case 0xC:
return BlockFace.EAST; return BlockFace.EAST;
case 0xD: case 0xD:
return BlockFace.SOUTH_SOUTH_WEST; return BlockFace.EAST_SOUTH_EAST;
case 0xE: case 0xE:
return BlockFace.SOUTH_WEST; return BlockFace.SOUTH_EAST;
case 0xF: case 0xF:
return BlockFace.WEST_SOUTH_WEST; return BlockFace.SOUTH_SOUTH_EAST;
} }
return null; return null;
@ -158,15 +158,15 @@ public class Sign extends MaterialData implements Attachable {
data = 0x0; data = 0x0;
break; break;
case WEST_NORTH_WEST: case SOUTH_SOUTH_WEST:
data = 0x1; data = 0x1;
break; break;
case NORTH_WEST: case SOUTH_WEST:
data = 0x2; data = 0x2;
break; break;
case NORTH_NORTH_WEST: case WEST_SOUTH_WEST:
data = 0x3; data = 0x3;
break; break;
@ -174,15 +174,15 @@ public class Sign extends MaterialData implements Attachable {
data = 0x4; data = 0x4;
break; break;
case NORTH_NORTH_EAST: case WEST_NORTH_WEST:
data = 0x5; data = 0x5;
break; break;
case NORTH_EAST: case NORTH_WEST:
data = 0x6; data = 0x6;
break; break;
case EAST_NORTH_EAST: case NORTH_NORTH_WEST:
data = 0x7; data = 0x7;
break; break;
@ -190,15 +190,15 @@ public class Sign extends MaterialData implements Attachable {
data = 0x8; data = 0x8;
break; break;
case EAST_SOUTH_EAST: case NORTH_NORTH_EAST:
data = 0x9; data = 0x9;
break; break;
case SOUTH_EAST: case NORTH_EAST:
data = 0xA; data = 0xA;
break; break;
case SOUTH_SOUTH_EAST: case EAST_NORTH_EAST:
data = 0xB; data = 0xB;
break; break;
@ -206,15 +206,15 @@ public class Sign extends MaterialData implements Attachable {
data = 0xC; data = 0xC;
break; break;
case SOUTH_SOUTH_WEST: case EAST_SOUTH_EAST:
data = 0xD; data = 0xD;
break; break;
case WEST_SOUTH_WEST: case SOUTH_SOUTH_EAST:
data = 0xF; data = 0xF;
break; break;
case SOUTH_WEST: case SOUTH_EAST:
default: default:
data = 0xE; data = 0xE;
} }

Datei anzeigen

@ -41,42 +41,49 @@ public class Skull extends MaterialData implements Directional {
int data; int data;
switch (face) { switch (face) {
case NORTH: case SELF:
default:
data = 0x1; data = 0x1;
break; break;
case EAST: case NORTH:
data = 0x2; data = 0x2;
break; break;
case EAST:
data = 0x4;
break;
case SOUTH: case SOUTH:
data = 0x3; data = 0x3;
break; break;
case WEST: case WEST:
default: data = 0x5;
data = 0x4;
} }
setData((byte) (data & 3)); setData((byte) data);
} }
public BlockFace getFacing() { public BlockFace getFacing() {
int data = getData() & 7; int data = getData();
switch (data) { switch (data) {
case 0x1: case 0x1:
return BlockFace.NORTH; default:
return BlockFace.SELF;
case 0x2: case 0x2:
return BlockFace.EAST; return BlockFace.NORTH;
case 0x3: case 0x3:
return BlockFace.SOUTH; return BlockFace.SOUTH;
case 0x4: case 0x4:
default:
return BlockFace.EAST; return BlockFace.EAST;
case 0x5:
return BlockFace.WEST;
} }
} }

Datei anzeigen

@ -60,22 +60,22 @@ public class Stairs extends MaterialData implements Directional {
byte data; byte data;
switch (face) { switch (face) {
case WEST: case NORTH:
data = 0x3;
break;
case SOUTH:
data = 0x2;
break;
case EAST:
default: default:
data = 0x0; data = 0x0;
break; break;
case EAST: case WEST:
data = 0x1; data = 0x1;
break; break;
case NORTH:
data = 0x2;
break;
case SOUTH:
data = 0x3;
break;
} }
setData((byte) ((getData() & 0xC) | data)); setData((byte) ((getData() & 0xC) | data));

Datei anzeigen

@ -49,10 +49,9 @@ public class Torch extends SimpleAttachableMaterialData {
return BlockFace.SOUTH; return BlockFace.SOUTH;
case 0x5: case 0x5:
default:
return BlockFace.DOWN; return BlockFace.DOWN;
} }
return null;
} }
public void setFacingDirection(BlockFace face) { public void setFacingDirection(BlockFace face) {

Datei anzeigen

@ -39,21 +39,21 @@ public class Vine extends MaterialData {
byte data = 0; byte data = 0;
if (faces.contains(BlockFace.WEST)) { if (faces.contains(BlockFace.WEST)) {
data |= VINE_NORTH;
}
if (faces.contains(BlockFace.NORTH)) {
data |= VINE_EAST;
}
if (faces.contains(BlockFace.SOUTH)) {
data |= VINE_WEST; data |= VINE_WEST;
} }
if (faces.contains(BlockFace.EAST)) { if (faces.contains(BlockFace.NORTH)) {
data |= VINE_NORTH;
}
if (faces.contains(BlockFace.SOUTH)) {
data |= VINE_SOUTH; data |= VINE_SOUTH;
} }
if (faces.contains(BlockFace.EAST)) {
data |= VINE_EAST;
}
setData(data); setData(data);
} }
@ -67,21 +67,21 @@ public class Vine extends MaterialData {
public boolean isOnFace(BlockFace face) { public boolean isOnFace(BlockFace face) {
switch (face) { switch (face) {
case WEST: case WEST:
return (getData() & VINE_NORTH) > 0; return (getData() & VINE_WEST) == VINE_WEST;
case NORTH: case NORTH:
return (getData() & VINE_EAST) > 0; return (getData() & VINE_NORTH) == VINE_NORTH;
case SOUTH: case SOUTH:
return (getData() & VINE_WEST) > 0; return (getData() & VINE_SOUTH) == VINE_SOUTH;
case EAST: case EAST:
return (getData() & VINE_SOUTH) > 0; return (getData() & VINE_EAST) == VINE_EAST;
case NORTH_EAST: case NORTH_EAST:
return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.NORTH);
case NORTH_WEST:
return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.SOUTH);
case SOUTH_EAST:
return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.NORTH); return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.NORTH);
case SOUTH_WEST: case NORTH_WEST:
return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.NORTH);
case SOUTH_EAST:
return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.SOUTH); return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.SOUTH);
case SOUTH_WEST:
return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.SOUTH);
case UP: // It's impossible to be accurate with this since it's contextual case UP: // It's impossible to be accurate with this since it's contextual
return true; return true;
default: default:
@ -97,30 +97,30 @@ public class Vine extends MaterialData {
public void putOnFace(BlockFace face) { public void putOnFace(BlockFace face) {
switch(face) { switch(face) {
case WEST: case WEST:
setData((byte) (getData() | VINE_NORTH));
break;
case NORTH:
setData((byte) (getData() | VINE_EAST));
break;
case SOUTH:
setData((byte) (getData() | VINE_WEST)); setData((byte) (getData() | VINE_WEST));
break; break;
case EAST: case NORTH:
setData((byte) (getData() | VINE_NORTH));
break;
case SOUTH:
setData((byte) (getData() | VINE_SOUTH)); setData((byte) (getData() | VINE_SOUTH));
break; break;
case NORTH_EAST: case EAST:
putOnFace(BlockFace.WEST); setData((byte) (getData() | VINE_EAST));
putOnFace(BlockFace.NORTH);
break; break;
case NORTH_WEST: case NORTH_WEST:
putOnFace(BlockFace.WEST); putOnFace(BlockFace.WEST);
putOnFace(BlockFace.SOUTH);
break;
case SOUTH_EAST:
putOnFace(BlockFace.EAST);
putOnFace(BlockFace.NORTH); putOnFace(BlockFace.NORTH);
break; break;
case SOUTH_WEST: case SOUTH_WEST:
putOnFace(BlockFace.WEST);
putOnFace(BlockFace.SOUTH);
break;
case NORTH_EAST:
putOnFace(BlockFace.EAST);
putOnFace(BlockFace.NORTH);
break;
case SOUTH_EAST:
putOnFace(BlockFace.EAST); putOnFace(BlockFace.EAST);
putOnFace(BlockFace.SOUTH); putOnFace(BlockFace.SOUTH);
break; break;
@ -139,30 +139,30 @@ public class Vine extends MaterialData {
public void removeFromFace(BlockFace face) { public void removeFromFace(BlockFace face) {
switch(face) { switch(face) {
case WEST: case WEST:
setData((byte) (getData() &~ VINE_NORTH)); setData((byte) (getData() & ~VINE_WEST));
break; break;
case NORTH: case NORTH:
setData((byte) (getData() &~ VINE_EAST)); setData((byte) (getData() & ~VINE_NORTH));
break; break;
case SOUTH: case SOUTH:
setData((byte) (getData() &~ VINE_WEST)); setData((byte) (getData() & ~VINE_SOUTH));
break; break;
case EAST: case EAST:
setData((byte) (getData() &~ VINE_SOUTH)); setData((byte) (getData() & ~VINE_EAST));
break;
case NORTH_EAST:
removeFromFace(BlockFace.WEST);
removeFromFace(BlockFace.NORTH);
break; break;
case NORTH_WEST: case NORTH_WEST:
removeFromFace(BlockFace.WEST); removeFromFace(BlockFace.WEST);
removeFromFace(BlockFace.SOUTH);
break;
case SOUTH_EAST:
removeFromFace(BlockFace.EAST);
removeFromFace(BlockFace.NORTH); removeFromFace(BlockFace.NORTH);
break; break;
case SOUTH_WEST: case SOUTH_WEST:
removeFromFace(BlockFace.WEST);
removeFromFace(BlockFace.SOUTH);
break;
case NORTH_EAST:
removeFromFace(BlockFace.EAST);
removeFromFace(BlockFace.NORTH);
break;
case SOUTH_EAST:
removeFromFace(BlockFace.EAST); removeFromFace(BlockFace.EAST);
removeFromFace(BlockFace.SOUTH); removeFromFace(BlockFace.SOUTH);
break; break;