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.Random;
006    
007    public class BlockCactus extends Block
008    {
009        protected BlockCactus(int par1, int par2)
010        {
011            super(par1, par2, Material.cactus);
012            this.setTickRandomly(true);
013            this.setCreativeTab(CreativeTabs.tabDecorations);
014        }
015    
016        /**
017         * Ticks the block if it's been scheduled
018         */
019        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
020        {
021            if (par1World.isAirBlock(par2, par3 + 1, par4))
022            {
023                int var6;
024    
025                for (var6 = 1; par1World.getBlockId(par2, par3 - var6, par4) == this.blockID; ++var6)
026                {
027                    ;
028                }
029    
030                if (var6 < 3)
031                {
032                    int var7 = par1World.getBlockMetadata(par2, par3, par4);
033    
034                    if (var7 == 15)
035                    {
036                        par1World.setBlockWithNotify(par2, par3 + 1, par4, this.blockID);
037                        par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
038                    }
039                    else
040                    {
041                        par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 + 1);
042                    }
043                }
044            }
045        }
046    
047        /**
048         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
049         * cleared to be reused)
050         */
051        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
052        {
053            float var5 = 0.0625F;
054            return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var5), (double)par3, (double)((float)par4 + var5), (double)((float)(par2 + 1) - var5), (double)((float)(par3 + 1) - var5), (double)((float)(par4 + 1) - var5));
055        }
056    
057        @SideOnly(Side.CLIENT)
058    
059        /**
060         * Returns the bounding box of the wired rectangular prism to render.
061         */
062        public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
063        {
064            float var5 = 0.0625F;
065            return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var5), (double)par3, (double)((float)par4 + var5), (double)((float)(par2 + 1) - var5), (double)(par3 + 1), (double)((float)(par4 + 1) - var5));
066        }
067    
068        /**
069         * Returns the block texture based on the side being looked at.  Args: side
070         */
071        public int getBlockTextureFromSide(int par1)
072        {
073            return par1 == 1 ? this.blockIndexInTexture - 1 : (par1 == 0 ? this.blockIndexInTexture + 1 : this.blockIndexInTexture);
074        }
075    
076        /**
077         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
078         */
079        public boolean renderAsNormalBlock()
080        {
081            return false;
082        }
083    
084        /**
085         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
086         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
087         */
088        public boolean isOpaqueCube()
089        {
090            return false;
091        }
092    
093        /**
094         * The type of render function that is called for this block
095         */
096        public int getRenderType()
097        {
098            return 13;
099        }
100    
101        /**
102         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
103         */
104        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
105        {
106            return !super.canPlaceBlockAt(par1World, par2, par3, par4) ? false : this.canBlockStay(par1World, par2, par3, par4);
107        }
108    
109        /**
110         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
111         * their own) Args: x, y, z, neighbor blockID
112         */
113        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
114        {
115            if (!this.canBlockStay(par1World, par2, par3, par4))
116            {
117                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
118                par1World.setBlockWithNotify(par2, par3, par4, 0);
119            }
120        }
121    
122        /**
123         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
124         */
125        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
126        {
127            if (par1World.getBlockMaterial(par2 - 1, par3, par4).isSolid())
128            {
129                return false;
130            }
131            else if (par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
132            {
133                return false;
134            }
135            else if (par1World.getBlockMaterial(par2, par3, par4 - 1).isSolid())
136            {
137                return false;
138            }
139            else if (par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
140            {
141                return false;
142            }
143            else
144            {
145                int var5 = par1World.getBlockId(par2, par3 - 1, par4);
146                return var5 == Block.cactus.blockID || var5 == Block.sand.blockID;
147            }
148        }
149    
150        /**
151         * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
152         */
153        public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
154        {
155            par5Entity.attackEntityFrom(DamageSource.cactus, 1);
156        }
157    }