    001    package net.minecraft.src;
    002
    003    import java.util.Iterator;
    004    import java.util.List;
    005    import java.util.Random;
    006
    007    public class BlockPressurePlate extends Block
    008    {
    009        /** The mob type that can trigger this pressure plate. */
    010        private EnumMobType triggerMobType;
    011
    012        protected BlockPressurePlate(int par1, int par2, EnumMobType par3EnumMobType, Material par4Material)
    013        {
    014            super(par1, par2, par4Material);
    015            this.triggerMobType = par3EnumMobType;
    016            this.setCreativeTab(CreativeTabs.tabRedstone);
    017            this.setTickRandomly(true);
    018            float var5 = 0.0625F;
    019            this.setBlockBounds(var5, 0.0F, var5, 1.0F - var5, 0.03125F, 1.0F - var5);
    020        }
    021
    022        /**
    023         * How many world ticks before ticking
    024         */
    025        public int tickRate()
    026        {
    027            return 20;
    028        }
    029
    030        /**
    031         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    032         * cleared to be reused)
    033         */
    034        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    035        {
    036            return null;
    037        }
    038
    039        /**
    040         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    041         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    042         */
    043        public boolean isOpaqueCube()
    044        {
    045            return false;
    046        }
    047
    048        /**
    049         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    050         */
    051        public boolean renderAsNormalBlock()
    052        {
    053            return false;
    054        }
    055
    056        public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    057        {
    058            return true;
    059        }
    060
    061        /**
    062         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    063         */
    064        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    065        {
    066            return par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) || BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4));
    067        }
    068
    069        /**
    070         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    071         * their own) Args: x, y, z, neighbor blockID
    072         */
    073        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    074        {
    075            boolean var6 = false;
    076
    077            if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4)))
    078            {
    079                var6 = true;
    080            }
    081
    082            if (var6)
    083            {
    084                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    085                par1World.setBlockWithNotify(par2, par3, par4, 0);
    086            }
    087        }
    088
    089        /**
    090         * Ticks the block if it's been scheduled
    091         */
    092        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    093        {
    094            if (!par1World.isRemote)
    095            {
    096                if (par1World.getBlockMetadata(par2, par3, par4) != 0)
    097                {
    098                    this.setStateIfMobInteractsWithPlate(par1World, par2, par3, par4);
    099                }
    100            }
    101        }
    102
    103        /**
    104         * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
    105         */
    106        public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
    107        {
    108            if (!par1World.isRemote)
    109            {
    110                if (par1World.getBlockMetadata(par2, par3, par4) != 1)
    111                {
    112                    this.setStateIfMobInteractsWithPlate(par1World, par2, par3, par4);
    113                }
    114            }
    115        }
    116
    117        /**
    118         * Checks if there are mobs on the plate. If a mob is on the plate and it is off, it turns it on, and vice versa.
    119         */
    120        private void setStateIfMobInteractsWithPlate(World par1World, int par2, int par3, int par4)
    121        {
    122            boolean var5 = par1World.getBlockMetadata(par2, par3, par4) == 1;
    123            boolean var6 = false;
    124            float var7 = 0.125F;
    125            List var8 = null;
    126
    127            if (this.triggerMobType == EnumMobType.everything)
    128            {
    129                var8 = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
    130            }
    131
    132            if (this.triggerMobType == EnumMobType.mobs)
    133            {
    134                var8 = par1World.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
    135            }
    136
    137            if (this.triggerMobType == EnumMobType.players)
    138            {
    139                var8 = par1World.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var7), (double)((float)(par2 + 1) - var7), (double)par3 + 0.25D, (double)((float)(par4 + 1) - var7)));
    140            }
    141
    142            if (!var8.isEmpty())
    143            {
    144                Iterator var9 = var8.iterator();
    145
    146                while (var9.hasNext())
    147                {
    148                    Entity var10 = (Entity)var9.next();
    149
    150                    if (!var10.func_82144_au())
    151                    {
    152                        var6 = true;
    153                        break;
    154                    }
    155                }
    156            }
    157
    158            if (var6 && !var5)
    159            {
    160                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
    161                par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
    162                par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
    163                par1World.markBlocksDirty(par2, par3, par4, par2, par3, par4);
    164                par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.1D, (double)par4 + 0.5D, "random.click", 0.3F, 0.6F);
    165            }
    166
    167            if (!var6 && var5)
    168            {
    169                par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
    170                par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
    171                par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
    172                par1World.markBlocksDirty(par2, par3, par4, par2, par3, par4);
    173                par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.1D, (double)par4 + 0.5D, "random.click", 0.3F, 0.5F);
    174            }
    175
    176            if (var6)
    177            {
    178                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    179            }
    180        }
    181
    182        /**
    183         * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    184         */
    185        public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    186        {
    187            if (par6 > 0)
    188            {
    189                par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
    190                par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
    191            }
    192
    193            super.breakBlock(par1World, par2, par3, par4, par5, par6);
    194        }
    195
    196        /**
    197         * Updates the blocks bounds based on its current state. Args: world, x, y, z
    198         */
    199        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    200        {
    201            boolean var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 1;
    202            float var6 = 0.0625F;
    203
    204            if (var5)
    205            {
    206                this.setBlockBounds(var6, 0.0F, var6, 1.0F - var6, 0.03125F, 1.0F - var6);
    207            }
    208            else
    209            {
    210                this.setBlockBounds(var6, 0.0F, var6, 1.0F - var6, 0.0625F, 1.0F - var6);
    211            }
    212        }
    213
    214        /**
    215         * Is this block powering the block on the specified side
    216         */
    217        public boolean isPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    218        {
    219            return par1IBlockAccess.getBlockMetadata(par2, par3, par4) > 0;
    220        }
    221
    222        /**
    223         * Is this block indirectly powering the block on the specified side
    224         */
    225        public boolean isIndirectlyPoweringTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    226        {
    227            return par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 0 ? false : par5 == 1;
    228        }
    229
    230        /**
    231         * Can this block provide power. Only wire currently seems to have this change based on its state.
    232         */
    233        public boolean canProvidePower()
    234        {
    235            return true;
    236        }
    237
    238        /**
    239         * Sets the block's bounds for rendering it as an item
    240         */
    241        public void setBlockBoundsForItemRender()
    242        {
    243            float var1 = 0.5F;
    244            float var2 = 0.125F;
    245            float var3 = 0.5F;
    246            this.setBlockBounds(0.5F - var1, 0.5F - var2, 0.5F - var3, 0.5F + var1, 0.5F + var2, 0.5F + var3);
    247        }
    248
    249        /**
    250         * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility
    251         * and stop pistons
    252         */
    253        public int getMobilityFlag()
    254        {
    255            return 1;
    256        }
    257    }