Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Tree.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
4 import org.bukkit.TreeSpecies;
6 
7 /**
8  * Represents the different types of Trees.
9  */
10 public class Tree extends MaterialData {
11  public Tree() {
12  super(Material.LOG);
13  }
14 
15  public Tree(TreeSpecies species) {
16  this();
17  setSpecies(species);
18  }
19 
20  public Tree(TreeSpecies species, BlockFace dir) {
21  this();
22  setSpecies(species);
23  setDirection(dir);
24  }
25 
26  /**
27  *
28  * @deprecated Magic value
29  */
30  @Deprecated
31  public Tree(final int type) {
32  super(type);
33  }
34 
35  public Tree(final Material type) {
36  super(type);
37  }
38 
39  /**
40  *
41  * @deprecated Magic value
42  */
43  @Deprecated
44  public Tree(final int type, final byte data) {
45  super(type, data);
46  }
47 
48  /**
49  *
50  * @deprecated Magic value
51  */
52  @Deprecated
53  public Tree(final Material type, final byte data) {
54  super(type, data);
55  }
56 
57  /**
58  * Gets the current species of this tree
59  *
60  * @return TreeSpecies of this tree
61  */
63  return TreeSpecies.getByData((byte) (getData() & 0x3));
64  }
65 
66  /**
67  * Sets the species of this tree
68  *
69  * @param species New species of this tree
70  */
71  public void setSpecies(TreeSpecies species) {
72  setData((byte) ((getData() & 0xC) | species.getData()));
73  }
74 
75  /**
76  * Get direction of the log
77  *
78  * @return one of:
79  * <ul>
80  * <li>BlockFace.TOP for upright (default)
81  * <li>BlockFace.NORTH (east-west)
82  * <li>BlockFace.WEST (north-south)
83  * <li>BlockFace.SELF (directionless)
84  * </ul>
85  */
87  switch ((getData() >> 2) & 0x3) {
88  case 0: // Up-down
89  default:
90  return BlockFace.UP;
91  case 1: // North-south
92  return BlockFace.WEST;
93  case 2: // East-west
94  return BlockFace.NORTH;
95  case 3: // Directionless (bark on all sides)
96  return BlockFace.SELF;
97  }
98  }
99  /**
100  * Set direction of the log
101  *
102  * @param dir - direction of end of log (BlockFace.SELF for no direction)
103  */
104  public void setDirection(BlockFace dir) {
105  int dat;
106  switch (dir) {
107  case UP:
108  case DOWN:
109  default:
110  dat = 0;
111  break;
112  case WEST:
113  case EAST:
114  dat = 1;
115  break;
116  case NORTH:
117  case SOUTH:
118  dat = 2;
119  break;
120  case SELF:
121  dat = 3;
122  break;
123  }
124  setData((byte) ((getData() & 0x3) | (dat << 2)));
125  }
126 
127  @Override
128  public String toString() {
129  return getSpecies() + " " + getDirection() + " " + super.toString();
130  }
131 
132  @Override
133  public Tree clone() {
134  return (Tree) super.clone();
135  }
136 }
void setDirection(BlockFace dir)
Definition: Tree.java:104
Tree(final Material type, final byte data)
Definition: Tree.java:53
void setSpecies(TreeSpecies species)
Definition: Tree.java:71
static TreeSpecies getByData(final byte data)
BlockFace getDirection()
Definition: Tree.java:86
Tree(final int type, final byte data)
Definition: Tree.java:44
Tree(final int type)
Definition: Tree.java:31
TreeSpecies getSpecies()
Definition: Tree.java:62