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