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