Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Vine.java
1 package org.bukkit.material;
2 
3 import java.util.Arrays;
4 import java.util.EnumSet;
5 
6 import org.bukkit.Material;
8 
9 /**
10  * Represents a vine
11  */
12 public class Vine extends MaterialData {
13  private static final int VINE_NORTH = 0x4;
14  private static final int VINE_EAST = 0x8;
15  private static final int VINE_WEST = 0x2;
16  private static final int VINE_SOUTH = 0x1;
17  EnumSet<BlockFace> possibleFaces = EnumSet.of(BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST);
18 
19  public Vine() {
20  super(Material.VINE);
21  }
22 
23  /**
24  *
25  * @deprecated Magic value
26  */
27  @Deprecated
28  public Vine(int type, byte data){
29  super(type, data);
30  }
31 
32  /**
33  *
34  * @deprecated Magic value
35  */
36  @Deprecated
37  public Vine(byte data) {
38  super(Material.VINE, data);
39  }
40 
41  public Vine(BlockFace... faces) {
42  this(EnumSet.copyOf(Arrays.asList(faces)));
43  }
44 
45  public Vine(EnumSet<BlockFace> faces) {
46  this((byte) 0);
47  faces.retainAll(possibleFaces);
48 
49  byte data = 0;
50 
51  if (faces.contains(BlockFace.WEST)) {
52  data |= VINE_WEST;
53  }
54 
55  if (faces.contains(BlockFace.NORTH)) {
56  data |= VINE_NORTH;
57  }
58 
59  if (faces.contains(BlockFace.SOUTH)) {
60  data |= VINE_SOUTH;
61  }
62 
63  if (faces.contains(BlockFace.EAST)) {
64  data |= VINE_EAST;
65  }
66 
67  setData(data);
68  }
69 
70  /**
71  * Check if the vine is attached to the specified face of an adjacent
72  * block. You can check two faces at once by passing e.g. {@link
73  * BlockFace#NORTH_EAST}.
74  *
75  * @param face The face to check.
76  * @return Whether it is attached to that face.
77  */
78  public boolean isOnFace(BlockFace face) {
79  switch (face) {
80  case WEST:
81  return (getData() & VINE_WEST) == VINE_WEST;
82  case NORTH:
83  return (getData() & VINE_NORTH) == VINE_NORTH;
84  case SOUTH:
85  return (getData() & VINE_SOUTH) == VINE_SOUTH;
86  case EAST:
87  return (getData() & VINE_EAST) == VINE_EAST;
88  case NORTH_EAST:
89  return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.NORTH);
90  case NORTH_WEST:
91  return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.NORTH);
92  case SOUTH_EAST:
93  return isOnFace(BlockFace.EAST) && isOnFace(BlockFace.SOUTH);
94  case SOUTH_WEST:
95  return isOnFace(BlockFace.WEST) && isOnFace(BlockFace.SOUTH);
96  case UP: // It's impossible to be accurate with this since it's contextual
97  return true;
98  default:
99  return false;
100  }
101  }
102 
103  /**
104  * Attach the vine to the specified face of an adjacent block.
105  *
106  * @param face The face to attach.
107  */
108  public void putOnFace(BlockFace face) {
109  switch(face) {
110  case WEST:
111  setData((byte) (getData() | VINE_WEST));
112  break;
113  case NORTH:
114  setData((byte) (getData() | VINE_NORTH));
115  break;
116  case SOUTH:
117  setData((byte) (getData() | VINE_SOUTH));
118  break;
119  case EAST:
120  setData((byte) (getData() | VINE_EAST));
121  break;
122  case NORTH_WEST:
123  putOnFace(BlockFace.WEST);
124  putOnFace(BlockFace.NORTH);
125  break;
126  case SOUTH_WEST:
127  putOnFace(BlockFace.WEST);
128  putOnFace(BlockFace.SOUTH);
129  break;
130  case NORTH_EAST:
131  putOnFace(BlockFace.EAST);
132  putOnFace(BlockFace.NORTH);
133  break;
134  case SOUTH_EAST:
135  putOnFace(BlockFace.EAST);
136  putOnFace(BlockFace.SOUTH);
137  break;
138  case UP:
139  break;
140  default:
141  throw new IllegalArgumentException("Vines can't go on face " + face.toString());
142  }
143  }
144 
145  /**
146  * Detach the vine from the specified face of an adjacent block.
147  *
148  * @param face The face to detach.
149  */
150  public void removeFromFace(BlockFace face) {
151  switch(face) {
152  case WEST:
153  setData((byte) (getData() & ~VINE_WEST));
154  break;
155  case NORTH:
156  setData((byte) (getData() & ~VINE_NORTH));
157  break;
158  case SOUTH:
159  setData((byte) (getData() & ~VINE_SOUTH));
160  break;
161  case EAST:
162  setData((byte) (getData() & ~VINE_EAST));
163  break;
164  case NORTH_WEST:
166  removeFromFace(BlockFace.NORTH);
167  break;
168  case SOUTH_WEST:
170  removeFromFace(BlockFace.SOUTH);
171  break;
172  case NORTH_EAST:
174  removeFromFace(BlockFace.NORTH);
175  break;
176  case SOUTH_EAST:
178  removeFromFace(BlockFace.SOUTH);
179  break;
180  case UP:
181  break;
182  default:
183  throw new IllegalArgumentException("Vines can't go on face " + face.toString());
184  }
185  }
186 
187  @Override
188  public String toString() {
189  return "VINE";
190  }
191 
192  @Override
193  public Vine clone() {
194  return (Vine) super.clone();
195  }
196 }
void putOnFace(BlockFace face)
Definition: Vine.java:108
boolean isOnFace(BlockFace face)
Definition: Vine.java:78
void removeFromFace(BlockFace face)
Definition: Vine.java:150
Vine(int type, byte data)
Definition: Vine.java:28