| 1 | package net.minecraft.enchantment;
|
| 2 |
|
| 3 | import net.minecraft.entity.Entity;
|
| 4 | import net.minecraft.util.DamageSource;
|
| 5 | import net.minecraft.util.MathHelper;
|
| 6 | import net.minecraft.util.ResourceLocation;
|
| 7 |
|
| 8 | public class EnchantmentProtection extends Enchantment
|
| 9 | {
|
| 10 | /** Holds the name to be translated of each protection type. */
|
| 11 | private static final String[] protectionName = new String[] {"all", "fire", "fall", "explosion", "projectile"};
|
| 12 |
|
| 13 | /**
|
| 14 | * Holds the base factor of enchantability needed to be able to use the enchant.
|
| 15 | */
|
| 16 | private static final int[] baseEnchantability = new int[] {1, 10, 5, 5, 3};
|
| 17 |
|
| 18 | /**
|
| 19 | * Holds how much each level increased the enchantability factor to be able to use this enchant.
|
| 20 | */
|
| 21 | private static final int[] levelEnchantability = new int[] {11, 8, 6, 8, 6};
|
| 22 |
|
| 23 | /**
|
| 24 | * Used on the formula of base enchantability, this is the 'window' factor of values to be able to use thing
|
| 25 | * enchant.
|
| 26 | */
|
| 27 | private static final int[] thresholdEnchantability = new int[] {20, 12, 10, 12, 15};
|
| 28 |
|
| 29 | /**
|
| 30 | * Defines the type of protection of the enchantment, 0 = all, 1 = fire, 2 = fall (feather fall), 3 = explosion and
|
| 31 | * 4 = projectile.
|
| 32 | */
|
| 33 | public final int protectionType;
|
| 34 |
|
| 35 | public EnchantmentProtection(int p_i45765_1_, ResourceLocation p_i45765_2_, int p_i45765_3_, int p_i45765_4_)
|
| 36 | {
|
| 37 | super(p_i45765_1_, p_i45765_2_, p_i45765_3_, EnumEnchantmentType.ARMOR);
|
| 38 | this.protectionType = p_i45765_4_;
|
| 39 |
|
| 40 | if (p_i45765_4_ == 2)
|
| 41 | {
|
| 42 | this.type = EnumEnchantmentType.ARMOR_FEET;
|
| 43 | }
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Returns the minimal value of enchantability needed on the enchantment level passed.
|
| 48 | */
|
| 49 | public int getMinEnchantability(int enchantmentLevel)
|
| 50 | {
|
| 51 | return baseEnchantability[this.protectionType] + (enchantmentLevel - 1) * levelEnchantability[this.protectionType];
|
| 52 | }
|
| 53 |
|
| 54 | /**
|
| 55 | * Returns the maximum value of enchantability nedded on the enchantment level passed.
|
| 56 | */
|
| 57 | public int getMaxEnchantability(int enchantmentLevel)
|
| 58 | {
|
| 59 | return this.getMinEnchantability(enchantmentLevel) + thresholdEnchantability[this.protectionType];
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * Returns the maximum level that the enchantment can have.
|
| 64 | */
|
| 65 | public int getMaxLevel()
|
| 66 | {
|
| 67 | return 4;
|
| 68 | }
|
| 69 |
|
| 70 | /**
|
| 71 | * Calculates the damage protection of the enchantment based on level and damage source passed.
|
| 72 | */
|
| 73 | public int calcModifierDamage(int level, DamageSource source)
|
| 74 | {
|
| 75 | if (source.canHarmInCreative())
|
| 76 | {
|
| 77 | return 0;
|
| 78 | }
|
| 79 | else
|
| 80 | {
|
| 81 | float f = (float)(6 + level * level) / 3.0F;
|
| 82 | return this.protectionType == 0 ? MathHelper.floor_float(f * 0.75F) : (this.protectionType == 1 && source.isFireDamage() ? MathHelper.floor_float(f * 1.25F) : (this.protectionType == 2 && source == DamageSource.fall ? MathHelper.floor_float(f * 2.5F) : (this.protectionType == 3 && source.isExplosion() ? MathHelper.floor_float(f * 1.5F) : (this.protectionType == 4 && source.isProjectile() ? MathHelper.floor_float(f * 1.5F) : 0))));
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | /**
|
| 87 | * Return the name of key in translation table of this enchantment.
|
| 88 | */
|
| 89 | public String getName()
|
| 90 | {
|
| 91 | return "enchantment.protect." + protectionName[this.protectionType];
|
| 92 | }
|
| 93 |
|
| 94 | /**
|
| 95 | * Determines if the enchantment passed can be applyied together with this enchantment.
|
| 96 | */
|
| 97 | public boolean canApplyTogether(Enchantment ench)
|
| 98 | {
|
| 99 | if (ench instanceof EnchantmentProtection)
|
| 100 | {
|
| 101 | EnchantmentProtection enchantmentprotection = (EnchantmentProtection)ench;
|
| 102 | return enchantmentprotection.protectionType == this.protectionType ? false : this.protectionType == 2 || enchantmentprotection.protectionType == 2;
|
| 103 | }
|
| 104 | else
|
| 105 | {
|
| 106 | return super.canApplyTogether(ench);
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | /**
|
| 111 | * Gets the amount of ticks an entity should be set fire, adjusted for fire protection.
|
| 112 | */
|
| 113 | public static int getFireTimeForEntity(Entity p_92093_0_, int p_92093_1_)
|
| 114 | {
|
| 115 | int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantment.fireProtection.effectId, p_92093_0_.getInventory());
|
| 116 |
|
| 117 | if (i > 0)
|
| 118 | {
|
| 119 | p_92093_1_ -= MathHelper.floor_float((float)p_92093_1_ * (float)i * 0.15F);
|
| 120 | }
|
| 121 |
|
| 122 | return p_92093_1_;
|
| 123 | }
|
| 124 |
|
| 125 | public static double func_92092_a(Entity p_92092_0_, double p_92092_1_)
|
| 126 | {
|
| 127 | int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantment.blastProtection.effectId, p_92092_0_.getInventory());
|
| 128 |
|
| 129 | if (i > 0)
|
| 130 | {
|
| 131 | p_92092_1_ -= (double)MathHelper.floor_double(p_92092_1_ * (double)((float)i * 0.15F));
|
| 132 | }
|
| 133 |
|
| 134 | return p_92092_1_;
|
| 135 | }
|
| 136 | }
|
| 137 |
|