001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 /** 007 * Material data for the piston extension block 008 */ 009 public class PistonExtensionMaterial extends MaterialData implements Attachable { 010 /** 011 * 012 * @deprecated Magic value 013 */ 014 @Deprecated 015 public PistonExtensionMaterial(final int type) { 016 super(type); 017 } 018 019 public PistonExtensionMaterial(final Material type) { 020 super(type); 021 } 022 023 /** 024 * 025 * @deprecated Magic value 026 */ 027 @Deprecated 028 public PistonExtensionMaterial(final int type, final byte data) { 029 super(type, data); 030 } 031 032 /** 033 * 034 * @deprecated Magic value 035 */ 036 @Deprecated 037 public PistonExtensionMaterial(final Material type, final byte data) { 038 super(type, data); 039 } 040 041 public void setFacingDirection(BlockFace face) { 042 byte data = (byte) (getData() & 0x8); 043 044 switch (face) { 045 case UP: 046 data |= 1; 047 break; 048 case NORTH: 049 data |= 2; 050 break; 051 case SOUTH: 052 data |= 3; 053 break; 054 case WEST: 055 data |= 4; 056 break; 057 case EAST: 058 data |= 5; 059 break; 060 } 061 setData(data); 062 } 063 064 public BlockFace getFacing() { 065 byte dir = (byte) (getData() & 7); 066 067 switch (dir) { 068 case 0: 069 return BlockFace.DOWN; 070 case 1: 071 return BlockFace.UP; 072 case 2: 073 return BlockFace.NORTH; 074 case 3: 075 return BlockFace.SOUTH; 076 case 4: 077 return BlockFace.WEST; 078 case 5: 079 return BlockFace.EAST; 080 default: 081 return BlockFace.SELF; 082 } 083 } 084 085 /** 086 * Checks if this piston extension is sticky, and returns true if so 087 * 088 * @return true if this piston is "sticky", or false 089 */ 090 public boolean isSticky() { 091 return (getData() & 8) == 8; 092 } 093 094 /** 095 * Sets whether or not this extension is sticky 096 * 097 * @param sticky true if sticky, otherwise false 098 */ 099 public void setSticky(boolean sticky) { 100 setData((byte) (sticky ? (getData() | 0x8) : (getData() & ~0x8))); 101 } 102 103 public BlockFace getAttachedFace() { 104 return getFacing().getOppositeFace(); 105 } 106 107 @Override 108 public PistonExtensionMaterial clone() { 109 return (PistonExtensionMaterial) super.clone(); 110 } 111 }