Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 91 lines 2.3 kB view raw
1package org.bukkit.material; 2 3import org.bukkit.Material; 4import org.bukkit.block.BlockFace; 5 6/** 7 * Material data for the piston extension block 8 */ 9public class PistonExtensionMaterial extends MaterialData implements Attachable { 10 public PistonExtensionMaterial(final int type) { 11 super(type); 12 } 13 14 public PistonExtensionMaterial(final Material type) { 15 super(type); 16 } 17 18 public PistonExtensionMaterial(final int type, final byte data) { 19 super(type, data); 20 } 21 22 public PistonExtensionMaterial(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 /** 71 * Checks if this piston extension is sticky, and returns true if so 72 * 73 * @return true if this piston is "sticky", or false 74 */ 75 public boolean isSticky() { 76 return (getData() & 8) == 8; 77 } 78 79 /** 80 * Sets whether or not this extension is sticky 81 * 82 * @param sticky true if sticky, otherwise false 83 */ 84 public void setSticky(boolean sticky) { 85 setData((byte) (sticky ? (getData() | 0x8) : (getData() & ~0x8))); 86 } 87 88 public BlockFace getAttachedFace() { 89 return getFacing().getOppositeFace(); 90 } 91}