    001    package net.minecraft.block;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.util.Random;
    006    import net.minecraft.block.material.Material;
    007    import net.minecraft.entity.player.EntityPlayer;
    008    import net.minecraft.item.Item;
    009    import net.minecraft.item.ItemStack;
    010    import net.minecraft.world.World;
    011
    012    public class BlockFlowerPot extends Block
    013    {
    014        public BlockFlowerPot(int par1)
    015        {
    016            super(par1, Material.circuits);
    017            this.blockIndexInTexture = 186;
    018            this.setBlockBoundsForItemRender();
    019            this.setRequiresSelfNotify();
    020        }
    021
    022        /**
    023         * Sets the block's bounds for rendering it as an item
    024         */
    025        public void setBlockBoundsForItemRender()
    026        {
    027            float var1 = 0.375F;
    028            float var2 = var1 / 2.0F;
    029            this.setBlockBounds(0.5F - var2, 0.0F, 0.5F - var2, 0.5F + var2, var1, 0.5F + var2);
    030        }
    031
    032        /**
    033         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    034         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    035         */
    036        public boolean isOpaqueCube()
    037        {
    038            return false;
    039        }
    040
    041        /**
    042         * The type of render function that is called for this block
    043         */
    044        public int getRenderType()
    045        {
    046            return 33;
    047        }
    048
    049        /**
    050         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    051         */
    052        public boolean renderAsNormalBlock()
    053        {
    054            return false;
    055        }
    056
    057        /**
    058         * Called upon block activation (right click on the block.)
    059         */
    060        public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    061        {
    062            ItemStack var10 = par5EntityPlayer.inventory.getCurrentItem();
    063
    064            if (var10 == null)
    065            {
    066                return false;
    067            }
    068            else if (par1World.getBlockMetadata(par2, par3, par4) != 0)
    069            {
    070                return false;
    071            }
    072            else
    073            {
    074                int var11 = getMetaForPlant(var10);
    075
    076                if (var11 > 0)
    077                {
    078                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var11);
    079
    080                    if (!par5EntityPlayer.capabilities.isCreativeMode && --var10.stackSize <= 0)
    081                    {
    082                        par5EntityPlayer.inventory.setInventorySlotContents(par5EntityPlayer.inventory.currentItem, (ItemStack)null);
    083                    }
    084
    085                    return true;
    086                }
    087                else
    088                {
    089                    return false;
    090                }
    091            }
    092        }
    093
    094        @SideOnly(Side.CLIENT)
    095
    096        /**
    097         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    098         */
    099        public int idPicked(World par1World, int par2, int par3, int par4)
    100        {
    101            ItemStack var5 = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4));
    102            return var5 == null ? Item.flowerPot.shiftedIndex : var5.itemID;
    103        }
    104
    105        /**
    106         * Get the block's damage value (for use with pick block).
    107         */
    108        public int getDamageValue(World par1World, int par2, int par3, int par4)
    109        {
    110            ItemStack var5 = getPlantForMeta(par1World.getBlockMetadata(par2, par3, par4));
    111            return var5 == null ? Item.flowerPot.shiftedIndex : var5.getItemDamage();
    112        }
    113
    114        @SideOnly(Side.CLIENT)
    115        public boolean func_82505_u_()
    116        {
    117            return true;
    118        }
    119
    120        /**
    121         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    122         */
    123        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    124        {
    125            return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4);
    126        }
    127
    128        /**
    129         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    130         * their own) Args: x, y, z, neighbor blockID
    131         */
    132        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    133        {
    134            if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
    135            {
    136                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    137                par1World.setBlockWithNotify(par2, par3, par4, 0);
    138            }
    139        }
    140
    141        /**
    142         * Drops the block items with a specified chance of dropping the specified items
    143         */
    144        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    145        {
    146            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, par7);
    147
    148            if (par5 > 0)
    149            {
    150                ItemStack var8 = getPlantForMeta(par5);
    151
    152                if (var8 != null)
    153                {
    154                    this.dropBlockAsItem_do(par1World, par2, par3, par4, var8);
    155                }
    156            }
    157        }
    158
    159        /**
    160         * Returns the ID of the items to drop on destruction.
    161         */
    162        public int idDropped(int par1, Random par2Random, int par3)
    163        {
    164            return Item.flowerPot.shiftedIndex;
    165        }
    166
    167        /**
    168         * Return the item associated with the specified flower pot metadata value.
    169         */
    170        public static ItemStack getPlantForMeta(int par0)
    171        {
    172            switch (par0)
    173            {
    174                case 1:
    175                    return new ItemStack(Block.plantRed);
    176                case 2:
    177                    return new ItemStack(Block.plantYellow);
    178                case 3:
    179                    return new ItemStack(Block.sapling, 1, 0);
    180                case 4:
    181                    return new ItemStack(Block.sapling, 1, 1);
    182                case 5:
    183                    return new ItemStack(Block.sapling, 1, 2);
    184                case 6:
    185                    return new ItemStack(Block.sapling, 1, 3);
    186                case 7:
    187                    return new ItemStack(Block.mushroomRed);
    188                case 8:
    189                    return new ItemStack(Block.mushroomBrown);
    190                case 9:
    191                    return new ItemStack(Block.cactus);
    192                case 10:
    193                    return new ItemStack(Block.deadBush);
    194                case 11:
    195                    return new ItemStack(Block.tallGrass, 1, 2);
    196                default:
    197                    return null;
    198            }
    199        }
    200
    201        /**
    202         * Return the flower pot metadata value associated with the specified item.
    203         */
    204        public static int getMetaForPlant(ItemStack par0ItemStack)
    205        {
    206            int var1 = par0ItemStack.getItem().shiftedIndex;
    207
    208            if (var1 == Block.plantRed.blockID)
    209            {
    210                return 1;
    211            }
    212            else if (var1 == Block.plantYellow.blockID)
    213            {
    214                return 2;
    215            }
    216            else if (var1 == Block.cactus.blockID)
    217            {
    218                return 9;
    219            }
    220            else if (var1 == Block.mushroomBrown.blockID)
    221            {
    222                return 8;
    223            }
    224            else if (var1 == Block.mushroomRed.blockID)
    225            {
    226                return 7;
    227            }
    228            else if (var1 == Block.deadBush.blockID)
    229            {
    230                return 10;
    231            }
    232            else
    233            {
    234                if (var1 == Block.sapling.blockID)
    235                {
    236                    switch (par0ItemStack.getItemDamage())
    237                    {
    238                        case 0:
    239                            return 3;
    240                        case 1:
    241                            return 4;
    242                        case 2:
    243                            return 5;
    244                        case 3:
    245                            return 6;
    246                    }
    247                }
    248
    249                if (var1 == Block.tallGrass.blockID)
    250                {
    251                    switch (par0ItemStack.getItemDamage())
    252                    {
    253                        case 2:
    254                            return 11;
    255                    }
    256                }
    257
    258                return 0;
    259            }
    260        }
    261    }