package common.item.tool;

import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityDynamite;
import common.init.SoundEvent;
import common.item.CheatTab;
import common.item.Item;
import common.item.ItemStack;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.ExtMath;
import common.util.Facing;
import common.util.Vec3;
import common.world.World;

public class ItemDynamite extends Item {
	public static final ItemDynamite[] DYNAMITE = new ItemDynamite[8];

	private final int power;

	public static ItemDynamite getByPower(int power) {
		return DYNAMITE[ExtMath.clampi(power, 0, DYNAMITE.length - 1)];
	}

	public ItemDynamite(int power) {
		this.power = power;
		this.setMaxAmount(32);
		this.setTab(CheatTab.TOOLS);
		DYNAMITE[power] = this;
	}

	public int getExplosionPower() {
		return this.power;
	}

	public ItemStack onItemRightClick(ItemStack stack, World world, EntityNPC player) {
		--stack.size;
		world.playSoundAtEntity(player, SoundEvent.THROW, 0.5F);
		if(!world.client)
			world.spawnEntityInWorld(new EntityDynamite(world, player, this.power));
		return stack;
	}
    
	public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
		return this.dispenseProjectile(world, facing, stack, new EntityDynamite(world, position.xCoord, position.yCoord, position.zCoord, this.power));
	}

	public int getDispenseSoundId() {
		return 1002;
	}
}
