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