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
6/**
7 * Material data for the piston base block
8 */
9public class PistonBaseMaterial extends MaterialData implements Directional, Redstone {
10 public PistonBaseMaterial(final int type) {
11 super(type);
12 }
13
14 public PistonBaseMaterial(final Material type) {
15 super(type);
16 }
17
18 public PistonBaseMaterial(final int type, final byte data) {
19 super(type, data);
20 }
21
22 public PistonBaseMaterial(final Material type, final byte data) {
23 super(type, data);
24 }
25
26 public void setFacingDirection(BlockFace face) {
27 byte data = (byte) (getData() & 0x8);
28
29 switch (face) {
30 case UP:
31 data |= 1;
32 break;
33 case EAST:
34 data |= 2;
35 break;
36 case WEST:
37 data |= 3;
38 break;
39 case NORTH:
40 data |= 4;
41 break;
42 case SOUTH:
43 data |= 5;
44 break;
45 }
46 setData(data);
47 }
48
49 public BlockFace getFacing() {
50 byte dir = (byte) (getData() & 7);
51
52 switch (dir) {
53 case 0:
54 return BlockFace.DOWN;
55 case 1:
56 return BlockFace.UP;
57 case 2:
58 return BlockFace.EAST;
59 case 3:
60 return BlockFace.WEST;
61 case 4:
62 return BlockFace.NORTH;
63 case 5:
64 return BlockFace.SOUTH;
65 default:
66 return BlockFace.SELF;
67 }
68 }
69
70 public boolean isPowered() {
71 return (getData() & 0x8) == 0x8;
72 }
73
74 /**
75 * Sets the current state of this piston
76 *
77 * @param powered true if the piston is extended & powered, or false
78 */
79 public void setPowered(boolean powered) {
80 setData((byte) (powered ? (getData() | 0x8) : (getData() & ~0x8)));
81 }
82
83 /**
84 * Checks if this piston base is sticky, and returns true if so
85 *
86 * @return true if this piston is "sticky", or false
87 */
88 public boolean isSticky() {
89 return this.getItemType() == Material.PISTON_STICKY_BASE;
90 }
91}