package common.item;

import java.util.List;

import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityDynamite;
import common.init.SoundEvent;
import common.model.Model;
import common.model.ModelProvider;
import common.world.World;

public class ItemDynamite extends Item
{
	private static final String[] TIERS = new String[] {"II", "III", "IV", "V", "VI", "VII", "VIII"};
	
    public ItemDynamite()
    {
        this.maxStackSize = 32;
        this.setTab(CheatTab.tabTools);
        this.setMaxDamage(0);
        this.setHasSubtypes(true);
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    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 EntityDynamite(worldIn, playerIn, itemStackIn.getMetadata()));
        }

//        playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
        return itemStackIn;
    }
    
    public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
    {
    	for(int z = 0; z < 8; z++) {
    		subItems.add(new ItemStack(itemIn, 1, z));
    	}
    }
    
    public String getDisplay(ItemStack stack)
    {
    	int exp = stack.getMetadata() & 7;
        return super.getDisplay(stack) + (exp == 0 ? "" : " " + TIERS[exp-1]);
    }

    public Model getModel(ModelProvider provider, String name, int meta) {
    	return provider.getModel(this.getTransform(), "dynamite" + (meta == 0 ? "" : ("_" + meta)));
    }
}
