Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
Stairs.java
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
5 
6 /**
7  * Represents stairs.
8  */
9 public class Stairs extends MaterialData implements Directional {
10 
11  /**
12  *
13  * @deprecated Magic value
14  */
15  @Deprecated
16  public Stairs(final int type) {
17  super(type);
18  }
19 
20  public Stairs(final Material type) {
21  super(type);
22  }
23 
24  /**
25  *
26  * @deprecated Magic value
27  */
28  @Deprecated
29  public Stairs(final int type, final byte data) {
30  super(type, data);
31  }
32 
33  /**
34  *
35  * @deprecated Magic value
36  */
37  @Deprecated
38  public Stairs(final Material type, final byte data) {
39  super(type, data);
40  }
41 
42  /**
43  * @return the direction the stairs ascend towards
44  */
46  byte data = getData();
47 
48  switch (data & 0x3) {
49  case 0x0:
50  default:
51  return BlockFace.EAST;
52 
53  case 0x1:
54  return BlockFace.WEST;
55 
56  case 0x2:
57  return BlockFace.SOUTH;
58 
59  case 0x3:
60  return BlockFace.NORTH;
61  }
62  }
63 
64  /**
65  * @return the direction the stairs descend towards
66  */
68  return getAscendingDirection().getOppositeFace();
69  }
70 
71  /**
72  * Set the direction the stair part of the block is facing
73  */
74  public void setFacingDirection(BlockFace face) {
75  byte data;
76 
77  switch (face) {
78  case NORTH:
79  data = 0x3;
80  break;
81 
82  case SOUTH:
83  data = 0x2;
84  break;
85 
86  case EAST:
87  default:
88  data = 0x0;
89  break;
90 
91  case WEST:
92  data = 0x1;
93  break;
94  }
95 
96  setData((byte) ((getData() & 0xC) | data));
97  }
98 
99  /**
100  * @return the direction the stair part of the block is facing
101  */
102  public BlockFace getFacing() {
103  return getDescendingDirection();
104  }
105 
106  /**
107  * Test if step is inverted
108  *
109  * @return true if inverted (top half), false if normal (bottom half)
110  */
111  public boolean isInverted() {
112  return ((getData() & 0x4) != 0);
113  }
114 
115  /**
116  * Set step inverted state
117  *
118  * @param inv - true if step is inverted (top half), false if step is
119  * normal (bottom half)
120  */
121  public void setInverted(boolean inv) {
122  int dat = getData() & 0x3;
123  if (inv) {
124  dat |= 0x4;
125  }
126  setData((byte) dat);
127  }
128 
129  @Override
130  public String toString() {
131  return super.toString() + " facing " + getFacing() + (isInverted()?" inverted":"");
132  }
133 
134  @Override
135  public Stairs clone() {
136  return (Stairs) super.clone();
137  }
138 }
Stairs(final int type)
Definition: Stairs.java:16
BlockFace getDescendingDirection()
Definition: Stairs.java:67
Stairs(final int type, final byte data)
Definition: Stairs.java:29
BlockFace getAscendingDirection()
Definition: Stairs.java:45
void setFacingDirection(BlockFace face)
Definition: Stairs.java:74
void setInverted(boolean inv)
Definition: Stairs.java:121
Stairs(final Material type, final byte data)
Definition: Stairs.java:38