Ton of Material extensions handling the meta-data of blocks.
By: sunkid <sunkid@iminurnetz.com>
This commit is contained in:
@@ -6,7 +6,11 @@ import org.bukkit.Material;
|
||||
/**
|
||||
* Represents a lever
|
||||
*/
|
||||
public class Lever extends MaterialData implements Redstone, Attachable {
|
||||
public class Lever extends SimpleAttachableMaterialData implements Redstone {
|
||||
public Lever() {
|
||||
super(Material.LEVER);
|
||||
}
|
||||
|
||||
public Lever(final int type) {
|
||||
super(type);
|
||||
}
|
||||
@@ -26,7 +30,7 @@ public class Lever extends MaterialData implements Redstone, Attachable {
|
||||
/**
|
||||
* Gets the current state of this Material, indicating if it's powered or
|
||||
* unpowered
|
||||
*
|
||||
*
|
||||
* @return true if powered, otherwise false
|
||||
*/
|
||||
public boolean isPowered() {
|
||||
@@ -35,26 +39,68 @@ public class Lever extends MaterialData implements Redstone, Attachable {
|
||||
|
||||
/**
|
||||
* Gets the face that this block is attached on
|
||||
*
|
||||
*
|
||||
* @return BlockFace attached to
|
||||
*/
|
||||
public BlockFace getAttachedFace() {
|
||||
byte data = (byte) (getData() & 0x7);
|
||||
|
||||
switch (data) {
|
||||
case 0x1:
|
||||
return BlockFace.NORTH;
|
||||
case 0x2:
|
||||
return BlockFace.SOUTH;
|
||||
case 0x3:
|
||||
return BlockFace.EAST;
|
||||
case 0x4:
|
||||
return BlockFace.WEST;
|
||||
case 0x5:
|
||||
case 0x6:
|
||||
return BlockFace.DOWN;
|
||||
case 0x1:
|
||||
return BlockFace.NORTH;
|
||||
case 0x2:
|
||||
return BlockFace.SOUTH;
|
||||
case 0x3:
|
||||
return BlockFace.EAST;
|
||||
case 0x4:
|
||||
return BlockFace.WEST;
|
||||
case 0x5:
|
||||
case 0x6:
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the direction this lever is pointing in
|
||||
*/
|
||||
public void setFacingDirection(BlockFace face) {
|
||||
byte data = (byte) (getData() & 0x8);
|
||||
|
||||
if (getAttachedFace() == BlockFace.DOWN) {
|
||||
switch (face) {
|
||||
case WEST:
|
||||
case EAST:
|
||||
data |= 0x5;
|
||||
break;
|
||||
case SOUTH:
|
||||
case NORTH:
|
||||
data |= 0x6;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (face) {
|
||||
case SOUTH:
|
||||
data |= 0x1;
|
||||
break;
|
||||
case NORTH:
|
||||
data |= 0x2;
|
||||
break;
|
||||
case WEST:
|
||||
data |= 0x3;
|
||||
break;
|
||||
case EAST:
|
||||
data |= 0x4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " facing " + getFacing() + " " + (isPowered() ? "" : "NOT ") + "POWERED";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user