    001package net.minecraft.enchantment;
    002
    003import net.minecraft.entity.EntityLiving;
    004import net.minecraft.entity.EnumCreatureAttribute;
    005import net.minecraft.item.ItemAxe;
    006import net.minecraft.item.ItemStack;
    007import net.minecraft.util.MathHelper;
    008
    009public class EnchantmentDamage extends Enchantment
    010{
    011    /** Holds the name to be translated of each protection type. */
    012    private static final String[] protectionName = new String[] {"all", "undead", "arthropods"};
    013
    014    /**
    015     * Holds the base factor of enchantability needed to be able to use the enchant.
    016     */
    017    private static final int[] baseEnchantability = new int[] {1, 5, 5};
    018
    019    /**
    020     * Holds how much each level increased the enchantability factor to be able to use this enchant.
    021     */
    022    private static final int[] levelEnchantability = new int[] {11, 8, 8};
    023
    024    /**
    025     * Used on the formula of base enchantability, this is the 'window' factor of values to be able to use thing
    026     * enchant.
    027     */
    028    private static final int[] thresholdEnchantability = new int[] {20, 20, 20};
    029
    030    /**
    031     * Defines the type of damage of the enchantment, 0 = all, 1 = undead, 3 = arthropods
    032     */
    033    public final int damageType;
    034
    035    public EnchantmentDamage(int par1, int par2, int par3)
    036    {
    037        super(par1, par2, EnumEnchantmentType.weapon);
    038        this.damageType = par3;
    039    }
    040
    041    /**
    042     * Returns the minimal value of enchantability needed on the enchantment level passed.
    043     */
    044    public int getMinEnchantability(int par1)
    045    {
    046        return baseEnchantability[this.damageType] + (par1 - 1) * levelEnchantability[this.damageType];
    047    }
    048
    049    /**
    050     * Returns the maximum value of enchantability nedded on the enchantment level passed.
    051     */
    052    public int getMaxEnchantability(int par1)
    053    {
    054        return this.getMinEnchantability(par1) + thresholdEnchantability[this.damageType];
    055    }
    056
    057    /**
    058     * Returns the maximum level that the enchantment can have.
    059     */
    060    public int getMaxLevel()
    061    {
    062        return 5;
    063    }
    064
    065    /**
    066     * Calculates de (magic) damage done by the enchantment on a living entity based on level and entity passed.
    067     */
    068    public int calcModifierLiving(int par1, EntityLiving par2EntityLiving)
    069    {
    070        return this.damageType == 0 ? MathHelper.floor_float((float)par1 * 2.75F) : (this.damageType == 1 && par2EntityLiving.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD ? MathHelper.floor_float((float)par1 * 4.5F) : (this.damageType == 2 && par2EntityLiving.getCreatureAttribute() == EnumCreatureAttribute.ARTHROPOD ? MathHelper.floor_float((float)par1 * 4.5F) : 0));
    071    }
    072
    073    /**
    074     * Return the name of key in translation table of this enchantment.
    075     */
    076    public String getName()
    077    {
    078        return "enchantment.damage." + protectionName[this.damageType];
    079    }
    080
    081    /**
    082     * Determines if the enchantment passed can be applyied together with this enchantment.
    083     */
    084    public boolean canApplyTogether(Enchantment par1Enchantment)
    085    {
    086        return !(par1Enchantment instanceof EnchantmentDamage);
    087    }
    088
    089    public boolean func_92089_a(ItemStack par1ItemStack)
    090    {
    091        return par1ItemStack.getItem() instanceof ItemAxe ? true : super.func_92089_a(par1ItemStack);
    092    }
    093}