    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    import net.minecraftforge.common.ForgeDirection;
    008    import net.minecraftforge.common.IPlantable;
    009
    010    public class BlockFarmland extends Block
    011    {
    012        protected BlockFarmland(int par1)
    013        {
    014            super(par1, Material.ground);
    015            this.blockIndexInTexture = 87;
    016            this.setTickRandomly(true);
    017            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F);
    018            this.setLightOpacity(255);
    019        }
    020
    021        /**
    022         * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
    023         * cleared to be reused)
    024         */
    025        public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    026        {
    027            return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)(par2 + 0), (double)(par3 + 0), (double)(par4 + 0), (double)(par2 + 1), (double)(par3 + 1), (double)(par4 + 1));
    028        }
    029
    030        /**
    031         * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
    032         * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
    033         */
    034        public boolean isOpaqueCube()
    035        {
    036            return false;
    037        }
    038
    039        /**
    040         * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
    041         */
    042        public boolean renderAsNormalBlock()
    043        {
    044            return false;
    045        }
    046
    047        /**
    048         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    049         */
    050        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    051        {
    052            return par1 == 1 && par2 > 0 ? this.blockIndexInTexture - 1 : (par1 == 1 ? this.blockIndexInTexture : 2);
    053        }
    054
    055        /**
    056         * Ticks the block if it's been scheduled
    057         */
    058        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    059        {
    060            if (!this.isWaterNearby(par1World, par2, par3, par4) && !par1World.canLightningStrikeAt(par2, par3 + 1, par4))
    061            {
    062                int var6 = par1World.getBlockMetadata(par2, par3, par4);
    063
    064                if (var6 > 0)
    065                {
    066                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 - 1);
    067                }
    068                else if (!this.isCropsNearby(par1World, par2, par3, par4))
    069                {
    070                    par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID);
    071                }
    072            }
    073            else
    074            {
    075                par1World.setBlockMetadataWithNotify(par2, par3, par4, 7);
    076            }
    077        }
    078
    079        /**
    080         * Block's chance to react to an entity falling on it.
    081         */
    082        public void onFallenUpon(World par1World, int par2, int par3, int par4, Entity par5Entity, float par6)
    083        {
    084            if (!par1World.isRemote && par1World.rand.nextFloat() < par6 - 0.5F)
    085            {
    086                par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID);
    087            }
    088        }
    089
    090        /**
    091         * returns true if there is at least one cropblock nearby (x-1 to x+1, y+1, z-1 to z+1)
    092         */
    093        private boolean isCropsNearby(World par1World, int par2, int par3, int par4)
    094        {
    095            byte var5 = 0;
    096
    097            for (int var6 = par2 - var5; var6 <= par2 + var5; ++var6)
    098            {
    099                for (int var7 = par4 - var5; var7 <= par4 + var5; ++var7)
    100                {
    101                    int var8 = par1World.getBlockId(var6, par3 + 1, var7);
    102
    103                    Block plant = blocksList[var8];
    104                    if (plant instanceof IPlantable && canSustainPlant(par1World, par2, par3, par4, ForgeDirection.UP, (IPlantable)plant))
    105                    {
    106                        return true;
    107                    }
    108                }
    109            }
    110
    111            return false;
    112        }
    113
    114        /**
    115         * returns true if there's water nearby (x-4 to x+4, y to y+1, k-4 to k+4)
    116         */
    117        private boolean isWaterNearby(World par1World, int par2, int par3, int par4)
    118        {
    119            for (int var5 = par2 - 4; var5 <= par2 + 4; ++var5)
    120            {
    121                for (int var6 = par3; var6 <= par3 + 1; ++var6)
    122                {
    123                    for (int var7 = par4 - 4; var7 <= par4 + 4; ++var7)
    124                    {
    125                        if (par1World.getBlockMaterial(var5, var6, var7) == Material.water)
    126                        {
    127                            return true;
    128                        }
    129                    }
    130                }
    131            }
    132
    133            return false;
    134        }
    135
    136        /**
    137         * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    138         * their own) Args: x, y, z, neighbor blockID
    139         */
    140        public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    141        {
    142            super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
    143            Material var6 = par1World.getBlockMaterial(par2, par3 + 1, par4);
    144
    145            if (var6.isSolid())
    146            {
    147                par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID);
    148            }
    149        }
    150
    151        /**
    152         * Returns the ID of the items to drop on destruction.
    153         */
    154        public int idDropped(int par1, Random par2Random, int par3)
    155        {
    156            return Block.dirt.idDropped(0, par2Random, par3);
    157        }
    158
    159        @SideOnly(Side.CLIENT)
    160
    161        /**
    162         * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
    163         */
    164        public int idPicked(World par1World, int par2, int par3, int par4)
    165        {
    166            return Block.dirt.blockID;
    167        }
    168    }