    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 BlockCake extends Block
    008    {
    009        protected BlockCake(int par1, int par2)
    010        {
    011            super(par1, par2, Material.cake);
    012            this.setTickRandomly(true);
    013        }
    014
    015        /**
    016         * Updates the blocks bounds based on its current state. Args: world, x, y, z
    017         */
    018        public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    019        {
    020            int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
    021            float var6 = 0.0625F;
    022            float var7 = (float)(1 + var5 * 2) / 16.0F;
    023            float var8 = 0.5F;
    024            this.setBlockBounds(var7, 0.0F, var6, 1.0F - var6, var8, 1.0F - var6);
    025        }
    026
    027        /**
    028         * Sets the block's bounds for rendering it as an item
    029         */
    030        public void setBlockBoundsForItemRender()
    031        {
    032            float var1 = 0.0625F;
    033            float var2 = 0.5F;
    034            this.setBlockBounds(var1, 0.0F, var1, 1.0F - var1, var2, 1.0F - var1);
    035        }
    036
    037        /**
    038         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    039         * cleared to be reused)
    040         */
    041        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    042        {
    043            int var5 = par1World.getBlockMetadata(par2, par3, par4);
    044            float var6 = 0.0625F;
    045            float var7 = (float)(1 + var5 * 2) / 16.0F;
    046            float var8 = 0.5F;
    047            return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var6), (double)((float)(par2 + 1) - var6), (double)((float)par3 + var8 - var6), (double)((float)(par4 + 1) - var6));
    048        }
    049
    050        @SideOnly(Side.CLIENT)
    051
    052        /**
    053         * Returns the bounding box of the wired rectangular prism to render.
    054         */
    055        public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    056        {
    057            int var5 = par1World.getBlockMetadata(par2, par3, par4);
    058            float var6 = 0.0625F;
    059            float var7 = (float)(1 + var5 * 2) / 16.0F;
    060            float var8 = 0.5F;
    061            return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var7), (double)par3, (double)((float)par4 + var6), (double)((float)(par2 + 1) - var6), (double)((float)par3 + var8), (double)((float)(par4 + 1) - var6));
    062        }
    063
    064        /**
    065         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    066         */
    067        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    068        {
    069            return par1 == 1 ? this.blockIndexInTexture : (par1 == 0 ? this.blockIndexInTexture + 3 : (par2 > 0 && par1 == 4 ? this.blockIndexInTexture + 2 : this.blockIndexInTexture + 1));
    070        }
    071
    072        /**
    073         * Returns the block texture based on the side being looked at.  Args: side
    074         */
    075        public int getBlockTextureFromSide(int par1)
    076        {
    077            return par1 == 1 ? this.blockIndexInTexture : (par1 == 0 ? this.blockIndexInTexture + 3 : this.blockIndexInTexture + 1);
    078        }
    079
    080        /**
    081         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    082         */
    083        public boolean renderAsNormalBlock()
    084        {
    085            return false;
    086        }
    087
    088        /**
    089         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    090         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    091         */
    092        public boolean isOpaqueCube()
    093        {
    094            return false;
    095        }
    096
    097        /**
    098         * Called upon block activation (right click on the block.)
    099         */
    100        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    101        {
    102            this.eatCakeSlice(par1World, par2, par3, par4, par5EntityPlayer);
    103            return true;
    104        }
    105
    106        /**
    107         * Called when the block is clicked by a player. Args: x, y, z, entityPlayer
    108         */
    109        public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    110        {
    111            this.eatCakeSlice(par1World, par2, par3, par4, par5EntityPlayer);
    112        }
    113
    114        /**
    115         * Heals the player and removes a slice from the cake.
    116         */
    117        private void eatCakeSlice(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    118        {
    119            if (par5EntityPlayer.canEat(false))
    120            {
    121                par5EntityPlayer.getFoodStats().addStats(2, 0.1F);
    122                int var6 = par1World.getBlockMetadata(par2, par3, par4) + 1;
    123
    124                if (var6 >= 6)
    125                {
    126                    par1World.setBlockWithNotify(par2, par3, par4, 0);
    127                }
    128                else
    129                {
    130                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
    131                    par1World.markBlockAsNeedsUpdate(par2, par3, par4);
    132                }
    133            }
    134        }
    135
    136        /**
    137         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    138         */
    139        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    140        {
    141            return !super.canPlaceBlockAt(par1World, par2, par3, par4) ? false : this.canBlockStay(par1World, par2, par3, par4);
    142        }
    143
    144        /**
    145         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    146         * their own) Args: x, y, z, neighbor blockID
    147         */
    148        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    149        {
    150            if (!this.canBlockStay(par1World, par2, par3, par4))
    151            {
    152                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    153                par1World.setBlockWithNotify(par2, par3, par4, 0);
    154            }
    155        }
    156
    157        /**
    158         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
    159         */
    160        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    161        {
    162            return par1World.getBlockMaterial(par2, par3 - 1, par4).isSolid();
    163        }
    164
    165        /**
    166         * Returns the quantity of items to drop on block destruction.
    167         */
    168        public int quantityDropped(Random par1Random)
    169        {
    170            return 0;
    171        }
    172
    173        /**
    174         * Returns the ID of the items to drop on destruction.
    175         */
    176        public int idDropped(int par1, Random par2Random, int par3)
    177        {
    178            return 0;
    179        }
    180
    181        @SideOnly(Side.CLIENT)
    182
    183        /**
    184         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    185         */
    186        public int idPicked(World par1World, int par2, int par3, int par4)
    187        {
    188            return Item.cake.shiftedIndex;
    189        }
    190    }