package emris.test18.Items.ItemBlocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import emris.test18.API.Enums.EnumItemReach;
import emris.test18.API.Enums.EnumSize;
import emris.test18.API.Enums.EnumWeight;
import emris.test18.API.Interfaces.IEquipable;
import emris.test18.API.Interfaces.ISize;

public class ItemTerraBlock extends ItemBlock implements ISize
{
	public String[] MetaNames;
	public String folder;

	public ItemTerraBlock(Block b)
	{
		super(b);
		this.setHasSubtypes(true);
		this.folder = "";
	}

	public ItemTerraBlock setFolder(String f)
	{
		folder = f;
		return this;
	}

	@Override
	public String getUnlocalizedName(ItemStack is)
	{
		if(MetaNames != null && is.getItemDamage() < MetaNames.length)
			return super.getUnlocalizedName() + "." + MetaNames[is.getItemDamage()];
		return super.getUnlocalizedName();
	}

	/**
	 * This is called by inventories in the world to tick things such as temperature and food decay. Override this and 
	 * return true if you want the item to be handled differently than the standard code. True will stop he standard TFC code from running.
	 */
	public boolean onUpdate(ItemStack is, World world, int x, int y, int z)
	{
		return false;
	}

	@Override
	public int getMetadata(int i)
	{
		return i;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public void addInformation(ItemStack is, EntityPlayer player, List arraylist, boolean flag)
	{
		addSizeInformation(is, arraylist);
	}

	private void addSizeInformation(ItemStack object, List<String> arraylist)
	{
		if(((ISize)object.getItem()).getSize(object)!= null
				&& ((ISize)object.getItem()).getWeight(object) != null
				&& ((ISize)object.getItem()).getReach(object)!= null)
		{
			arraylist.add("\u2696" + StatCollector.translateToLocal("gui.Weight." + ((ISize)object.getItem()).getWeight(object).getName()) + " \u21F2" + 
					StatCollector.translateToLocal("gui.Size." + ((ISize)object.getItem()).getSize(object).getName().replace(" ", "")));
		}

		if(object.getItem() instanceof IEquipable)
		{
			if(((IEquipable)object.getItem()).getEquipType(object) == IEquipable.EquipType.BACK)
			{
				arraylist.add(EnumChatFormatting.LIGHT_PURPLE.toString()+StatCollector.translateToLocal("gui.slot")+ 
						EnumChatFormatting.GRAY.toString()+": " + 
						EnumChatFormatting.WHITE.toString() + StatCollector.translateToLocal("gui.slot.back"));
			}
		}
	}

	@Override
	public boolean getShareTag()
	{
		return true;
	}

	@Override
	public int getItemStackLimit(ItemStack is)
	{
		if(canStack())
			return this.getSize(null).stackSize * getWeight(null).multiplier;
		else
			return 1;
	}

	@Override
	public EnumSize getSize(ItemStack is)
	{
		return EnumSize.VERYSMALL;
	}

	@Override
	public boolean canStack()
	{
		return true;
	}

	@Override
	public EnumWeight getWeight(ItemStack is)
	{
		return EnumWeight.HEAVY;
	}

	@Override
	public EnumItemReach getReach(ItemStack is)
	{
		return EnumItemReach.SHORT;
	}
}