package net.tropicraft.block; import java.util.List; import net.minecraft.block.BlockBush; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.tropicraft.info.TCInfo; import net.tropicraft.info.TCNames; import net.tropicraft.registry.TCCreativeTabRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockTropicraftFlower extends BlockBush { /** Names of each of the images */ private String[] names; /** Array of icons associated with this item */ @SideOnly(Side.CLIENT) private IIcon[] icons; public BlockTropicraftFlower(String[] names) { super(Material.plants); this.names = names; this.setBlockTextureName(TCNames.flower); this.setCreativeTab(TCCreativeTabRegistry.tabDecorations); this.setStepSound(soundTypeGrass); } /** * Gets an icon index based on an item's damage value */ @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int id, int metadata) { if (metadata < 0 || metadata > names.length - 1) metadata = names.length - 1; return icons[metadata]; } /** * Determines the damage on the item the block drops. Used in cloth and wood. */ @Override public int damageDropped(int meta) { return meta; } /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override @SideOnly(Side.CLIENT) public void getSubBlocks(Item item, CreativeTabs tab, List list) { for (int i = 0; i < names.length; i++) list.add(new ItemStack(item, 1, i)); } /** * @return The unlocalized block name */ @Override public String getUnlocalizedName() { return String.format("tile.%s%s", TCInfo.ICON_LOCATION, getActualName(super.getUnlocalizedName())); } /** * Get the true name of the block * @param unlocalizedName tile.%truename% * @return The actual name of the block, rather than tile.%truename% */ protected String getActualName(String unlocalizedName) { return unlocalizedName.substring(unlocalizedName.indexOf('.') + 1); } /** * Register all icons here * @param iconRegister Icon registry */ @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { icons = new IIcon[names.length]; for (int i = 0 ; i < names.length ; i++) { icons[i] = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1) + "_" + i); } } }