package frogcraftrebirth.common.item;

import java.util.Collection;
import java.util.List;

import frogcraftrebirth.api.FrogAPI;
import frogcraftrebirth.api.item.FluidArmorPotionEffectManager;
import ic2.api.item.IMetalArmor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;

/**
 * @author 3TUSK
 * Created at 7:46:59 PM Sep 6, 2015 EST 2015
 */
public class ItemFluidArmor extends ItemArmor implements IMetalArmor {

	public static final ArmorMaterial FLUID_ARMOR = EnumHelper.addArmorMaterial("fluidArmor", "armorMaterial.fluidArmor", 1000, new int[] {1,1,1,1}, 5, null, 1);
	
	public final int capacity;
	
	public ItemFluidArmor(int capacity) {
		super(FLUID_ARMOR, 0, EntityEquipmentSlot.CHEST);//0->cloth(leather) renderer; render stuff is WIP
		setMaxStackSize(1);
		setCreativeTab(FrogAPI.TAB);
		setRegistryName("fluid_armor");
		setUnlocalizedName("fluidArmor");
		this.capacity = capacity;
	}
	
	@Override
	public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
		return "frogcraftrebirth:textures/items/FluidArmor.png";
	}
	

	@Override
	public boolean isMetalArmor(ItemStack itemstack, EntityPlayer player) {
		return true;
	}
	
	@Override
	public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
		if (world.isRemote) return;
		
		FluidStack currentFluid = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).getTankProperties()[0].getContents();
		if (currentFluid != null) {
			Collection<PotionEffect> effectList = FluidArmorPotionEffectManager.INSTANCE.getEffect(currentFluid.getFluid());
			for (PotionEffect effect : effectList) {
				player.addPotionEffect(effect);
			}
		}
	}
	
	@Override
	public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound tag) {
		return new FluidHandlerItemStack(stack, capacity);
	}
	
	@Override
	public void addInformation(ItemStack stack, EntityPlayer player, List<String> info, boolean adv) {
		FluidStack fluid = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).getTankProperties()[0].getContents();
		if (fluid != null) {
			info.add("Name:" + fluid.getLocalizedName());
			info.add("Amount: " + fluid.amount);
		} else {
			info.add("No fluid is in armor now");
		}
	}
	
	
	
}

@@ -255,16 +255,62 @@
 Entity;%0A
+import net.minecraft.entity.EntityLivingBase;%0A
 import n
@@ -584,19 +584,107 @@
 aft.
-world.World
+util.DamageSource;%0Aimport net.minecraft.world.World;%0Aimport net.minecraftforge.common.ISpecialArmor
 ;%0Aim
@@ -1128,16 +1128,31 @@
 talArmor
+, ISpecialArmor
  %7B%0A%0A%09pub
@@ -1268,18 +1268,16 @@
 mor%22, 10
-00
 , new in
@@ -1285,15 +1285,15 @@
 %5B%5D %7B
-1,1,1,1
+0,0,0,0
 %7D, 5
@@ -1430,57 +1430,8 @@
 ST);
-//0-%3Ecloth(leather) renderer; render stuff is WIP
 %0A%09%09s
@@ -1759,18 +1759,16 @@
 png%22;%0A%09%7D
-%0A%09
 %0A%0A%09@Over
@@ -2949,12 +2949,428 @@
 %0A%09%7D%0A
-%09%0A%09%0A%09
+%0A%09@Override%0A%09public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) %7B%0A%09%09return new ArmorProperties(0, 1.0, 100);%0A%09%7D%0A%0A%09@Override%0A%09public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) %7B%0A%09%09return 0;%0A%09%7D%0A%0A%09@Override%0A%09public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) %7B%0A%09%09%0A%09%7D%0A
 %0A%7D%0A

Add ISpecialArmor support