Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.material;
2
3import org.bukkit.Material;
4import org.bukkit.block.BlockFace;
5
6public class Diode extends MaterialData implements Directional {
7 public Diode() {
8 super(Material.DIODE_BLOCK_ON);
9 }
10
11 public Diode(int type) {
12 super(type);
13 }
14
15 public Diode(Material type) {
16 super(type);
17 }
18
19 public Diode(int type, byte data) {
20 super(type, data);
21 }
22
23 public Diode(Material type, byte data) {
24 super(type, data);
25 }
26
27 /**
28 * Sets the delay of the repeater
29 *
30 * @param delay The new delay (1-4)
31 */
32 public void setDelay(int delay) {
33 if (delay > 4) {
34 delay = 4;
35 }
36 if (delay < 1) {
37 delay = 1;
38 }
39 byte newData = (byte) (getData() & 0x3);
40
41 setData((byte) (newData | ((delay - 1) << 2)));
42 }
43
44 /**
45 * Gets the delay of the repeater in ticks
46 *
47 * @return The delay (1-4)
48 */
49 public int getDelay() {
50 return (getData() >> 2) + 1;
51 }
52
53 public void setFacingDirection(BlockFace face) {
54 int delay = getDelay();
55 byte data;
56
57 switch (face) {
58 case SOUTH:
59 data = 0x1;
60 break;
61
62 case WEST:
63 data = 0x2;
64 break;
65
66 case NORTH:
67 data = 0x3;
68 break;
69
70 case EAST:
71 default:
72 data = 0x0;
73 }
74
75 setData(data);
76 setDelay(delay);
77 }
78
79 public BlockFace getFacing() {
80 byte data = (byte) (getData() & 0x3);
81
82 switch (data) {
83 case 0x0:
84 default:
85 return BlockFace.EAST;
86
87 case 0x1:
88 return BlockFace.SOUTH;
89
90 case 0x2:
91 return BlockFace.WEST;
92
93 case 0x3:
94 return BlockFace.NORTH;
95 }
96 }
97
98 @Override
99 public String toString() {
100 return super.toString() + " facing " + getFacing() + " with " + getDelay() + " ticks delay";
101 }
102}