package com.zivilon.cinder_loe.items;

import com.zivilon.cinder_loe.LoECreativeTabs;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;

import java.util.List;

public class WarDartHeads extends Item {
    public IIcon[] icons;

    public WarDartHeads() {
        super();
        this.setCreativeTab(LoECreativeTabs.tabMiscLoE);
        setHasSubtypes(true);
    }

    @Override
    public void registerIcons(IIconRegister iconRegister) {
        icons = new IIcon[12];
        for (int i = 0; i < 6; i++) {
            icons[i] = iconRegister.registerIcon("lotr:war_dart_heads_" + i);
        }
        for (int i = 0; i < 6; i++) {
            icons[i + 6] = iconRegister.registerIcon("lotr:war_dart_heads_" + i + "_morgul");
        }
    }

    @Override
    public String getUnlocalizedName(ItemStack item) {
        return "item.war_dart_heads_" + WarDart.getDartMaterial(item);
    }

    @Override
    public int getColorFromItemStack(ItemStack stack, int renderPass) {
        int damage = stack.getItemDamage();

        switch (damage) {
            case 1: return 0xCA6C40; // Copper
            case 2: return 0xC28336; // Bronze
            case 3: return 0xD8D8D8; // Iron
            case 4: return 0x5D685A; // Orc
            case 5: return 0x6B787A; // Dwarven
            case 6: return 0x4C4D34;  // Uruk
            case 7: return 0x577287; // Blue Dwarven
            case 8: return 0x444138; // Black Uruk
            case 9: return 0xD0C9AC; // Elven
            case 10: return 0xFFFFB0; // Gilded Iron
            case 11: return 0xFFC48B; // Red dwarven
            case 12: return 0xAFB3D3; // Mithril
            case 13: return 0x335753; // Ancient
            case 14: return 16777215; // Morgul
            default: return 0xFFFFFF; // Blank
        }
    }

    @Override
    public IIcon getIconIndex(ItemStack item) {
        return getIcon(item, 0);
    }

    @Override
    public IIcon getIcon(ItemStack stack, int renderPass) {
        int count = stack.stackSize;
        int dmg = stack.getItemDamage();

        if (count > 5 || count < 1) {
            if (dmg == 14)
                return icons[6];
            return icons[0];
        } else {
            if (dmg == 14)
                return icons[count + 6];
            return icons[count];
        }
    }

    @Override
    public void getSubItems(Item item, CreativeTabs tab, List list) {
        for (int i = 1; i < 15; i++) {
            list.add(new ItemStack(item, 1, i));
        }
    }
}
