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