public Tree(TreeSpecies species, BlockFace dir) { this(); setSpecies(species); setDirection(dir); }
/** * 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 WEST: case EAST: dat = 1; break; case NORTH: case SOUTH: dat = 2; break; case SELF: dat = 3; break; } setData((byte) ((getData() & 0x3) | (dat << 2))); }
@Override public String toString() { return getSpecies() + " " + getDirection() + " " + super.toString(); }
public void saveTree(){ Queue<Tree> contentQueue = new LinkedList<Tree>(); Queue<String> pathQueue = new LinkedList<String>(); ArrayList<String> output = new ArrayList<String>(); contentQueue.add(this); pathQueue,add(""); //use the queue of string side-by-side while(!contentQueue.isEmpty()){ Tree child = (Tree) contentQueue.remove(); String val = pathQueue.remove(); output.add(val + " " + child.getData()); if(child.getLeft() != null){ contentQueue.add(child.getLeft()); pathQueue.add(val + "Y"); //concatenate the current value to the parent value } if(child.getRight()!= null){ contentQueue.add(child.getRight()); pathQueue.add(val + "N"); //concatenate the current value to the parent value } }
public Tree(TreeSpecies species) { this(); setSpecies(species); }
/** * Get direction of the log * * @return one of: * <ul> * <li>BlockFace.TOP for upright (default) * <li>BlockFace.NORTH (east-west) * <li>BlockFace.WEST (north-south) * <li>BlockFace.SELF (directionless) * </ul> */ public BlockFace getDirection() { switch ((getData() >> 2) & 0x3) { case 0: // Up-down default: return BlockFace.UP; case 1: // North-south return BlockFace.WEST; case 2: // East-west return BlockFace.NORTH; case 3: // Directionless (bark on all sides) return BlockFace.SELF; } } /**
@Override public boolean canPlaceAt(GlowPlayer player, GlowBlock block, BlockFace against) { BlockFace face = against.getOppositeFace(); if (Arrays.asList(SIDES).contains(face) && block.getRelative(face).getType() == Material.LOG) { MaterialData data = block.getRelative(face).getState().getData(); if (data instanceof Tree) { if (((Tree) data).getSpecies() == TreeSpecies.JUNGLE) { return true; } } else { warnMaterialData(Tree.class, data); } } return false; }
public Tree(TreeSpecies species) { this(); setSpecies(species); }
/** * Gets the current species of this tree * * @return TreeSpecies of this tree */ public TreeSpecies getSpecies() { return TreeSpecies.getByData((byte) (getData() & 0x3)); }
setData((byte) 10); } else if (mat == Material.SAPLING) { TreeSpecies species = ((Tree) materialData).getSpecies();
@Override public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) { super.placeBlock(player, state, face, holding, clickedLoc); MaterialData data = state.getData(); if (data instanceof Tree) { ((Tree) data).setDirection(face); ((Tree) data).setSpecies(TreeSpecies.getByData((byte) holding.getDurability())); } else { warnMaterialData(Tree.class, data); } state.setData(data); }
@Override public String toString() { return getSpecies() + " " + getDirection() + " " + super.toString(); }
if (species == null) return def; tdat.setSpecies(species); } else if (dat instanceof Leaves) { Leaves tdat = (Leaves) dat;
/** * Get direction of the log * * @return one of: * <ul> * <li>BlockFace.TOP for upright (default) * <li>BlockFace.NORTH (east-west) * <li>BlockFace.WEST (north-south) * <li>BlockFace.SELF (directionless) * </ul> */ public BlockFace getDirection() { switch ((getData() >> 2) & 0x3) { case 0: // Up-down default: return BlockFace.UP; case 1: // North-south return BlockFace.WEST; case 2: // East-west return BlockFace.NORTH; case 3: // Directionless (bark on all sides) return BlockFace.SELF; } } /**
setData((byte) 10); } else if (mat == Material.SAPLING) { TreeSpecies species = ((Tree) materialData).getSpecies();
public Tree(TreeSpecies species, BlockFace dir) { this(); setSpecies(species); setDirection(dir); }
/** * 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 WEST: case EAST: dat = 1; break; case NORTH: case SOUTH: dat = 2; break; case SELF: dat = 3; break; } setData((byte) ((getData() & 0x3) | (dat << 2))); }