001    package net.minecraft.block;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    
006    import java.util.ArrayList;
007    import java.util.Random;
008    import net.minecraft.block.material.Material;
009    import net.minecraft.entity.EntityLiving;
010    import net.minecraft.item.Item;
011    import net.minecraft.item.ItemStack;
012    import net.minecraft.util.AxisAlignedBB;
013    import net.minecraft.util.Direction;
014    import net.minecraft.util.MathHelper;
015    import net.minecraft.world.IBlockAccess;
016    import net.minecraft.world.World;
017    
018    public class BlockCocoa extends BlockDirectional
019    {
020        public BlockCocoa(int par1)
021        {
022            super(par1, 168, Material.plants);
023            this.setTickRandomly(true);
024        }
025    
026        /**
027         * Ticks the block if it's been scheduled
028         */
029        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
030        {
031            if (!this.canBlockStay(par1World, par2, par3, par4))
032            {
033                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
034                par1World.setBlockWithNotify(par2, par3, par4, 0);
035            }
036            else if (par1World.rand.nextInt(5) == 0)
037            {
038                int var6 = par1World.getBlockMetadata(par2, par3, par4);
039                int var7 = func_72219_c(var6);
040    
041                if (var7 < 2)
042                {
043                    ++var7;
044                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 << 2 | getDirection(var6));
045                }
046            }
047        }
048    
049        /**
050         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
051         */
052        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
053        {
054            int var5 = getDirection(par1World.getBlockMetadata(par2, par3, par4));
055            par2 += Direction.offsetX[var5];
056            par4 += Direction.offsetZ[var5];
057            int var6 = par1World.getBlockId(par2, par3, par4);
058            return var6 == Block.wood.blockID && BlockLog.limitToValidMetadata(par1World.getBlockMetadata(par2, par3, par4)) == 3;
059        }
060    
061        /**
062         * The type of render function that is called for this block
063         */
064        public int getRenderType()
065        {
066            return 28;
067        }
068    
069        /**
070         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
071         */
072        public boolean renderAsNormalBlock()
073        {
074            return false;
075        }
076    
077        /**
078         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
079         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
080         */
081        public boolean isOpaqueCube()
082        {
083            return false;
084        }
085    
086        /**
087         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
088         * cleared to be reused)
089         */
090        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
091        {
092            this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
093            return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
094        }
095    
096        @SideOnly(Side.CLIENT)
097    
098        /**
099         * Returns the bounding box of the wired rectangular prism to render.
100         */
101        public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
102        {
103            this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
104            return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
105        }
106    
107        /**
108         * Updates the blocks bounds based on its current state. Args: world, x, y, z
109         */
110        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
111        {
112            int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
113            int var6 = getDirection(var5);
114            int var7 = func_72219_c(var5);
115            int var8 = 4 + var7 * 2;
116            int var9 = 5 + var7 * 2;
117            float var10 = (float)var8 / 2.0F;
118    
119            switch (var6)
120            {
121                case 0:
122                    this.setBlockBounds((8.0F - var10) / 16.0F, (12.0F - (float)var9) / 16.0F, (15.0F - (float)var8) / 16.0F, (8.0F + var10) / 16.0F, 0.75F, 0.9375F);
123                    break;
124                case 1:
125                    this.setBlockBounds(0.0625F, (12.0F - (float)var9) / 16.0F, (8.0F - var10) / 16.0F, (1.0F + (float)var8) / 16.0F, 0.75F, (8.0F + var10) / 16.0F);
126                    break;
127                case 2:
128                    this.setBlockBounds((8.0F - var10) / 16.0F, (12.0F - (float)var9) / 16.0F, 0.0625F, (8.0F + var10) / 16.0F, 0.75F, (1.0F + (float)var8) / 16.0F);
129                    break;
130                case 3:
131                    this.setBlockBounds((15.0F - (float)var8) / 16.0F, (12.0F - (float)var9) / 16.0F, (8.0F - var10) / 16.0F, 0.9375F, 0.75F, (8.0F + var10) / 16.0F);
132            }
133        }
134    
135        /**
136         * Called when the block is placed in the world.
137         */
138        public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
139        {
140            int var6 = ((MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) + 0) % 4;
141            par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
142        }
143    
144        public int func_85104_a(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
145        {
146            if (par5 == 1 || par5 == 0)
147            {
148                par5 = 2;
149            }
150    
151            return Direction.footInvisibleFaceRemap[Direction.vineGrowth[par5]];
152        }
153    
154        /**
155         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
156         * their own) Args: x, y, z, neighbor blockID
157         */
158        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
159        {
160            if (!this.canBlockStay(par1World, par2, par3, par4))
161            {
162                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
163                par1World.setBlockWithNotify(par2, par3, par4, 0);
164            }
165        }
166    
167        public static int func_72219_c(int par0)
168        {
169            return (par0 & 12) >> 2;
170        }
171    
172        /**
173         * Drops the block items with a specified chance of dropping the specified items
174         */
175        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
176        {
177            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
178        }
179    
180        @Override
181        public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
182        {
183            ArrayList<ItemStack> dropped = super.getBlockDropped(world, x, y, z, metadata, fortune);
184            int var8 = func_72219_c(metadata);
185            byte var9 = 1;
186    
187            if (var8 >= 2)
188            {
189                var9 = 3;
190            }
191    
192            for (int var10 = 0; var10 < var9; ++var10)
193            {
194                dropped.add(new ItemStack(Item.dyePowder, 1, 3));
195            }
196            return dropped;
197        }
198    
199        @SideOnly(Side.CLIENT)
200    
201        /**
202         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
203         */
204        public int idPicked(World par1World, int par2, int par3, int par4)
205        {
206            return Item.dyePowder.shiftedIndex;
207        }
208    
209        /**
210         * Get the block's damage value (for use with pick block).
211         */
212        public int getDamageValue(World par1World, int par2, int par3, int par4)
213        {
214            return 3;
215        }
216    
217        @Override
218        public int idDropped(int par1, Random par2Random, int par3)
219        {
220            return 0;
221        }
222    }