001 package net.minecraft.src;
002
003 public class EnchantmentProtection extends Enchantment
004 {
005 /** Holds the name to be translated of each protection type. */
006 private static final String[] protectionName = new String[] {"all", "fire", "fall", "explosion", "projectile"};
007
008 /**
009 * Holds the base factor of enchantability needed to be able to use the enchant.
010 */
011 private static final int[] baseEnchantability = new int[] {1, 10, 5, 5, 3};
012
013 /**
014 * Holds how much each level increased the enchantability factor to be able to use this enchant.
015 */
016 private static final int[] levelEnchantability = new int[] {11, 8, 6, 8, 6};
017
018 /**
019 * Used on the formula of base enchantability, this is the 'window' factor of values to be able to use thing
020 * enchant.
021 */
022 private static final int[] thresholdEnchantability = new int[] {20, 12, 10, 12, 15};
023
024 /**
025 * Defines the type of protection of the enchantment, 0 = all, 1 = fire, 2 = fall (feather fall), 3 = explosion and
026 * 4 = projectile.
027 */
028 public final int protectionType;
029
030 public EnchantmentProtection(int par1, int par2, int par3)
031 {
032 super(par1, par2, EnumEnchantmentType.armor);
033 this.protectionType = par3;
034
035 if (par3 == 2)
036 {
037 this.type = EnumEnchantmentType.armor_feet;
038 }
039 }
040
041 /**
042 * Returns the minimal value of enchantability needed on the enchantment level passed.
043 */
044 public int getMinEnchantability(int par1)
045 {
046 return baseEnchantability[this.protectionType] + (par1 - 1) * levelEnchantability[this.protectionType];
047 }
048
049 /**
050 * Returns the maximum value of enchantability nedded on the enchantment level passed.
051 */
052 public int getMaxEnchantability(int par1)
053 {
054 return this.getMinEnchantability(par1) + thresholdEnchantability[this.protectionType];
055 }
056
057 /**
058 * Returns the maximum level that the enchantment can have.
059 */
060 public int getMaxLevel()
061 {
062 return 4;
063 }
064
065 /**
066 * Calculates de damage protection of the enchantment based on level and damage source passed.
067 */
068 public int calcModifierDamage(int par1, DamageSource par2DamageSource)
069 {
070 if (par2DamageSource.canHarmInCreative())
071 {
072 return 0;
073 }
074 else
075 {
076 int var3 = (6 + par1 * par1) / 2;
077 return this.protectionType == 0 ? var3 : (this.protectionType == 1 && par2DamageSource.isFireDamage() ? var3 : (this.protectionType == 2 && par2DamageSource == DamageSource.fall ? var3 * 2 : ((this.protectionType != 3 || par2DamageSource != DamageSource.explosion) && par2DamageSource != DamageSource.field_76375_l ? (this.protectionType == 4 && par2DamageSource.isProjectile() ? var3 : 0) : var3)));
078 }
079 }
080
081 /**
082 * Return the name of key in translation table of this enchantment.
083 */
084 public String getName()
085 {
086 return "enchantment.protect." + protectionName[this.protectionType];
087 }
088
089 /**
090 * Determines if the enchantment passed can be applyied together with this enchantment.
091 */
092 public boolean canApplyTogether(Enchantment par1Enchantment)
093 {
094 if (par1Enchantment instanceof EnchantmentProtection)
095 {
096 EnchantmentProtection var2 = (EnchantmentProtection)par1Enchantment;
097 return var2.protectionType == this.protectionType ? false : this.protectionType == 2 || var2.protectionType == 2;
098 }
099 else
100 {
101 return super.canApplyTogether(par1Enchantment);
102 }
103 }
104 }