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