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