    001    package net.minecraft.enchantment;
    002
    003    import java.util.Random;
    004    import net.minecraft.entity.Entity;
    005    import net.minecraft.entity.EntityLiving;
    006    import net.minecraft.item.ItemArmor;
    007    import net.minecraft.item.ItemStack;
    008    import net.minecraft.util.DamageSource;
    009
    010    public 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_92037_a(ItemStack par1ItemStack)
    043        {
    044            return par1ItemStack.getItem() instanceof ItemArmor ? true : super.func_92037_a(par1ItemStack);
    045        }
    046
    047        public static boolean func_92042_a(int par0, Random par1Random)
    048        {
    049            return par0 <= 0 ? false : par1Random.nextFloat() < 0.15F * (float)par0;
    050        }
    051
    052        public static int func_92043_b(int par0, Random par1)
    053        {
    054            return par0 > 10 ? par0 - 10 : 1 + par1.nextInt(4);
    055        }
    056
    057        public static void func_92044_a(Entity par0Entity, EntityLiving par1, Random par2Random)
    058        {
    059            int var3 = EnchantmentHelper.func_92046_i(par1);
    060            ItemStack var4 = EnchantmentHelper.func_92047_a(Enchantment.field_92039_k, par1);
    061
    062            if (func_92042_a(var3, par2Random))
    063            {
    064                par0Entity.attackEntityFrom(DamageSource.func_92036_a(par1), func_92043_b(var3, par2Random));
    065                par0Entity.func_85030_a("damage.thorns", 0.5F, 1.0F);
    066
    067                if (var4 != null)
    068                {
    069                    var4.damageItem(3, par1);
    070                }
    071            }
    072            else if (var4 != null)
    073            {
    074                var4.damageItem(1, par1);
    075            }
    076        }
    077    }