001package net.minecraft.enchantment;
002
003import java.util.Random;
004import net.minecraft.entity.Entity;
005import net.minecraft.entity.EntityLiving;
006import net.minecraft.item.ItemArmor;
007import net.minecraft.item.ItemStack;
008import net.minecraft.util.DamageSource;
009
010public class EnchantmentThorns extends Enchantment
011{
012    public EnchantmentThorns(int par1, int par2)
013    {
014        super(par1, par2, EnumEnchantmentType.armor_torso);
015        this.setName("thorns");
016    }
017
018    /**
019     * Returns the minimal value of enchantability needed on the enchantment level passed.
020     */
021    public int getMinEnchantability(int par1)
022    {
023        return 10 + 20 * (par1 - 1);
024    }
025
026    /**
027     * Returns the maximum value of enchantability nedded on the enchantment level passed.
028     */
029    public int getMaxEnchantability(int par1)
030    {
031        return super.getMinEnchantability(par1) + 50;
032    }
033
034    /**
035     * Returns the maximum level that the enchantment can have.
036     */
037    public int getMaxLevel()
038    {
039        return 3;
040    }
041
042    public boolean func_92089_a(ItemStack par1ItemStack)
043    {
044        return par1ItemStack.getItem() instanceof ItemArmor ? true : super.func_92089_a(par1ItemStack);
045    }
046
047    public static boolean func_92094_a(int par0, Random par1Random)
048    {
049        return par0 <= 0 ? false : par1Random.nextFloat() < 0.15F * (float)par0;
050    }
051
052    public static int func_92095_b(int par0, Random par1Random)
053    {
054        return par0 > 10 ? par0 - 10 : 1 + par1Random.nextInt(4);
055    }
056
057    public static void func_92096_a(Entity par0Entity, EntityLiving par1EntityLiving, Random par2Random)
058    {
059        int i = EnchantmentHelper.func_92098_i(par1EntityLiving);
060        ItemStack itemstack = EnchantmentHelper.func_92099_a(Enchantment.field_92091_k, par1EntityLiving);
061
062        if (func_92094_a(i, par2Random))
063        {
064            par0Entity.attackEntityFrom(DamageSource.func_92087_a(par1EntityLiving), func_92095_b(i, par2Random));
065            par0Entity.playSound("damage.thorns", 0.5F, 1.0F);
066
067            if (itemstack != null)
068            {
069                itemstack.damageItem(3, par1EntityLiving);
070            }
071        }
072        else if (itemstack != null)
073        {
074            itemstack.damageItem(1, par1EntityLiving);
075        }
076    }
077}