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