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