    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Random;
    006
    007    public class BlockPistonMoving extends BlockContainer
    008    {
    009        public BlockPistonMoving(int par1)
    010        {
    011            super(par1, Material.piston);
    012            this.setHardness(-1.0F);
    013        }
    014
    015        /**
    016         * Returns a new instance of a block's tile entity class. Called on placing the block.
    017         */
    018        public TileEntity createNewTileEntity(World par1World)
    019        {
    020            return null;
    021        }
    022
    023        /**
    024         * Called whenever the block is added into the world. Args: world, x, y, z
    025         */
    026        public void onBlockAdded(World par1World, int par2, int par3, int par4) {}
    027
    028        /**
    029         * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    030         */
    031        public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    032        {
    033            TileEntity var7 = par1World.getBlockTileEntity(par2, par3, par4);
    034
    035            if (var7 instanceof TileEntityPiston)
    036            {
    037                ((TileEntityPiston)var7).clearPistonTileEntity();
    038            }
    039            else
    040            {
    041                super.breakBlock(par1World, par2, par3, par4, par5, par6);
    042            }
    043        }
    044
    045        /**
    046         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    047         */
    048        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    049        {
    050            return false;
    051        }
    052
    053        /**
    054         * checks to see if you can place this block can be placed on that side of a block: BlockLever overrides
    055         */
    056        public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5)
    057        {
    058            return false;
    059        }
    060
    061        /**
    062         * The type of render function that is called for this block
    063         */
    064        public int getRenderType()
    065        {
    066            return -1;
    067        }
    068
    069        /**
    070         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    071         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    072         */
    073        public boolean isOpaqueCube()
    074        {
    075            return false;
    076        }
    077
    078        /**
    079         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    080         */
    081        public boolean renderAsNormalBlock()
    082        {
    083            return false;
    084        }
    085
    086        /**
    087         * Called upon block activation (right click on the block.)
    088         */
    089        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    090        {
    091            if (!par1World.isRemote && par1World.getBlockTileEntity(par2, par3, par4) == null)
    092            {
    093                par1World.setBlockWithNotify(par2, par3, par4, 0);
    094                return true;
    095            }
    096            else
    097            {
    098                return false;
    099            }
    100        }
    101
    102        /**
    103         * Returns the ID of the items to drop on destruction.
    104         */
    105        public int idDropped(int par1, Random par2Random, int par3)
    106        {
    107            return 0;
    108        }
    109
    110        /**
    111         * Drops the block items with a specified chance of dropping the specified items
    112         */
    113        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    114        {
    115            if (!par1World.isRemote)
    116            {
    117                TileEntityPiston var8 = this.getTileEntityAtLocation(par1World, par2, par3, par4);
    118
    119                if (var8 != null)
    120                {
    121                    Block.blocksList[var8.getStoredBlockID()].dropBlockAsItem(par1World, par2, par3, par4, var8.getBlockMetadata(), 0);
    122                }
    123            }
    124        }
    125
    126        /**
    127         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    128         * their own) Args: x, y, z, neighbor blockID
    129         */
    130        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    131        {
    132            if (!par1World.isRemote && par1World.getBlockTileEntity(par2, par3, par4) == null)
    133            {
    134                ;
    135            }
    136        }
    137
    138        /**
    139         * gets a new TileEntityPiston created with the arguments provided.
    140         */
    141        public static TileEntity getTileEntity(int par0, int par1, int par2, boolean par3, boolean par4)
    142        {
    143            return new TileEntityPiston(par0, par1, par2, par3, par4);
    144        }
    145
    146        /**
    147         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    148         * cleared to be reused)
    149         */
    150        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    151        {
    152            TileEntityPiston var5 = this.getTileEntityAtLocation(par1World, par2, par3, par4);
    153
    154            if (var5 == null)
    155            {
    156                return null;
    157            }
    158            else
    159            {
    160                float var6 = var5.getProgress(0.0F);
    161
    162                if (var5.isExtending())
    163                {
    164                    var6 = 1.0F - var6;
    165                }
    166
    167                return this.getAxisAlignedBB(par1World, par2, par3, par4, var5.getStoredBlockID(), var6, var5.getPistonOrientation());
    168            }
    169        }
    170
    171        /**
    172         * Updates the blocks bounds based on its current state. Args: world, x, y, z
    173         */
    174        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    175        {
    176            TileEntityPiston var5 = this.getTileEntityAtLocation(par1IBlockAccess, par2, par3, par4);
    177
    178            if (var5 != null)
    179            {
    180                Block var6 = Block.blocksList[var5.getStoredBlockID()];
    181
    182                if (var6 == null || var6 == this)
    183                {
    184                    return;
    185                }
    186
    187                var6.setBlockBoundsBasedOnState(par1IBlockAccess, par2, par3, par4);
    188                float var7 = var5.getProgress(0.0F);
    189
    190                if (var5.isExtending())
    191                {
    192                    var7 = 1.0F - var7;
    193                }
    194
    195                int var8 = var5.getPistonOrientation();
    196                this.minX = var6.minX - (double)((float)Facing.offsetsXForSide[var8] * var7);
    197                this.minY = var6.minY - (double)((float)Facing.offsetsYForSide[var8] * var7);
    198                this.minZ = var6.minZ - (double)((float)Facing.offsetsZForSide[var8] * var7);
    199                this.maxX = var6.maxX - (double)((float)Facing.offsetsXForSide[var8] * var7);
    200                this.maxY = var6.maxY - (double)((float)Facing.offsetsYForSide[var8] * var7);
    201                this.maxZ = var6.maxZ - (double)((float)Facing.offsetsZForSide[var8] * var7);
    202            }
    203        }
    204
    205        public AxisAlignedBB getAxisAlignedBB(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    206        {
    207            if (par5 != 0 && par5 != this.blockID)
    208            {
    209                AxisAlignedBB var8 = Block.blocksList[par5].getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
    210
    211                if (var8 == null)
    212                {
    213                    return null;
    214                }
    215                else
    216                {
    217                    if (Facing.offsetsXForSide[par7] < 0)
    218                    {
    219                        var8.minX -= (double)((float)Facing.offsetsXForSide[par7] * par6);
    220                    }
    221                    else
    222                    {
    223                        var8.maxX -= (double)((float)Facing.offsetsXForSide[par7] * par6);
    224                    }
    225
    226                    if (Facing.offsetsYForSide[par7] < 0)
    227                    {
    228                        var8.minY -= (double)((float)Facing.offsetsYForSide[par7] * par6);
    229                    }
    230                    else
    231                    {
    232                        var8.maxY -= (double)((float)Facing.offsetsYForSide[par7] * par6);
    233                    }
    234
    235                    if (Facing.offsetsZForSide[par7] < 0)
    236                    {
    237                        var8.minZ -= (double)((float)Facing.offsetsZForSide[par7] * par6);
    238                    }
    239                    else
    240                    {
    241                        var8.maxZ -= (double)((float)Facing.offsetsZForSide[par7] * par6);
    242                    }
    243
    244                    return var8;
    245                }
    246            }
    247            else
    248            {
    249                return null;
    250            }
    251        }
    252
    253        /**
    254         * gets the piston tile entity at the specified location
    255         */
    256        private TileEntityPiston getTileEntityAtLocation(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    257        {
    258            TileEntity var5 = par1IBlockAccess.getBlockTileEntity(par2, par3, par4);
    259            return var5 instanceof TileEntityPiston ? (TileEntityPiston)var5 : null;
    260        }
    261
    262        @SideOnly(Side.CLIENT)
    263
    264        /**
    265         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    266         */
    267        public int idPicked(World par1World, int par2, int par3, int par4)
    268        {
    269            return 0;
    270        }
    271    }