    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 BlockGrass extends Block
    008    {
    009        protected BlockGrass(int par1)
    010        {
    011            super(par1, Material.grass);
    012            this.blockIndexInTexture = 3;
    013            this.setTickRandomly(true);
    014            this.setCreativeTab(CreativeTabs.tabBlock);
    015        }
    016
    017        /**
    018         * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    019         */
    020        public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    021        {
    022            return par1 == 1 ? 0 : (par1 == 0 ? 2 : 3);
    023        }
    024
    025        @SideOnly(Side.CLIENT)
    026
    027        /**
    028         * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
    029         */
    030        public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    031        {
    032            if (par5 == 1)
    033            {
    034                return 0;
    035            }
    036            else if (par5 == 0)
    037            {
    038                return 2;
    039            }
    040            else
    041            {
    042                Material var6 = par1IBlockAccess.getBlockMaterial(par2, par3 + 1, par4);
    043                return var6 != Material.snow && var6 != Material.craftedSnow ? 3 : 68;
    044            }
    045        }
    046
    047        @SideOnly(Side.CLIENT)
    048        public int getBlockColor()
    049        {
    050            double var1 = 0.5D;
    051            double var3 = 1.0D;
    052            return ColorizerGrass.getGrassColor(var1, var3);
    053        }
    054
    055        @SideOnly(Side.CLIENT)
    056
    057        /**
    058         * Returns the color this block should be rendered. Used by leaves.
    059         */
    060        public int getRenderColor(int par1)
    061        {
    062            return this.getBlockColor();
    063        }
    064
    065        @SideOnly(Side.CLIENT)
    066
    067        /**
    068         * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
    069         * when first determining what to render.
    070         */
    071        public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    072        {
    073            int var5 = 0;
    074            int var6 = 0;
    075            int var7 = 0;
    076
    077            for (int var8 = -1; var8 <= 1; ++var8)
    078            {
    079                for (int var9 = -1; var9 <= 1; ++var9)
    080                {
    081                    int var10 = par1IBlockAccess.getBiomeGenForCoords(par2 + var9, par4 + var8).getBiomeGrassColor();
    082                    var5 += (var10 & 16711680) >> 16;
    083                    var6 += (var10 & 65280) >> 8;
    084                    var7 += var10 & 255;
    085                }
    086            }
    087
    088            return (var5 / 9 & 255) << 16 | (var6 / 9 & 255) << 8 | var7 / 9 & 255;
    089        }
    090
    091        /**
    092         * Ticks the block if it's been scheduled
    093         */
    094        public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    095        {
    096            if (!par1World.isRemote)
    097            {
    098                if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1World.getBlockLightOpacity(par2, par3 + 1, par4) > 2)
    099                {
    100                    par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID);
    101                }
    102                else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)
    103                {
    104                    for (int var6 = 0; var6 < 4; ++var6)
    105                    {
    106                        int var7 = par2 + par5Random.nextInt(3) - 1;
    107                        int var8 = par3 + par5Random.nextInt(5) - 3;
    108                        int var9 = par4 + par5Random.nextInt(3) - 1;
    109                        int var10 = par1World.getBlockId(var7, var8 + 1, var9);
    110
    111                        if (par1World.getBlockId(var7, var8, var9) == Block.dirt.blockID && par1World.getBlockLightValue(var7, var8 + 1, var9) >= 4 && par1World.getBlockLightOpacity(var7, var8 + 1, var9) <= 2)
    112                        {
    113                            par1World.setBlockWithNotify(var7, var8, var9, Block.grass.blockID);
    114                        }
    115                    }
    116                }
    117            }
    118        }
    119
    120        /**
    121         * Returns the ID of the items to drop on destruction.
    122         */
    123        public int idDropped(int par1, Random par2Random, int par3)
    124        {
    125            return Block.dirt.idDropped(0, par2Random, par3);
    126        }
    127    }