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