[Bleeding] Add new MaterialData classes for new blocks and update existing blocks with new data
By: Mike Primm <mike@primmhome.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package org.bukkit.material;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
/**
|
||||
* Represents the different types of Trees.
|
||||
@@ -16,6 +17,12 @@ public class Tree extends MaterialData {
|
||||
setSpecies(species);
|
||||
}
|
||||
|
||||
public Tree(TreeSpecies species, BlockFace dir) {
|
||||
this();
|
||||
setSpecies(species);
|
||||
setDirection(dir);
|
||||
}
|
||||
|
||||
public Tree(final int type) {
|
||||
super(type);
|
||||
}
|
||||
@@ -38,7 +45,7 @@ public class Tree extends MaterialData {
|
||||
* @return TreeSpecies of this tree
|
||||
*/
|
||||
public TreeSpecies getSpecies() {
|
||||
return TreeSpecies.getByData(getData());
|
||||
return TreeSpecies.getByData((byte) (getData() & 0x3));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,12 +54,57 @@ public class Tree extends MaterialData {
|
||||
* @param species New species of this tree
|
||||
*/
|
||||
public void setSpecies(TreeSpecies species) {
|
||||
setData(species.getData());
|
||||
setData((byte) ((getData() & 0xC) | species.getData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get direction of the log
|
||||
*
|
||||
* @return BlockFace.TOP for upright (default), BlockFace.EAST (east-west), BlockFace.NORTH (north-sout), BlockFace.SELF (directionless)
|
||||
*/
|
||||
public BlockFace getDirection() {
|
||||
switch ((getData() >> 2) & 0x3) {
|
||||
case 0: // Up-down
|
||||
default:
|
||||
return BlockFace.UP;
|
||||
case 1: // North-south
|
||||
return BlockFace.NORTH;
|
||||
case 2: // East-west
|
||||
return BlockFace.EAST;
|
||||
case 3: // Directionless (bark on all sides)
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set direction of the log
|
||||
* @param dir - direction of end of log (BlockFace.SELF for no direction)
|
||||
*/
|
||||
public void setDirection(BlockFace dir) {
|
||||
int dat;
|
||||
switch (dir) {
|
||||
case UP:
|
||||
case DOWN:
|
||||
default:
|
||||
dat = 0;
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
dat = 1;
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
dat = 2;
|
||||
break;
|
||||
case SELF:
|
||||
dat = 3;
|
||||
break;
|
||||
}
|
||||
setData((byte) ((getData() & 0x3) | (dat << 2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSpecies() + " " + super.toString();
|
||||
return getSpecies() + " " + getDirection() + " " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user