package common.item;

import java.util.List;

import common.color.TextColor;
import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityDie;
import common.init.SoundEvent;
import common.model.Model;
import common.model.ModelProvider;
import common.model.Transforms;
import common.util.ExtMath;
import common.world.World;

public class ItemDie extends Item
{
	public static final int[] DIE_SIDES = new int[] {4, 6, 8, 10, 12, 20};
	public static final TextColor[] DIE_COLORS = new TextColor[] {TextColor.DGREEN, TextColor.NEON, TextColor.DMAGENTA, 
			TextColor.MAGENTA, TextColor.DRED, TextColor.ORANGE};
	
    public ItemDie()
    {
        this.setTab(CheatTab.tabTools);
        this.setMaxDamage(0);
        this.setHasSubtypes(true);
    }
    
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
    {
//        if (!playerIn.creative)
//        {
        --itemStackIn.stackSize;
//        }

        worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F);

        if (!worldIn.client)
        {
            worldIn.spawnEntityInWorld(new EntityDie(worldIn, playerIn, DIE_SIDES[ExtMath.clampi(itemStackIn.getMetadata(), 
            		0, DIE_SIDES.length - 1)], false)); // playerIn.creative));
        }

//        playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
        return itemStackIn;
    }
    
    public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
    {
    	for(int z = 0; z < DIE_SIDES.length; z++) {
    		subItems.add(new ItemStack(itemIn, 1, z));
    	}
    }
    
    public String getDisplay(ItemStack stack)
    {
        return super.getDisplay(stack) + " W" + DIE_SIDES[ExtMath.clampi(stack.getMetadata(), 0, DIE_SIDES.length - 1)];
    }

    public Transforms getTransform() {
    	return Transforms.DICE;
    }

    public Model getModel(ModelProvider provider, String name, int meta) {
    	return provider.getModel(provider.getModel("items/die_d" + DIE_SIDES[meta] + "_side").add().nswe()
    			.du("items/die_d" + DIE_SIDES[meta] + "_top"), this.getTransform());
    }
}
