package com.hbm.items.machine;

import java.util.List;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.ModItems;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.minecraft.util.StatCollector;

public class ItemFluidTank extends Item {

	protected IIcon overlayIcon;

	public ItemFluidTank() {
		this.setHasSubtypes(true);
		this.setMaxDamage(0);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void getSubItems(Item item, CreativeTabs tabs, List list) {
		
		FluidType[] order = Fluids.getInNiceOrder();
		for(int i = 1; i < order.length; ++i) {
			FluidType type = order[i];
			
			if(type.hasNoContainer()) continue;
			int id = type.getID();
			
			if(type.needsLeadContainer()) {
				if(this == ModItems.fluid_tank_lead_full) {
					list.add(new ItemStack(item, 1, id));
				}
				
			} else {
				list.add(new ItemStack(item, 1, id));
			}
		}
	}

	@Override
	public String getItemStackDisplayName(ItemStack stack) {
		String s1 = ("" + StatCollector.translateToLocal(Fluids.fromID(stack.getItemDamage()).getConditionalName())).trim();
		String s = ("" + StatCollector.translateToLocalFormatted(this.getUnlocalizedName() + ".name", s1)).trim();
		return s;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public boolean requiresMultipleRenderPasses() {
		return true;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void registerIcons(IIconRegister p_94581_1_) {
		super.registerIcons(p_94581_1_);

		if(this == ModItems.fluid_tank_full) this.overlayIcon = p_94581_1_.registerIcon("hbm:fluid_tank_overlay");
		if(this == ModItems.fluid_tank_lead_full) this.overlayIcon = p_94581_1_.registerIcon("hbm:fluid_tank_lead_overlay");
		if(this == ModItems.fluid_barrel_full) this.overlayIcon = p_94581_1_.registerIcon("hbm:fluid_barrel_overlay");
		if(this == ModItems.fluid_pack_full) this.overlayIcon = p_94581_1_.registerIcon("hbm:fluid_pack_overlay");
	}

	@Override
	@SideOnly(Side.CLIENT)
	public IIcon getIconFromDamageForRenderPass(int p_77618_1_, int p_77618_2_) {
		return p_77618_2_ == 1 ? this.overlayIcon : super.getIconFromDamageForRenderPass(p_77618_1_, p_77618_2_);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public int getColorFromItemStack(ItemStack stack, int pass) {
		if(pass == 0) {
			return 16777215;
		} else {
			int j = Fluids.fromID(stack.getItemDamage()).getColor();
			if(j < 0) j = 16777215;
			return j;
		}
	}
}
