package net.minecraft.item;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;

public class ItemTool extends Item
{
	private Set field_150914_c;
	protected float efficiencyOnProperMaterial = 4.0F;
	private float damageVsEntity;
	protected Item.ToolMaterial toolMaterial;
	private static final String __OBFID = "CL_00000019";

	protected ItemTool(float p_i45333_1_, Item.ToolMaterial p_i45333_2_, Set p_i45333_3_)
	{
		this.toolMaterial = p_i45333_2_;
		this.field_150914_c = p_i45333_3_;
		this.maxStackSize = 1;
		this.setMaxDamage(p_i45333_2_.getMaxUses());
		this.efficiencyOnProperMaterial = p_i45333_2_.getEfficiencyOnProperMaterial();
		this.damageVsEntity = p_i45333_1_ + p_i45333_2_.getDamageVsEntity();
		this.setCreativeTab(CreativeTabs.tabTools);
		if (this instanceof ItemPickaxe)
		{
			toolClass = "pickaxe";
		}
		else if (this instanceof ItemAxe)
		{
			toolClass = "axe";
		}
		else if (this instanceof ItemSpade)
		{
			toolClass = "shovel";
		}
	}

	public float func_150893_a(ItemStack p_150893_1_, Block p_150893_2_)
	{
		return this.field_150914_c.contains(p_150893_2_) ? this.efficiencyOnProperMaterial : 1.0F;
	}

	public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase)
	{
		par1ItemStack.damageItem(2, par3EntityLivingBase);
		return true;
	}

	public boolean onBlockDestroyed(ItemStack p_150894_1_, World p_150894_2_, Block p_150894_3_, int p_150894_4_, int p_150894_5_, int p_150894_6_, EntityLivingBase p_150894_7_)
	{
		if ((double)p_150894_3_.getBlockHardness(p_150894_2_, p_150894_4_, p_150894_5_, p_150894_6_) != 0.0D)
		{
			p_150894_1_.damageItem(1, p_150894_7_);
		}

		return true;
	}

	@SideOnly(Side.CLIENT)
	public boolean isFull3D()
	{
		return true;
	}

	public Item.ToolMaterial func_150913_i()
	{
		return this.toolMaterial;
	}

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

	public String getToolMaterialName()
	{
		return this.toolMaterial.toString();
	}

	public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
	{
		return this.toolMaterial.func_150995_f() == par2ItemStack.getItem() ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
	}

	public Multimap getItemAttributeModifiers()
	{
		Multimap multimap = super.getItemAttributeModifiers();
		multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.damageVsEntity, 0));
		return multimap;
	}

	/*===================================== FORGE START =================================*/
	private String toolClass;
	@Override
	public int getHarvestLevel(ItemStack stack, String toolClass)
	{
		int level = super.getHarvestLevel(stack, toolClass);
		if (level == -1 && toolClass != null && toolClass.equals(this.toolClass))
		{
			return this.toolMaterial.getHarvestLevel();
		}
		else
		{
			return level;
		}
	}

	@Override
	public Set<String> getToolClasses(ItemStack stack)
	{
		return toolClass != null ? ImmutableSet.of(toolClass) : super.getToolClasses(stack);
	}

	@Override
	public float getDigSpeed(ItemStack stack, Block block, int meta)
	{
		if (ForgeHooks.isToolEffective(stack, block, meta))
		{
			return efficiencyOnProperMaterial;
		}
		return super.getDigSpeed(stack, block, meta);
	}
	/*===================================== FORGE END =================================*/
}