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    import net.minecraftforge.common.EnumPlantType;
008    import net.minecraftforge.common.ForgeDirection;
009    import net.minecraftforge.common.IPlantable;
010    
011    public class BlockReed extends Block implements IPlantable
012    {
013        protected BlockReed(int par1, int par2)
014        {
015            super(par1, Material.plants);
016            this.blockIndexInTexture = par2;
017            float var3 = 0.375F;
018            this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 1.0F, 0.5F + var3);
019            this.setTickRandomly(true);
020        }
021    
022        /**
023         * Ticks the block if it's been scheduled
024         */
025        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
026        {
027            if (par1World.isAirBlock(par2, par3 + 1, par4))
028            {
029                int var6;
030    
031                for (var6 = 1; par1World.getBlockId(par2, par3 - var6, par4) == this.blockID; ++var6)
032                {
033                    ;
034                }
035    
036                if (var6 < 3)
037                {
038                    int var7 = par1World.getBlockMetadata(par2, par3, par4);
039    
040                    if (var7 == 15)
041                    {
042                        par1World.setBlockWithNotify(par2, par3 + 1, par4, this.blockID);
043                        par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
044                    }
045                    else
046                    {
047                        par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 + 1);
048                    }
049                }
050            }
051        }
052    
053        /**
054         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
055         */
056        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
057        {
058            Block block = Block.blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
059            return (block != null && block.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
060        }
061    
062        /**
063         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
064         * their own) Args: x, y, z, neighbor blockID
065         */
066        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
067        {
068            this.checkBlockCoordValid(par1World, par2, par3, par4);
069        }
070    
071        /**
072         * Checks if current block pos is valid, if not, breaks the block as dropable item. Used for reed and cactus.
073         */
074        protected final void checkBlockCoordValid(World par1World, int par2, int par3, int par4)
075        {
076            if (!this.canBlockStay(par1World, par2, par3, par4))
077            {
078                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
079                par1World.setBlockWithNotify(par2, par3, par4, 0);
080            }
081        }
082    
083        /**
084         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
085         */
086        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
087        {
088            return this.canPlaceBlockAt(par1World, par2, par3, par4);
089        }
090    
091        /**
092         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
093         * cleared to be reused)
094         */
095        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
096        {
097            return null;
098        }
099    
100        /**
101         * Returns the ID of the items to drop on destruction.
102         */
103        public int idDropped(int par1, Random par2Random, int par3)
104        {
105            return Item.reed.shiftedIndex;
106        }
107    
108        /**
109         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
110         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
111         */
112        public boolean isOpaqueCube()
113        {
114            return false;
115        }
116    
117        /**
118         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
119         */
120        public boolean renderAsNormalBlock()
121        {
122            return false;
123        }
124    
125        /**
126         * The type of render function that is called for this block
127         */
128        public int getRenderType()
129        {
130            return 1;
131        }
132    
133        @SideOnly(Side.CLIENT)
134    
135        /**
136         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
137         */
138        public int idPicked(World par1World, int par2, int par3, int par4)
139        {
140            return Item.reed.shiftedIndex;
141        }
142    
143        @Override
144        public EnumPlantType getPlantType(World world, int x, int y, int z)
145        {
146            return EnumPlantType.Beach;
147        }
148    
149        @Override
150        public int getPlantID(World world, int x, int y, int z)
151        {
152            return blockID;
153        }
154    
155        @Override
156        public int getPlantMetadata(World world, int x, int y, int z)
157        {
158            return world.getBlockMetadata(x, y, z);
159        }
160    }