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