Bukkit  1.5.2-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
Diode.java
Go to the documentation of this file.
1 package org.bukkit.material;
2 
3 import org.bukkit.Material;
4 import org.bukkit.block.BlockFace;
5 
6 public class Diode extends MaterialData implements Directional {
7  public Diode() {
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 
33  public void setDelay(int delay) {
34  if (delay > 4) {
35  delay = 4;
36  }
37  if (delay < 1) {
38  delay = 1;
39  }
40  byte newData = (byte) (getData() & 0x3);
41 
42  setData((byte) (newData | ((delay - 1) << 2)));
43  }
44 
50  public int getDelay() {
51  return (getData() >> 2) + 1;
52  }
53 
54  public void setFacingDirection(BlockFace face) {
55  int delay = getDelay();
56  byte data;
57 
58  switch (face) {
59  case EAST:
60  data = 0x1;
61  break;
62 
63  case SOUTH:
64  data = 0x2;
65  break;
66 
67  case WEST:
68  data = 0x3;
69  break;
70 
71  case NORTH:
72  default:
73  data = 0x0;
74  }
75 
76  setData(data);
77  setDelay(delay);
78  }
79 
80  public BlockFace getFacing() {
81  byte data = (byte) (getData() & 0x3);
82 
83  switch (data) {
84  case 0x0:
85  default:
86  return BlockFace.NORTH;
87 
88  case 0x1:
89  return BlockFace.EAST;
90 
91  case 0x2:
92  return BlockFace.SOUTH;
93 
94  case 0x3:
95  return BlockFace.WEST;
96  }
97  }
98 
99  @Override
100  public String toString() {
101  return super.toString() + " facing " + getFacing() + " with " + getDelay() + " ticks delay";
102  }
103 
104  @Override
105  public Diode clone() {
106  return (Diode) super.clone();
107  }
108 }