    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.Iterator;
    006    import java.util.List;
    007    import java.util.Random;
    008
    009    public class BlockTripWire extends Block
    010    {
    011        public BlockTripWire(int par1)
    012        {
    013            super(par1, 173, Material.circuits);
    014            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.15625F, 1.0F);
    015            this.setTickRandomly(true);
    016        }
    017
    018        /**
    019         * How many world ticks before ticking
    020         */
    021        public int tickRate()
    022        {
    023            return 10;
    024        }
    025
    026        /**
    027         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    028         * cleared to be reused)
    029         */
    030        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    031        {
    032            return null;
    033        }
    034
    035        /**
    036         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    037         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    038         */
    039        public boolean isOpaqueCube()
    040        {
    041            return false;
    042        }
    043
    044        /**
    045         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    046         */
    047        public boolean renderAsNormalBlock()
    048        {
    049            return false;
    050        }
    051
    052        @SideOnly(Side.CLIENT)
    053
    054        /**
    055         * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha
    056         */
    057        public int getRenderBlockPass()
    058        {
    059            return 1;
    060        }
    061
    062        /**
    063         * The type of render function that is called for this block
    064         */
    065        public int getRenderType()
    066        {
    067            return 30;
    068        }
    069
    070        /**
    071         * Returns the ID of the items to drop on destruction.
    072         */
    073        public int idDropped(int par1, Random par2Random, int par3)
    074        {
    075            return Item.silk.shiftedIndex;
    076        }
    077
    078        @SideOnly(Side.CLIENT)
    079
    080        /**
    081         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    082         */
    083        public int idPicked(World par1World, int par2, int par3, int par4)
    084        {
    085            return Item.silk.shiftedIndex;
    086        }
    087
    088        /**
    089         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    090         * their own) Args: x, y, z, neighbor blockID
    091         */
    092        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    093        {
    094            int var6 = par1World.getBlockMetadata(par2, par3, par4);
    095            boolean var7 = (var6 & 2) == 2;
    096            boolean var8 = !par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4);
    097
    098            if (var7 != var8)
    099            {
    100                this.dropBlockAsItem(par1World, par2, par3, par4, var6, 0);
    101                par1World.setBlockWithNotify(par2, par3, par4, 0);
    102            }
    103        }
    104
    105        /**
    106         * Updates the blocks bounds based on its current state. Args: world, x, y, z
    107         */
    108        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    109        {
    110            int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
    111            boolean var6 = (var5 & 4) == 4;
    112            boolean var7 = (var5 & 2) == 2;
    113
    114            if (!var7)
    115            {
    116                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.09375F, 1.0F);
    117            }
    118            else if (!var6)
    119            {
    120                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
    121            }
    122            else
    123            {
    124                this.setBlockBounds(0.0F, 0.0625F, 0.0F, 1.0F, 0.15625F, 1.0F);
    125            }
    126        }
    127
    128        /**
    129         * Called whenever the block is added into the world. Args: world, x, y, z
    130         */
    131        public void onBlockAdded(World par1World, int par2, int par3, int par4)
    132        {
    133            int var5 = par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) ? 0 : 2;
    134            par1World.setBlockMetadataWithNotify(par2, par3, par4, var5);
    135            this.func_72149_e(par1World, par2, par3, par4, var5);
    136        }
    137
    138        /**
    139         * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    140         */
    141        public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    142        {
    143            this.func_72149_e(par1World, par2, par3, par4, par6 | 1);
    144        }
    145
    146        /**
    147         * Called when the block is attempted to be harvested
    148         */
    149        public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer)
    150        {
    151            if (!par1World.isRemote)
    152            {
    153                if (par6EntityPlayer.getCurrentEquippedItem() != null && par6EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
    154                {
    155                    par1World.setBlockMetadataWithNotify(par2, par3, par4, par5 | 8);
    156                }
    157            }
    158        }
    159
    160        private void func_72149_e(World par1World, int par2, int par3, int par4, int par5)
    161        {
    162            int var6 = 0;
    163
    164            while (var6 < 2)
    165            {
    166                int var7 = 1;
    167
    168                while (true)
    169                {
    170                    if (var7 < 42)
    171                    {
    172                        int var8 = par2 + Direction.offsetX[var6] * var7;
    173                        int var9 = par4 + Direction.offsetZ[var6] * var7;
    174                        int var10 = par1World.getBlockId(var8, par3, var9);
    175
    176                        if (var10 == Block.tripWireSource.blockID)
    177                        {
    178                            int var11 = par1World.getBlockMetadata(var8, par3, var9) & 3;
    179
    180                            if (var11 == Direction.footInvisibleFaceRemap[var6])
    181                            {
    182                                Block.tripWireSource.func_72143_a(par1World, var8, par3, var9, var10, par1World.getBlockMetadata(var8, par3, var9), true, var7, par5);
    183                            }
    184                        }
    185                        else if (var10 == Block.tripWire.blockID)
    186                        {
    187                            ++var7;
    188                            continue;
    189                        }
    190                    }
    191
    192                    ++var6;
    193                    break;
    194                }
    195            }
    196        }
    197
    198        /**
    199         * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
    200         */
    201        public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
    202        {
    203            if (!par1World.isRemote)
    204            {
    205                if ((par1World.getBlockMetadata(par2, par3, par4) & 1) != 1)
    206                {
    207                    this.updateTripWireState(par1World, par2, par3, par4);
    208                }
    209            }
    210        }
    211
    212        /**
    213         * Ticks the block if it's been scheduled
    214         */
    215        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    216        {
    217            if (!par1World.isRemote)
    218            {
    219                if ((par1World.getBlockMetadata(par2, par3, par4) & 1) == 1)
    220                {
    221                    this.updateTripWireState(par1World, par2, par3, par4);
    222                }
    223            }
    224        }
    225
    226        private void updateTripWireState(World par1World, int par2, int par3, int par4)
    227        {
    228            int var5 = par1World.getBlockMetadata(par2, par3, par4);
    229            boolean var6 = (var5 & 1) == 1;
    230            boolean var7 = false;
    231            List var8 = par1World.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ));
    232
    233            if (!var8.isEmpty())
    234            {
    235                Iterator var9 = var8.iterator();
    236
    237                while (var9.hasNext())
    238                {
    239                    Entity var10 = (Entity)var9.next();
    240
    241                    if (!var10.doesEntityNotTriggerPressurePlate())
    242                    {
    243                        var7 = true;
    244                        break;
    245                    }
    246                }
    247            }
    248
    249            if (var7 && !var6)
    250            {
    251                var5 |= 1;
    252            }
    253
    254            if (!var7 && var6)
    255            {
    256                var5 &= -2;
    257            }
    258
    259            if (var7 != var6)
    260            {
    261                par1World.setBlockMetadataWithNotify(par2, par3, par4, var5);
    262                this.func_72149_e(par1World, par2, par3, par4, var5);
    263            }
    264
    265            if (var7)
    266            {
    267                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());
    268            }
    269        }
    270
    271        @SideOnly(Side.CLIENT)
    272        public static boolean func_72148_a(IBlockAccess par0IBlockAccess, int par1, int par2, int par3, int par4, int par5)
    273        {
    274            int var6 = par1 + Direction.offsetX[par5];
    275            int var8 = par3 + Direction.offsetZ[par5];
    276            int var9 = par0IBlockAccess.getBlockId(var6, par2, var8);
    277            boolean var10 = (par4 & 2) == 2;
    278            int var11;
    279
    280            if (var9 == Block.tripWireSource.blockID)
    281            {
    282                var11 = par0IBlockAccess.getBlockMetadata(var6, par2, var8);
    283                int var13 = var11 & 3;
    284                return var13 == Direction.footInvisibleFaceRemap[par5];
    285            }
    286            else if (var9 == Block.tripWire.blockID)
    287            {
    288                var11 = par0IBlockAccess.getBlockMetadata(var6, par2, var8);
    289                boolean var12 = (var11 & 2) == 2;
    290                return var10 == var12;
    291            }
    292            else
    293            {
    294                return false;
    295            }
    296        }
    297    }