    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    import net.minecraftforge.common.EnumPlantType;
    006    import net.minecraftforge.common.ForgeDirection;
    007    import net.minecraftforge.common.IPlantable;
    008    import static net.minecraftforge.common.EnumPlantType.*;
    009
    010    public class BlockFlower extends Block implements IPlantable
    011    {
    012        protected BlockFlower(int par1, int par2, Material par3Material)
    013        {
    014            super(par1, par3Material);
    015            this.blockIndexInTexture = par2;
    016            this.setTickRandomly(true);
    017            float var4 = 0.2F;
    018            this.setBlockBounds(0.5F - var4, 0.0F, 0.5F - var4, 0.5F + var4, var4 * 3.0F, 0.5F + var4);
    019            this.setCreativeTab(CreativeTabs.tabDecorations);
    020        }
    021
    022        protected BlockFlower(int par1, int par2)
    023        {
    024            this(par1, par2, Material.plants);
    025        }
    026
    027        /**
    028         * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
    029         */
    030        public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    031        {
    032            return super.canPlaceBlockAt(par1World, par2, par3, par4) && canBlockStay(par1World, par2, par3, par4);
    033        }
    034
    035        /**
    036         * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
    037         * blockID passed in. Args: blockID
    038         */
    039        protected boolean canThisPlantGrowOnThisBlockID(int par1)
    040        {
    041            return par1 == Block.grass.blockID || par1 == Block.dirt.blockID || par1 == Block.tilledField.blockID;
    042        }
    043
    044        /**
    045         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    046         * their own) Args: x, y, z, neighbor blockID
    047         */
    048        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    049        {
    050            super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    051            this.checkFlowerChange(par1World, par2, par3, par4);
    052        }
    053
    054        /**
    055         * Ticks the block if it's been scheduled
    056         */
    057        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    058        {
    059            this.checkFlowerChange(par1World, par2, par3, par4);
    060        }
    061
    062        protected final void checkFlowerChange(World par1World, int par2, int par3, int par4)
    063        {
    064            if (!this.canBlockStay(par1World, par2, par3, par4))
    065            {
    066                this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
    067                par1World.setBlockWithNotify(par2, par3, par4, 0);
    068            }
    069        }
    070
    071        /**
    072         * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
    073         */
    074        public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    075        {
    076            Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
    077            return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) &&
    078                    (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
    079        }
    080
    081        /**
    082         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    083         * cleared to be reused)
    084         */
    085        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    086        {
    087            return null;
    088        }
    089
    090        /**
    091         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    092         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    093         */
    094        public boolean isOpaqueCube()
    095        {
    096            return false;
    097        }
    098
    099        /**
    100         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    101         */
    102        public boolean renderAsNormalBlock()
    103        {
    104            return false;
    105        }
    106
    107        /**
    108         * The type of render function that is called for this block
    109         */
    110        public int getRenderType()
    111        {
    112            return 1;
    113        }
    114
    115        @Override
    116        public EnumPlantType getPlantType(World world, int x, int y, int z)
    117        {
    118            if (blockID == crops.blockID        ) return Crop;
    119            if (blockID == deadBush.blockID     ) return Desert;
    120            if (blockID == waterlily.blockID    ) return Water;
    121            if (blockID == mushroomRed.blockID  ) return Cave;
    122            if (blockID == mushroomBrown.blockID) return Cave;
    123            if (blockID == netherStalk.blockID  ) return Nether;
    124            if (blockID == sapling.blockID      ) return Plains;
    125            if (blockID == melonStem.blockID    ) return Crop;
    126            if (blockID == pumpkinStem.blockID  ) return Crop;
    127            if (blockID == tallGrass.blockID    ) return Plains;
    128            return Plains;
    129        }
    130
    131        @Override
    132        public int getPlantID(World world, int x, int y, int z)
    133        {
    134            return blockID;
    135        }
    136
    137        @Override
    138        public int getPlantMetadata(World world, int x, int y, int z)
    139        {
    140            return world.getBlockMetadata(x, y, z);
    141        }
    142    }