001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005 006import java.util.ArrayList; 007import java.util.List; 008import java.util.Random; 009import net.minecraft.block.material.Material; 010import net.minecraft.client.renderer.texture.IconRegister; 011import net.minecraft.creativetab.CreativeTabs; 012import net.minecraft.entity.player.EntityPlayer; 013import net.minecraft.item.Item; 014import net.minecraft.item.ItemStack; 015import net.minecraft.stats.StatList; 016import net.minecraft.util.Icon; 017import net.minecraft.world.ColorizerFoliage; 018import net.minecraft.world.ColorizerGrass; 019import net.minecraft.world.IBlockAccess; 020import net.minecraft.world.World; 021 022import net.minecraftforge.common.ForgeHooks; 023import net.minecraftforge.common.IShearable; 024 025public class BlockTallGrass extends BlockFlower implements IShearable 026{ 027 private static final String[] grassTypes = new String[] {"deadbush", "tallgrass", "fern"}; 028 @SideOnly(Side.CLIENT) 029 private Icon[] iconArray; 030 031 protected BlockTallGrass(int par1) 032 { 033 super(par1, Material.vine); 034 float f = 0.4F; 035 this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f); 036 } 037 038 @SideOnly(Side.CLIENT) 039 040 /** 041 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 042 */ 043 public Icon getBlockTextureFromSideAndMetadata(int par1, int par2) 044 { 045 if (par2 >= this.iconArray.length) 046 { 047 par2 = 0; 048 } 049 050 return this.iconArray[par2]; 051 } 052 053 /** 054 * Returns the ID of the items to drop on destruction. 055 */ 056 public int idDropped(int par1, Random par2Random, int par3) 057 { 058 return -1; 059 } 060 061 /** 062 * Returns the usual quantity dropped by the block plus a bonus of 1 to 'i' (inclusive). 063 */ 064 public int quantityDroppedWithBonus(int par1, Random par2Random) 065 { 066 return 1 + par2Random.nextInt(par1 * 2 + 1); 067 } 068 069 /** 070 * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the 071 * block and l is the block's subtype/damage. 072 */ 073 public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) 074 { 075 super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); 076 } 077 078 @SideOnly(Side.CLIENT) 079 public int getBlockColor() 080 { 081 double d0 = 0.5D; 082 double d1 = 1.0D; 083 return ColorizerGrass.getGrassColor(d0, d1); 084 } 085 086 @SideOnly(Side.CLIENT) 087 088 /** 089 * Returns the color this block should be rendered. Used by leaves. 090 */ 091 public int getRenderColor(int par1) 092 { 093 return par1 == 0 ? 16777215 : ColorizerFoliage.getFoliageColorBasic(); 094 } 095 096 @SideOnly(Side.CLIENT) 097 098 /** 099 * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called 100 * when first determining what to render. 101 */ 102 public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 103 { 104 int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4); 105 return l == 0 ? 16777215 : par1IBlockAccess.getBiomeGenForCoords(par2, par4).getBiomeGrassColor(); 106 } 107 108 /** 109 * Get the block's damage value (for use with pick block). 110 */ 111 public int getDamageValue(World par1World, int par2, int par3, int par4) 112 { 113 return par1World.getBlockMetadata(par2, par3, par4); 114 } 115 116 @SideOnly(Side.CLIENT) 117 118 /** 119 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) 120 */ 121 public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) 122 { 123 for (int j = 1; j < 3; ++j) 124 { 125 par3List.add(new ItemStack(par1, 1, j)); 126 } 127 } 128 129 @SideOnly(Side.CLIENT) 130 131 /** 132 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 133 * is the only chance you get to register icons. 134 */ 135 public void registerIcons(IconRegister par1IconRegister) 136 { 137 this.iconArray = new Icon[grassTypes.length]; 138 139 for (int i = 0; i < this.iconArray.length; ++i) 140 { 141 this.iconArray[i] = par1IconRegister.registerIcon(grassTypes[i]); 142 } 143 } 144 145 @Override 146 public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int meta, int fortune) 147 { 148 ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); 149 if (world.rand.nextInt(8) != 0) 150 { 151 return ret; 152 } 153 154 ItemStack item = ForgeHooks.getGrassSeed(world); 155 if (item != null) 156 { 157 ret.add(item); 158 } 159 return ret; 160 } 161 162 @Override 163 public boolean isShearable(ItemStack item, World world, int x, int y, int z) 164 { 165 return true; 166 } 167 168 @Override 169 public ArrayList<ItemStack> onSheared(ItemStack item, World world, int x, int y, int z, int fortune) 170 { 171 ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); 172 ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z))); 173 return ret; 174 } 175}