| 1 | package net.minecraft.enchantment;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Map;
|
| 7 | import java.util.Set;
|
| 8 | import net.minecraft.entity.Entity;
|
| 9 | import net.minecraft.entity.EntityLivingBase;
|
| 10 | import net.minecraft.entity.EnumCreatureAttribute;
|
| 11 | import net.minecraft.item.ItemStack;
|
| 12 | import net.minecraft.util.DamageSource;
|
| 13 | import net.minecraft.util.ResourceLocation;
|
| 14 | import net.minecraft.util.StatCollector;
|
| 15 |
|
| 16 | public abstract class Enchantment
|
| 17 | {
|
| 18 | private static final Enchantment[] enchantmentsList = new Enchantment[256];
|
| 19 | public static final Enchantment[] enchantmentsBookList;
|
| 20 | private static final Map<ResourceLocation, Enchantment> locationEnchantments = Maps.<ResourceLocation, Enchantment>newHashMap();
|
| 21 | public static final Enchantment protection = new EnchantmentProtection(0, new ResourceLocation("protection"), 10, 0);
|
| 22 |
|
| 23 | /** Protection against fire */
|
| 24 | public static final Enchantment fireProtection = new EnchantmentProtection(1, new ResourceLocation("fire_protection"), 5, 1);
|
| 25 | public static final Enchantment featherFalling = new EnchantmentProtection(2, new ResourceLocation("feather_falling"), 5, 2);
|
| 26 |
|
| 27 | /** Protection against explosions */
|
| 28 | public static final Enchantment blastProtection = new EnchantmentProtection(3, new ResourceLocation("blast_protection"), 2, 3);
|
| 29 | public static final Enchantment projectileProtection = new EnchantmentProtection(4, new ResourceLocation("projectile_protection"), 5, 4);
|
| 30 | public static final Enchantment respiration = new EnchantmentOxygen(5, new ResourceLocation("respiration"), 2);
|
| 31 |
|
| 32 | /** Increases underwater mining rate */
|
| 33 | public static final Enchantment aquaAffinity = new EnchantmentWaterWorker(6, new ResourceLocation("aqua_affinity"), 2);
|
| 34 | public static final Enchantment thorns = new EnchantmentThorns(7, new ResourceLocation("thorns"), 1);
|
| 35 | public static final Enchantment depthStrider = new EnchantmentWaterWalker(8, new ResourceLocation("depth_strider"), 2);
|
| 36 | public static final Enchantment sharpness = new EnchantmentDamage(16, new ResourceLocation("sharpness"), 10, 0);
|
| 37 | public static final Enchantment smite = new EnchantmentDamage(17, new ResourceLocation("smite"), 5, 1);
|
| 38 | public static final Enchantment baneOfArthropods = new EnchantmentDamage(18, new ResourceLocation("bane_of_arthropods"), 5, 2);
|
| 39 | public static final Enchantment knockback = new EnchantmentKnockback(19, new ResourceLocation("knockback"), 5);
|
| 40 |
|
| 41 | /** Lights mobs on fire */
|
| 42 | public static final Enchantment fireAspect = new EnchantmentFireAspect(20, new ResourceLocation("fire_aspect"), 2);
|
| 43 |
|
| 44 | /** Mobs have a chance to drop more loot */
|
| 45 | public static final Enchantment looting = new EnchantmentLootBonus(21, new ResourceLocation("looting"), 2, EnumEnchantmentType.WEAPON);
|
| 46 |
|
| 47 | /** Faster resource gathering while in use */
|
| 48 | public static final Enchantment efficiency = new EnchantmentDigging(32, new ResourceLocation("efficiency"), 10);
|
| 49 |
|
| 50 | /**
|
| 51 | * Blocks mined will drop themselves, even if it should drop something else (e.g. stone will drop stone, not
|
| 52 | * cobblestone)
|
| 53 | */
|
| 54 | public static final Enchantment silkTouch = new EnchantmentUntouching(33, new ResourceLocation("silk_touch"), 1);
|
| 55 |
|
| 56 | /**
|
| 57 | * Sometimes, the tool's durability will not be spent when the tool is used
|
| 58 | */
|
| 59 | public static final Enchantment unbreaking = new EnchantmentDurability(34, new ResourceLocation("unbreaking"), 5);
|
| 60 |
|
| 61 | /** Can multiply the drop rate of items from blocks */
|
| 62 | public static final Enchantment fortune = new EnchantmentLootBonus(35, new ResourceLocation("fortune"), 2, EnumEnchantmentType.DIGGER);
|
| 63 |
|
| 64 | /** Power enchantment for bows, add's extra damage to arrows. */
|
| 65 | public static final Enchantment power = new EnchantmentArrowDamage(48, new ResourceLocation("power"), 10);
|
| 66 |
|
| 67 | /**
|
| 68 | * Knockback enchantments for bows, the arrows will knockback the target when hit.
|
| 69 | */
|
| 70 | public static final Enchantment punch = new EnchantmentArrowKnockback(49, new ResourceLocation("punch"), 2);
|
| 71 |
|
| 72 | /**
|
| 73 | * Flame enchantment for bows. Arrows fired by the bow will be on fire. Any target hit will also set on fire.
|
| 74 | */
|
| 75 | public static final Enchantment flame = new EnchantmentArrowFire(50, new ResourceLocation("flame"), 2);
|
| 76 |
|
| 77 | /**
|
| 78 | * Infinity enchantment for bows. The bow will not consume arrows anymore, but will still required at least one
|
| 79 | * arrow on inventory use the bow.
|
| 80 | */
|
| 81 | public static final Enchantment infinity = new EnchantmentArrowInfinite(51, new ResourceLocation("infinity"), 1);
|
| 82 | public static final Enchantment luckOfTheSea = new EnchantmentLootBonus(61, new ResourceLocation("luck_of_the_sea"), 2, EnumEnchantmentType.FISHING_ROD);
|
| 83 | public static final Enchantment lure = new EnchantmentFishingSpeed(62, new ResourceLocation("lure"), 2, EnumEnchantmentType.FISHING_ROD);
|
| 84 | public final int effectId;
|
| 85 | private final int weight;
|
| 86 |
|
| 87 | /** The EnumEnchantmentType given to this Enchantment. */
|
| 88 | public EnumEnchantmentType type;
|
| 89 |
|
| 90 | /** Used in localisation and stats. */
|
| 91 | protected String name;
|
| 92 |
|
| 93 | /**
|
| 94 | * Retrieves an Enchantment from the enchantmentsList
|
| 95 | */
|
| 96 | public static Enchantment getEnchantmentById(int enchID)
|
| 97 | {
|
| 98 | return enchID >= 0 && enchID < enchantmentsList.length ? enchantmentsList[enchID] : null;
|
| 99 | }
|
| 100 |
|
| 101 | protected Enchantment(int enchID, ResourceLocation enchName, int enchWeight, EnumEnchantmentType enchType)
|
| 102 | {
|
| 103 | this.effectId = enchID;
|
| 104 | this.weight = enchWeight;
|
| 105 | this.type = enchType;
|
| 106 |
|
| 107 | if (enchantmentsList[enchID] != null)
|
| 108 | {
|
| 109 | throw new IllegalArgumentException("Duplicate enchantment id!");
|
| 110 | }
|
| 111 | else
|
| 112 | {
|
| 113 | enchantmentsList[enchID] = this;
|
| 114 | locationEnchantments.put(enchName, this);
|
| 115 | }
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * Retrieves an enchantment by using its location name.
|
| 120 | */
|
| 121 | public static Enchantment getEnchantmentByLocation(String location)
|
| 122 | {
|
| 123 | return (Enchantment)locationEnchantments.get(new ResourceLocation(location));
|
| 124 | }
|
| 125 |
|
| 126 | public static Set<ResourceLocation> func_181077_c()
|
| 127 | {
|
| 128 | return locationEnchantments.keySet();
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | * Retrieves the weight value of an Enchantment. This weight value is used within vanilla to determine how rare an
|
| 133 | * enchantment is.
|
| 134 | */
|
| 135 | public int getWeight()
|
| 136 | {
|
| 137 | return this.weight;
|
| 138 | }
|
| 139 |
|
| 140 | /**
|
| 141 | * Returns the minimum level that the enchantment can have.
|
| 142 | */
|
| 143 | public int getMinLevel()
|
| 144 | {
|
| 145 | return 1;
|
| 146 | }
|
| 147 |
|
| 148 | /**
|
| 149 | * Returns the maximum level that the enchantment can have.
|
| 150 | */
|
| 151 | public int getMaxLevel()
|
| 152 | {
|
| 153 | return 1;
|
| 154 | }
|
| 155 |
|
| 156 | /**
|
| 157 | * Returns the minimal value of enchantability needed on the enchantment level passed.
|
| 158 | */
|
| 159 | public int getMinEnchantability(int enchantmentLevel)
|
| 160 | {
|
| 161 | return 1 + enchantmentLevel * 10;
|
| 162 | }
|
| 163 |
|
| 164 | /**
|
| 165 | * Returns the maximum value of enchantability nedded on the enchantment level passed.
|
| 166 | */
|
| 167 | public int getMaxEnchantability(int enchantmentLevel)
|
| 168 | {
|
| 169 | return this.getMinEnchantability(enchantmentLevel) + 5;
|
| 170 | }
|
| 171 |
|
| 172 | /**
|
| 173 | * Calculates the damage protection of the enchantment based on level and damage source passed.
|
| 174 | */
|
| 175 | public int calcModifierDamage(int level, DamageSource source)
|
| 176 | {
|
| 177 | return 0;
|
| 178 | }
|
| 179 |
|
| 180 | /**
|
| 181 | * Calculates the additional damage that will be dealt by an item with this enchantment. This alternative to
|
| 182 | * calcModifierDamage is sensitive to the targets EnumCreatureAttribute.
|
| 183 | */
|
| 184 | public float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
|
| 185 | {
|
| 186 | return 0.0F;
|
| 187 | }
|
| 188 |
|
| 189 | /**
|
| 190 | * Determines if the enchantment passed can be applyied together with this enchantment.
|
| 191 | */
|
| 192 | public boolean canApplyTogether(Enchantment ench)
|
| 193 | {
|
| 194 | return this != ench;
|
| 195 | }
|
| 196 |
|
| 197 | /**
|
| 198 | * Sets the enchantment name
|
| 199 | */
|
| 200 | public Enchantment setName(String enchName)
|
| 201 | {
|
| 202 | this.name = enchName;
|
| 203 | return this;
|
| 204 | }
|
| 205 |
|
| 206 | /**
|
| 207 | * Return the name of key in translation table of this enchantment.
|
| 208 | */
|
| 209 | public String getName()
|
| 210 | {
|
| 211 | return "enchantment." + this.name;
|
| 212 | }
|
| 213 |
|
| 214 | /**
|
| 215 | * Returns the correct traslated name of the enchantment and the level in roman numbers.
|
| 216 | */
|
| 217 | public String getTranslatedName(int level)
|
| 218 | {
|
| 219 | String s = StatCollector.translateToLocal(this.getName());
|
| 220 | return s + " " + StatCollector.translateToLocal("enchantment.level." + level);
|
| 221 | }
|
| 222 |
|
| 223 | /**
|
| 224 | * Determines if this enchantment can be applied to a specific ItemStack.
|
| 225 | */
|
| 226 | public boolean canApply(ItemStack stack)
|
| 227 | {
|
| 228 | return this.type.canEnchantItem(stack.getItem());
|
| 229 | }
|
| 230 |
|
| 231 | /**
|
| 232 | * Called whenever a mob is damaged with an item that has this enchantment on it.
|
| 233 | */
|
| 234 | public void onEntityDamaged(EntityLivingBase user, Entity target, int level)
|
| 235 | {
|
| 236 | }
|
| 237 |
|
| 238 | /**
|
| 239 | * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
|
| 240 | * called.
|
| 241 | */
|
| 242 | public void onUserHurt(EntityLivingBase user, Entity attacker, int level)
|
| 243 | {
|
| 244 | }
|
| 245 |
|
| 246 | static
|
| 247 | {
|
| 248 | List<Enchantment> list = Lists.<Enchantment>newArrayList();
|
| 249 |
|
| 250 | for (Enchantment enchantment : enchantmentsList)
|
| 251 | {
|
| 252 | if (enchantment != null)
|
| 253 | {
|
| 254 | list.add(enchantment);
|
| 255 | }
|
| 256 | }
|
| 257 |
|
| 258 | enchantmentsBookList = (Enchantment[])list.toArray(new Enchantment[list.size()]);
|
| 259 | }
|
| 260 | }
|
| 261 |
|