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