package org.pfaa.chemica.fluid;

import java.util.Collections;
import java.util.List;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;

import org.pfaa.chemica.Chemica;
import org.pfaa.chemica.fluid.IndustrialFluid;

import com.google.common.base.CaseFormat;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/* Alternative design:
 * Use a brewing API to define a custom potion for every fluid. Then, the FluidContainerRegistry
 * maps from fluid to potion (damage on the itemstack), and vice versa. 
 * Otherwise, this class may behave strangely in a brewing stand.
 */
public class FilledGlassBottleItem extends ItemPotion {
	
    public FilledGlassBottleItem() {
        this.setTextureName("potion");
    }
    
	private Fluid getFluidForItemStack(ItemStack itemStack) {
		FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStack);
		return fluidStack.getFluid();
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public int getColorFromItemStack(ItemStack itemStack, int renderPass) {
		if (renderPass > 0) {
			return super.getColorFromItemStack(itemStack, renderPass);
		} else {
			return this.getFluidForItemStack(itemStack).getBlock().colorMultiplier(null, 0, 0, 0); 
		}
	}

	@Override
    @SideOnly(Side.CLIENT)
    public boolean hasEffect(ItemStack p_77636_1_)
    {
        return false;
    }

    @Override
	public List<PotionEffect> getEffects(ItemStack itemStack) {
		Fluid fluid = this.getFluidForItemStack(itemStack);
		if (fluid instanceof IndustrialFluid) {
			return ((IndustrialFluid)fluid).getProperties().hazard.getIngestionEffects();
		}
		return Collections.EMPTY_LIST;
	}

	@Override
	public List<PotionEffect> getEffects(int damage) {
		return this.getEffects(new ItemStack(this, 1, damage));
	}

	@Override
	public String getUnlocalizedName(ItemStack itemStack) {
	    String fluidPostfix = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, 
	            this.getFluidForItemStack(itemStack).getName());
		return this.getUnlocalizedName() + "." + fluidPostfix;
	}

    @Override
    public String getItemStackDisplayName(ItemStack p_77653_1_)
    {
        return StatCollector.translateToLocal(this.getUnlocalizedName(p_77653_1_) + ".name").trim();
    }
}

@@ -22,24 +22,53 @@
 ica.fluid;%0A%0A
+import java.util.Collection;%0A
 import java.
@@ -143,85 +143,181 @@
 t.re
-nderer.texture.IIconRegister;%0Aimport net.minecraft.entity.player.EntityPlayer
+sources.I18n;%0Aimport net.minecraft.creativetab.CreativeTabs;%0Aimport net.minecraft.entity.player.EntityPlayer;%0Aimport net.minecraft.init.Items;%0Aimport net.minecraft.item.Item
 ;%0Aim
@@ -431,16 +431,62 @@
 Effect;%0A
+import net.minecraft.util.EnumChatFormatting;%0A
 import n
@@ -522,42 +522,8 @@
 or;%0A
-import net.minecraft.world.World;%0A
 impo
@@ -657,94 +657,61 @@
 luid
-Stack;%0A%0Aimport org.pfaa.chemica.Chemica;%0Aimport org.pfaa.chemica.fluid.IndustrialFluid
+Registry;%0Aimport net.minecraftforge.fluids.FluidStack
 ;%0A%0Ai
@@ -1228,16 +1228,50 @@
 tion%22);%0A
+        this.setMaxStackSize(64);%0A
     %7D%0A  
@@ -2762,11 +2762,1113 @@
 );%0A    %7D
+%0A%0A    @Override%0A    @SideOnly(Side.CLIENT)%0A    public void getSubItems(Item item, CreativeTabs tabs, List itemStacks)%0A    %7B%0A        Collection%3CFluid%3E fluids = FluidRegistry.getRegisteredFluids().values();%0A        for (Fluid fluid : fluids) %7B%0A            FluidStack fluidStack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);%0A            ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(fluidStack, FluidContainerRegistry.EMPTY_BOTTLE);%0A            if (filledContainer != null) %7B%0A                itemStacks.add(filledContainer);%0A            %7D%0A        %7D%0A    %7D%0A%0A    @Override%0A    @SideOnly(Side.CLIENT)%0A    public void addInformation(ItemStack itemStack, EntityPlayer player, List lines, boolean p_77624_4_)%0A    %7B%0A        Fluid fluid = this.getFluidForItemStack(itemStack);%0A        if (fluid instanceof IndustrialFluid) %7B%0A            IndustrialFluid industrialFluid = (IndustrialFluid)fluid;%0A            lines.add(EnumChatFormatting.BLUE + I18n.format(%22label.hazard.health%22) + %22: %22 + %0A                      industrialFluid.getProperties().hazard.health);%0A        %7D%0A    %7D
 %0A%7D%0A

Add sub-item and tooltip support to FilledGlassBottle