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