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.client.renderer.texture.IconRegister; 008import net.minecraft.creativetab.CreativeTabs; 009import net.minecraft.util.Icon; 010import net.minecraft.world.ColorizerGrass; 011import net.minecraft.world.IBlockAccess; 012import net.minecraft.world.World; 013 014public class BlockGrass extends Block 015{ 016 @SideOnly(Side.CLIENT) 017 private Icon field_94437_a; 018 @SideOnly(Side.CLIENT) 019 private Icon field_94435_b; 020 @SideOnly(Side.CLIENT) 021 private Icon field_94436_c; 022 023 protected BlockGrass(int par1) 024 { 025 super(par1, Material.grass); 026 this.setTickRandomly(true); 027 this.setCreativeTab(CreativeTabs.tabBlock); 028 } 029 030 @SideOnly(Side.CLIENT) 031 032 /** 033 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 034 */ 035 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 036 { 037 return par1 == 1 ? this.field_94437_a : (par1 == 0 ? Block.dirt.getBlockTextureFromSide(par1) : this.field_94336_cN); 038 } 039 040 /** 041 * Ticks the block if it's been scheduled 042 */ 043 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 044 { 045 if (!par1World.isRemote) 046 { 047 if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1World.getBlockLightOpacity(par2, par3 + 1, par4) > 2) 048 { 049 par1World.func_94575_c(par2, par3, par4, Block.dirt.blockID); 050 } 051 else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9) 052 { 053 for (int l = 0; l < 4; ++l) 054 { 055 int i1 = par2 + par5Random.nextInt(3) - 1; 056 int j1 = par3 + par5Random.nextInt(5) - 3; 057 int k1 = par4 + par5Random.nextInt(3) - 1; 058 int l1 = par1World.getBlockId(i1, j1 + 1, k1); 059 060 if (par1World.getBlockId(i1, j1, k1) == Block.dirt.blockID && par1World.getBlockLightValue(i1, j1 + 1, k1) >= 4 && par1World.getBlockLightOpacity(i1, j1 + 1, k1) <= 2) 061 { 062 par1World.func_94575_c(i1, j1, k1, Block.grass.blockID); 063 } 064 } 065 } 066 } 067 } 068 069 /** 070 * Returns the ID of the items to drop on destruction. 071 */ 072 public int idDropped(int par1, Random par2Random, int par3) 073 { 074 return Block.dirt.idDropped(0, par2Random, par3); 075 } 076 077 @SideOnly(Side.CLIENT) 078 079 /** 080 * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side 081 */ 082 public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 083 { 084 if (par5 == 1) 085 { 086 return this.field_94437_a; 087 } 088 else if (par5 == 0) 089 { 090 return Block.dirt.getBlockTextureFromSide(par5); 091 } 092 else 093 { 094 Material material = par1IBlockAccess.getBlockMaterial(par2, par3 + 1, par4); 095 return material != Material.snow && material != Material.craftedSnow ? this.field_94336_cN : this.field_94435_b; 096 } 097 } 098 099 @SideOnly(Side.CLIENT) 100 public void func_94332_a(IconRegister par1IconRegister) 101 { 102 this.field_94336_cN = par1IconRegister.func_94245_a("grass_side"); 103 this.field_94437_a = par1IconRegister.func_94245_a("grass_top"); 104 this.field_94435_b = par1IconRegister.func_94245_a("snow_side"); 105 this.field_94436_c = par1IconRegister.func_94245_a("grass_side_overlay"); 106 } 107 108 @SideOnly(Side.CLIENT) 109 public int getBlockColor() 110 { 111 double d0 = 0.5D; 112 double d1 = 1.0D; 113 return ColorizerGrass.getGrassColor(d0, d1); 114 } 115 116 @SideOnly(Side.CLIENT) 117 118 /** 119 * Returns the color this block should be rendered. Used by leaves. 120 */ 121 public int getRenderColor(int par1) 122 { 123 return this.getBlockColor(); 124 } 125 126 @SideOnly(Side.CLIENT) 127 128 /** 129 * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called 130 * when first determining what to render. 131 */ 132 public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 133 { 134 int l = 0; 135 int i1 = 0; 136 int j1 = 0; 137 138 for (int k1 = -1; k1 <= 1; ++k1) 139 { 140 for (int l1 = -1; l1 <= 1; ++l1) 141 { 142 int i2 = par1IBlockAccess.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeGrassColor(); 143 l += (i2 & 16711680) >> 16; 144 i1 += (i2 & 65280) >> 8; 145 j1 += i2 & 255; 146 } 147 } 148 149 return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255; 150 } 151 152 @SideOnly(Side.CLIENT) 153 public static Icon func_94434_o() 154 { 155 return Block.grass.field_94436_c; 156 } 157}