Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Rails.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents minecart rails.
8  */
9 public class Rails extends MaterialData {
10 
11  public Rails() {
12  super(Material.RAILS);
13  }
14 
15  /**
16  *
17  * @deprecated Magic value
18  */
19  @Deprecated
20  public Rails(final int type) {
21  super(type);
22  }
23 
24  public Rails(final Material type) {
25  super(type);
26  }
27 
28  /**
29  *
30  * @deprecated Magic value
31  */
32  @Deprecated
33  public Rails(final int type, final byte data) {
34  super(type, data);
35  }
36 
37  /**
38  *
39  * @deprecated Magic value
40  */
41  @Deprecated
42  public Rails(final Material type, final byte data) {
43  super(type, data);
44  }
45 
46  /**
47  * @return the whether this track is set on a slope
48  */
49  public boolean isOnSlope() {
50  byte d = getConvertedData();
51 
52  return (d == 0x2 || d == 0x3 || d == 0x4 || d == 0x5);
53  }
54 
55  /**
56  * @return the whether this track is set as a curve
57  */
58  public boolean isCurve() {
59  byte d = getConvertedData();
60 
61  return (d == 0x6 || d == 0x7 || d == 0x8 || d == 0x9);
62  }
63 
64  /**
65  * @return the direction these tracks are set
66  * <p>
67  * Note that tracks are bidirectional and that the direction returned
68  * is the ascending direction if the track is set on a slope. If it is
69  * set as a curve, the corner of the track is returned.
70  */
72  byte d = getConvertedData();
73 
74  switch (d) {
75  case 0x0:
76  default:
77  return BlockFace.SOUTH;
78 
79  case 0x1:
80  return BlockFace.EAST;
81 
82  case 0x2:
83  return BlockFace.EAST;
84 
85  case 0x3:
86  return BlockFace.WEST;
87 
88  case 0x4:
89  return BlockFace.NORTH;
90 
91  case 0x5:
92  return BlockFace.SOUTH;
93 
94  case 0x6:
95  return BlockFace.NORTH_WEST;
96 
97  case 0x7:
98  return BlockFace.NORTH_EAST;
99 
100  case 0x8:
101  return BlockFace.SOUTH_EAST;
102 
103  case 0x9:
104  return BlockFace.SOUTH_WEST;
105  }
106  }
107 
108  @Override
109  public String toString() {
110  return super.toString() + " facing " + getDirection() + (isCurve() ? " on a curve" : (isOnSlope() ? " on a slope" : ""));
111  }
112 
113  /**
114  * Return the data without the extended properties used by {@link
115  * PoweredRail} and {@link DetectorRail}. Overridden in {@link
116  * ExtendedRails}
117  *
118  * @return the data without the extended part
119  * @deprecated Magic value
120  */
121  @Deprecated
122  protected byte getConvertedData() {
123  return getData();
124  }
125 
126  /**
127  * Set the direction of these tracks
128  * <p>
129  * Note that tracks are bidirectional and that the direction returned is
130  * the ascending direction if the track is set on a slope. If it is set as
131  * a curve, the corner of the track should be supplied.
132  *
133  * @param face the direction the track should be facing
134  * @param isOnSlope whether or not the track should be on a slope
135  */
136  public void setDirection(BlockFace face, boolean isOnSlope) {
137  switch (face) {
138  case EAST:
139  setData((byte) (isOnSlope ? 0x2 : 0x1));
140  break;
141 
142  case WEST:
143  setData((byte) (isOnSlope ? 0x3 : 0x1));
144  break;
145 
146  case NORTH:
147  setData((byte) (isOnSlope ? 0x4 : 0x0));
148  break;
149 
150  case SOUTH:
151  setData((byte) (isOnSlope ? 0x5 : 0x0));
152  break;
153 
154  case NORTH_WEST:
155  setData((byte) 0x6);
156  break;
157 
158  case NORTH_EAST:
159  setData((byte) 0x7);
160  break;
161 
162  case SOUTH_EAST:
163  setData((byte) 0x8);
164  break;
165 
166  case SOUTH_WEST:
167  setData((byte) 0x9);
168  break;
169  }
170  }
171 
172  @Override
173  public Rails clone() {
174  return (Rails) super.clone();
175  }
176 }
void setDirection(BlockFace face, boolean isOnSlope)
Definition: Rails.java:136
Rails(final Material type, final byte data)
Definition: Rails.java:42
BlockFace getDirection()
Definition: Rails.java:71
Rails(final int type)
Definition: Rails.java:20
Rails(final int type, final byte data)
Definition: Rails.java:33