001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    public abstract class Enchantment
007    {
008        public static final Enchantment[] enchantmentsList = new Enchantment[256];
009    
010        /** Converts environmental damage to armour damage */
011        public static final Enchantment protection = new EnchantmentProtection(0, 10, 0);
012    
013        /** Protection against fire */
014        public static final Enchantment fireProtection = new EnchantmentProtection(1, 5, 1);
015    
016        /** Less fall damage */
017        public static final Enchantment featherFalling = new EnchantmentProtection(2, 5, 2);
018    
019        /** Protection against explosions */
020        public static final Enchantment blastProtection = new EnchantmentProtection(3, 2, 3);
021    
022        /** Protection against projectile entities (e.g. arrows) */
023        public static final Enchantment projectileProtection = new EnchantmentProtection(4, 5, 4);
024    
025        /**
026         * Decreases the rate of air loss underwater; increases time between damage while suffocating
027         */
028        public static final Enchantment respiration = new EnchantmentOxygen(5, 2);
029    
030        /** Increases underwater mining rate */
031        public static final Enchantment aquaAffinity = new EnchantmentWaterWorker(6, 2);
032    
033        /** Extra damage to mobs */
034        public static final Enchantment sharpness = new EnchantmentDamage(16, 10, 0);
035    
036        /** Extra damage to zombies, zombie pigmen and skeletons */
037        public static final Enchantment smite = new EnchantmentDamage(17, 5, 1);
038    
039        /** Extra damage to spiders, cave spiders and silverfish */
040        public static final Enchantment baneOfArthropods = new EnchantmentDamage(18, 5, 2);
041    
042        /** Knocks mob and players backwards upon hit */
043        public static final Enchantment knockback = new EnchantmentKnockback(19, 5);
044    
045        /** Lights mobs on fire */
046        public static final Enchantment fireAspect = new EnchantmentFireAspect(20, 2);
047    
048        /** Mobs have a chance to drop more loot */
049        public static final Enchantment looting = new EnchantmentLootBonus(21, 2, EnumEnchantmentType.weapon);
050    
051        /** Faster resource gathering while in use */
052        public static final Enchantment efficiency = new EnchantmentDigging(32, 10);
053    
054        /**
055         * Blocks mined will drop themselves, even if it should drop something else (e.g. stone will drop stone, not
056         * cobblestone)
057         */
058        public static final Enchantment silkTouch = new EnchantmentUntouching(33, 1);
059    
060        /**
061         * Sometimes, the tool's durability will not be spent when the tool is used
062         */
063        public static final Enchantment unbreaking = new EnchantmentDurability(34, 5);
064    
065        /** Can multiply the drop rate of items from blocks */
066        public static final Enchantment fortune = new EnchantmentLootBonus(35, 2, EnumEnchantmentType.digger);
067    
068        /** Power enchantment for bows, add's extra damage to arrows. */
069        public static final Enchantment power = new EnchantmentArrowDamage(48, 10);
070    
071        /**
072         * Knockback enchantments for bows, the arrows will knockback the target when hit.
073         */
074        public static final Enchantment punch = new EnchantmentArrowKnockback(49, 2);
075    
076        /**
077         * Flame enchantment for bows. Arrows fired by the bow will be on fire. Any target hit will also set on fire.
078         */
079        public static final Enchantment flame = new EnchantmentArrowFire(50, 2);
080    
081        /**
082         * Infinity enchantment for bows. The bow will not consume arrows anymore, but will still required at least one
083         * arrow on inventory use the bow.
084         */
085        public static final Enchantment infinity = new EnchantmentArrowInfinite(51, 1);
086        public final int effectId;
087        private final int weight;
088    
089        /** The EnumEnchantmentType given to this Enchantment. */
090        public EnumEnchantmentType type;
091    
092        /** Used in localisation and stats. */
093        protected String name;
094    
095        protected Enchantment(int par1, int par2, EnumEnchantmentType par3EnumEnchantmentType)
096        {
097            this.effectId = par1;
098            this.weight = par2;
099            this.type = par3EnumEnchantmentType;
100    
101            if (enchantmentsList[par1] != null)
102            {
103                throw new IllegalArgumentException("Duplicate enchantment id!");
104            }
105            else
106            {
107                enchantmentsList[par1] = this;
108            }
109        }
110    
111        public int getWeight()
112        {
113            return this.weight;
114        }
115    
116        /**
117         * Returns the minimum level that the enchantment can have.
118         */
119        public int getMinLevel()
120        {
121            return 1;
122        }
123    
124        /**
125         * Returns the maximum level that the enchantment can have.
126         */
127        public int getMaxLevel()
128        {
129            return 1;
130        }
131    
132        /**
133         * Returns the minimal value of enchantability needed on the enchantment level passed.
134         */
135        public int getMinEnchantability(int par1)
136        {
137            return 1 + par1 * 10;
138        }
139    
140        /**
141         * Returns the maximum value of enchantability nedded on the enchantment level passed.
142         */
143        public int getMaxEnchantability(int par1)
144        {
145            return this.getMinEnchantability(par1) + 5;
146        }
147    
148        /**
149         * Calculates de damage protection of the enchantment based on level and damage source passed.
150         */
151        public int calcModifierDamage(int par1, DamageSource par2DamageSource)
152        {
153            return 0;
154        }
155    
156        /**
157         * Calculates de (magic) damage done by the enchantment on a living entity based on level and entity passed.
158         */
159        public int calcModifierLiving(int par1, EntityLiving par2EntityLiving)
160        {
161            return 0;
162        }
163    
164        /**
165         * Determines if the enchantment passed can be applyied together with this enchantment.
166         */
167        public boolean canApplyTogether(Enchantment par1Enchantment)
168        {
169            return this != par1Enchantment;
170        }
171    
172        /**
173         * Sets the enchantment name
174         */
175        public Enchantment setName(String par1Str)
176        {
177            this.name = par1Str;
178            return this;
179        }
180    
181        @SideOnly(Side.CLIENT)
182    
183        /**
184         * Return the name of key in translation table of this enchantment.
185         */
186        public String getName()
187        {
188            return "enchantment." + this.name;
189        }
190    
191        @SideOnly(Side.CLIENT)
192    
193        /**
194         * Returns the correct traslated name of the enchantment and the level in roman numbers.
195         */
196        public String getTranslatedName(int par1)
197        {
198            String var2 = StatCollector.translateToLocal(this.getName());
199            return var2 + " " + StatCollector.translateToLocal("enchantment.level." + par1);
200        }
201    
202        /**
203        * Called to determine if this enchantment can be applied to a ItemStack
204        * @param item The ItemStack that the enchantment might be put on
205        * @return True if the item is valid, false otherwise
206        */
207        public boolean canEnchantItem(ItemStack item) 
208        {
209            return type.canEnchantItem(item.getItem());
210        }
211    }