package common.item.tool;

import common.block.Block;
import common.entity.types.EntityLiving;
import common.init.ToolMaterial;
import common.item.CheatTab;
import common.item.Item;
import common.item.ItemStack;
import common.model.Transforms;
import common.util.BlockPos;
import common.world.World;

public abstract class ItemTool extends Item {
	private final float efficiency;
	private final int damage;
	private final ToolMaterial material;

	public ItemTool(int damage, ToolMaterial material) {
		this.material = material;
		this.setMaxDamage(material.getDurability());
		this.efficiency = material.getEfficiency();
		this.damage = damage + material.getDamage();
		this.setTab(CheatTab.TOOLS);
	}

	public abstract boolean canUseOn(ItemStack stack, Block block);

	public float getStrVsBlock(ItemStack stack, Block block) {
		return !this.canUseOn(stack, block) ? 1.0F : this.efficiency;
	}

	public boolean hitEntity(ItemStack stack, EntityLiving target, EntityLiving attacker) {
		stack.damageItem(2, attacker);
		return true;
	}

	public boolean onBlockDestroyed(ItemStack stack, World world, Block block, BlockPos pos, EntityLiving player) {
		if(block.getBlockHardness(world, pos) != 0.0f)
			stack.damageItem(1, player);
		return true;
	}

	public ToolMaterial getToolMaterial() {
		return this.material;
	}

	public int getItemEnchantability() {
		return this.material.getEnchantability();
	}

	public boolean getIsRepairable(ItemStack stack, ItemStack repair) {
		return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(stack, repair);
	}
    
    public int getAttackDamageBonus() {
    	return this.damage;
    }

	public boolean isMagnetic() {
		return this.material.isMagnetic();
	}

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

	public boolean canBeWielded() {
		return true;
	}
}
