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

Datei anzeigen

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

Datei anzeigen

@ -5,7 +5,10 @@ import org.bukkit.block.BlockFace;
/**
* Represents a door.
*
* @deprecated No longer functions. Do not use.
*/
@Deprecated
public class Door extends MaterialData implements Directional, Openable {
public Door() {
super(Material.WOODEN_DOOR);
@ -27,10 +30,18 @@ public class Door extends MaterialData implements Directional, Openable {
super(type, data);
}
/**
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public boolean isOpen() {
return ((getData() & 0x4) == 0x4);
}
/**
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public void setOpen(boolean isOpen) {
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;
*
* @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 the location of the hinges
* @return BlockFace.SELF
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public BlockFace getHingeCorner() {
byte d = getData();
@ -70,14 +85,16 @@ public class Door extends MaterialData implements Directional, Openable {
@Override
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.
*
* @param face the direction
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public void setFacingDirection(BlockFace face) {
byte data = (byte) (getData() & 0x12);
switch (face) {
@ -100,7 +117,9 @@ public class Door extends MaterialData implements Directional, Openable {
* Get the direction that this door is facing.
*
* @return the direction
* @deprecated Does not work (correctly) anymore
*/
@Deprecated
public BlockFace getFacing() {
byte data = (byte) (getData() & 0x3);
switch (data) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -39,21 +39,21 @@ public class Vine extends MaterialData {
byte data = 0;
if (faces.contains(BlockFace.WEST)) {
data |= VINE_NORTH;
}
if (faces.contains(BlockFace.NORTH)) {
data |= VINE_EAST;
}
if (faces.contains(BlockFace.SOUTH)) {
data |= VINE_WEST;
}
if (faces.contains(BlockFace.EAST)) {
if (faces.contains(BlockFace.NORTH)) {
data |= VINE_NORTH;
}
if (faces.contains(BlockFace.SOUTH)) {
data |= VINE_SOUTH;
}
if (faces.contains(BlockFace.EAST)) {
data |= VINE_EAST;
}
setData(data);
}
@ -67,21 +67,21 @@ public class Vine extends MaterialData {
public boolean isOnFace(BlockFace face) {
switch (face) {
case WEST:
return (getData() & VINE_NORTH) > 0;
return (getData() & VINE_WEST) == VINE_WEST;
case NORTH:
return (getData() & VINE_EAST) > 0;
return (getData() & VINE_NORTH) == VINE_NORTH;
case SOUTH:
return (getData() & VINE_WEST) > 0;
return (getData() & VINE_SOUTH) == VINE_SOUTH;
case EAST:
return (getData() & VINE_SOUTH) > 0;
return (getData() & VINE_EAST) == VINE_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);
case SOUTH_WEST:
case NORTH_WEST:
return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.NORTH);
case SOUTH_EAST:
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
return true;
default:
@ -97,30 +97,30 @@ public class Vine extends MaterialData {
public void putOnFace(BlockFace face) {
switch(face) {
case WEST:
setData((byte) (getData() | VINE_NORTH));
break;
case NORTH:
setData((byte) (getData() | VINE_EAST));
break;
case SOUTH:
setData((byte) (getData() | VINE_WEST));
break;
case EAST:
case NORTH:
setData((byte) (getData() | VINE_NORTH));
break;
case SOUTH:
setData((byte) (getData() | VINE_SOUTH));
break;
case NORTH_EAST:
putOnFace(BlockFace.WEST);
putOnFace(BlockFace.NORTH);
case EAST:
setData((byte) (getData() | VINE_EAST));
break;
case NORTH_WEST:
putOnFace(BlockFace.WEST);
putOnFace(BlockFace.SOUTH);
break;
case SOUTH_EAST:
putOnFace(BlockFace.EAST);
putOnFace(BlockFace.NORTH);
break;
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.SOUTH);
break;
@ -139,30 +139,30 @@ public class Vine extends MaterialData {
public void removeFromFace(BlockFace face) {
switch(face) {
case WEST:
setData((byte) (getData() &~ VINE_NORTH));
setData((byte) (getData() & ~VINE_WEST));
break;
case NORTH:
setData((byte) (getData() &~ VINE_EAST));
setData((byte) (getData() & ~VINE_NORTH));
break;
case SOUTH:
setData((byte) (getData() &~ VINE_WEST));
setData((byte) (getData() & ~VINE_SOUTH));
break;
case EAST:
setData((byte) (getData() &~ VINE_SOUTH));
break;
case NORTH_EAST:
removeFromFace(BlockFace.WEST);
removeFromFace(BlockFace.NORTH);
setData((byte) (getData() & ~VINE_EAST));
break;
case NORTH_WEST:
removeFromFace(BlockFace.WEST);
removeFromFace(BlockFace.SOUTH);
break;
case SOUTH_EAST:
removeFromFace(BlockFace.EAST);
removeFromFace(BlockFace.NORTH);
break;
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.SOUTH);
break;