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 base block
008     */
009    public class PistonBaseMaterial extends MaterialData implements Directional, Redstone {
010        /**
011         *
012         * @deprecated Magic value
013         */
014        @Deprecated
015        public PistonBaseMaterial(final int type) {
016            super(type);
017        }
018    
019        public PistonBaseMaterial(final Material type) {
020            super(type);
021        }
022    
023        /**
024         *
025         * @deprecated Magic value
026         */
027        @Deprecated
028        public PistonBaseMaterial(final int type, final byte data) {
029            super(type, data);
030        }
031    
032        /**
033         *
034         * @deprecated Magic value
035         */
036        @Deprecated
037        public PistonBaseMaterial(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        public boolean isPowered() {
086            return (getData() & 0x8) == 0x8;
087        }
088    
089        /**
090         * Sets the current state of this piston
091         *
092         * @param powered true if the piston is extended & powered, or false
093         */
094        public void setPowered(boolean powered) {
095            setData((byte) (powered ? (getData() | 0x8) : (getData() & ~0x8)));
096        }
097    
098        /**
099         * Checks if this piston base is sticky, and returns true if so
100         *
101         * @return true if this piston is "sticky", or false
102         */
103        public boolean isSticky() {
104            return this.getItemType() == Material.PISTON_STICKY_BASE;
105        }
106    
107        @Override
108        public PistonBaseMaterial clone() {
109            return (PistonBaseMaterial) super.clone();
110        }
111    }