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 Potion 007 { 008 /** The array of potion types. */ 009 public static final Potion[] potionTypes = new Potion[32]; 010 public static final Potion field_76423_b = null; 011 public static final Potion moveSpeed = (new Potion(1, false, 8171462)).setPotionName("potion.moveSpeed").setIconIndex(0, 0); 012 public static final Potion moveSlowdown = (new Potion(2, true, 5926017)).setPotionName("potion.moveSlowdown").setIconIndex(1, 0); 013 public static final Potion digSpeed = (new Potion(3, false, 14270531)).setPotionName("potion.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D); 014 public static final Potion digSlowdown = (new Potion(4, true, 4866583)).setPotionName("potion.digSlowDown").setIconIndex(3, 0); 015 public static final Potion damageBoost = (new Potion(5, false, 9643043)).setPotionName("potion.damageBoost").setIconIndex(4, 0); 016 public static final Potion heal = (new PotionHealth(6, false, 16262179)).setPotionName("potion.heal"); 017 public static final Potion harm = (new PotionHealth(7, true, 4393481)).setPotionName("potion.harm"); 018 public static final Potion jump = (new Potion(8, false, 7889559)).setPotionName("potion.jump").setIconIndex(2, 1); 019 public static final Potion confusion = (new Potion(9, true, 5578058)).setPotionName("potion.confusion").setIconIndex(3, 1).setEffectiveness(0.25D); 020 021 /** The regeneration Potion object. */ 022 public static final Potion regeneration = (new Potion(10, false, 13458603)).setPotionName("potion.regeneration").setIconIndex(7, 0).setEffectiveness(0.25D); 023 public static final Potion resistance = (new Potion(11, false, 10044730)).setPotionName("potion.resistance").setIconIndex(6, 1); 024 025 /** The fire resistance Potion object. */ 026 public static final Potion fireResistance = (new Potion(12, false, 14981690)).setPotionName("potion.fireResistance").setIconIndex(7, 1); 027 028 /** The water breathing Potion object. */ 029 public static final Potion waterBreathing = (new Potion(13, false, 3035801)).setPotionName("potion.waterBreathing").setIconIndex(0, 2); 030 031 /** The invisibility Potion object. */ 032 public static final Potion invisibility = (new Potion(14, false, 8356754)).setPotionName("potion.invisibility").setIconIndex(0, 1); 033 034 /** The blindness Potion object. */ 035 public static final Potion blindness = (new Potion(15, true, 2039587)).setPotionName("potion.blindness").setIconIndex(5, 1).setEffectiveness(0.25D); 036 037 /** The night vision Potion object. */ 038 public static final Potion nightVision = (new Potion(16, false, 2039713)).setPotionName("potion.nightVision").setIconIndex(4, 1); 039 040 /** The hunger Potion object. */ 041 public static final Potion hunger = (new Potion(17, true, 5797459)).setPotionName("potion.hunger").setIconIndex(1, 1); 042 043 /** The weakness Potion object. */ 044 public static final Potion weakness = (new Potion(18, true, 4738376)).setPotionName("potion.weakness").setIconIndex(5, 0); 045 046 /** The poison Potion object. */ 047 public static final Potion poison = (new Potion(19, true, 5149489)).setPotionName("potion.poison").setIconIndex(6, 0).setEffectiveness(0.25D); 048 049 /** The wither Potion object. */ 050 public static final Potion wither = (new Potion(20, true, 3484199)).setPotionName("potion.wither").setIconIndex(1, 2).setEffectiveness(0.25D); 051 public static final Potion field_76434_w = null; 052 public static final Potion field_76444_x = null; 053 public static final Potion field_76443_y = null; 054 public static final Potion field_76442_z = null; 055 public static final Potion field_76409_A = null; 056 public static final Potion field_76410_B = null; 057 public static final Potion field_76411_C = null; 058 public static final Potion field_76405_D = null; 059 public static final Potion field_76406_E = null; 060 public static final Potion field_76407_F = null; 061 public static final Potion field_76408_G = null; 062 063 /** The Id of a Potion object. */ 064 public final int id; 065 066 /** The name of the Potion. */ 067 private String name = ""; 068 069 /** The index for the icon displayed when the potion effect is active. */ 070 private int statusIconIndex = -1; 071 072 /** 073 * This field indicated if the effect is 'bad' - negative - for the entity. 074 */ 075 private final boolean isBadEffect; 076 private double effectiveness; 077 private boolean usable; 078 079 /** Is the color of the liquid for this potion. */ 080 private final int liquidColor; 081 082 protected Potion(int par1, boolean par2, int par3) 083 { 084 this.id = par1; 085 potionTypes[par1] = this; 086 this.isBadEffect = par2; 087 088 if (par2) 089 { 090 this.effectiveness = 0.5D; 091 } 092 else 093 { 094 this.effectiveness = 1.0D; 095 } 096 097 this.liquidColor = par3; 098 } 099 100 /** 101 * Sets the index for the icon displayed in the player's inventory when the status is active. 102 */ 103 protected Potion setIconIndex(int par1, int par2) 104 { 105 this.statusIconIndex = par1 + par2 * 8; 106 return this; 107 } 108 109 /** 110 * returns the ID of the potion 111 */ 112 public int getId() 113 { 114 return this.id; 115 } 116 117 public void performEffect(EntityLiving par1EntityLiving, int par2) 118 { 119 if (this.id == regeneration.id) 120 { 121 if (par1EntityLiving.getHealth() < par1EntityLiving.getMaxHealth()) 122 { 123 par1EntityLiving.heal(1); 124 } 125 } 126 else if (this.id == poison.id) 127 { 128 if (par1EntityLiving.getHealth() > 1) 129 { 130 par1EntityLiving.attackEntityFrom(DamageSource.magic, 1); 131 } 132 } 133 else if (this.id == wither.id) 134 { 135 par1EntityLiving.attackEntityFrom(DamageSource.wither, 1); 136 } 137 else if (this.id == hunger.id && par1EntityLiving instanceof EntityPlayer) 138 { 139 ((EntityPlayer)par1EntityLiving).addExhaustion(0.025F * (float)(par2 + 1)); 140 } 141 else if ((this.id != heal.id || par1EntityLiving.isEntityUndead()) && (this.id != harm.id || !par1EntityLiving.isEntityUndead())) 142 { 143 if (this.id == harm.id && !par1EntityLiving.isEntityUndead() || this.id == heal.id && par1EntityLiving.isEntityUndead()) 144 { 145 par1EntityLiving.attackEntityFrom(DamageSource.magic, 6 << par2); 146 } 147 } 148 else 149 { 150 par1EntityLiving.heal(6 << par2); 151 } 152 } 153 154 /** 155 * Hits the provided entity with this potion's instant effect. 156 */ 157 public void affectEntity(EntityLiving par1EntityLiving, EntityLiving par2EntityLiving, int par3, double par4) 158 { 159 int var6; 160 161 if ((this.id != heal.id || par2EntityLiving.isEntityUndead()) && (this.id != harm.id || !par2EntityLiving.isEntityUndead())) 162 { 163 if (this.id == harm.id && !par2EntityLiving.isEntityUndead() || this.id == heal.id && par2EntityLiving.isEntityUndead()) 164 { 165 var6 = (int)(par4 * (double)(6 << par3) + 0.5D); 166 167 if (par1EntityLiving == null) 168 { 169 par2EntityLiving.attackEntityFrom(DamageSource.magic, var6); 170 } 171 else 172 { 173 par2EntityLiving.attackEntityFrom(DamageSource.causeIndirectMagicDamage(par2EntityLiving, par1EntityLiving), var6); 174 } 175 } 176 } 177 else 178 { 179 var6 = (int)(par4 * (double)(6 << par3) + 0.5D); 180 par2EntityLiving.heal(var6); 181 } 182 } 183 184 /** 185 * Returns true if the potion has an instant effect instead of a continuous one (eg Harming) 186 */ 187 public boolean isInstant() 188 { 189 return false; 190 } 191 192 /** 193 * checks if Potion effect is ready to be applied this tick. 194 */ 195 public boolean isReady(int par1, int par2) 196 { 197 int var3; 198 199 if (this.id != regeneration.id && this.id != poison.id) 200 { 201 if (this.id == wither.id) 202 { 203 var3 = 40 >> par2; 204 return var3 > 0 ? par1 % var3 == 0 : true; 205 } 206 else 207 { 208 return this.id == hunger.id; 209 } 210 } 211 else 212 { 213 var3 = 25 >> par2; 214 return var3 > 0 ? par1 % var3 == 0 : true; 215 } 216 } 217 218 /** 219 * Set the potion name. 220 */ 221 public Potion setPotionName(String par1Str) 222 { 223 this.name = par1Str; 224 return this; 225 } 226 227 /** 228 * returns the name of the potion 229 */ 230 public String getName() 231 { 232 return this.name; 233 } 234 235 protected Potion setEffectiveness(double par1) 236 { 237 this.effectiveness = par1; 238 return this; 239 } 240 241 @SideOnly(Side.CLIENT) 242 243 /** 244 * Returns true if the potion has a associated status icon to display in then inventory when active. 245 */ 246 public boolean hasStatusIcon() 247 { 248 return this.statusIconIndex >= 0; 249 } 250 251 @SideOnly(Side.CLIENT) 252 253 /** 254 * Returns the index for the icon to display when the potion is active. 255 */ 256 public int getStatusIconIndex() 257 { 258 return this.statusIconIndex; 259 } 260 261 @SideOnly(Side.CLIENT) 262 263 /** 264 * This method returns true if the potion effect is bad - negative - for the entity. 265 */ 266 public boolean isBadEffect() 267 { 268 return this.isBadEffect; 269 } 270 271 @SideOnly(Side.CLIENT) 272 public static String getDurationString(PotionEffect par0PotionEffect) 273 { 274 int var1 = par0PotionEffect.getDuration(); 275 return StringUtils.ticksToElapsedTime(var1); 276 } 277 278 public double getEffectiveness() 279 { 280 return this.effectiveness; 281 } 282 283 public boolean isUsable() 284 { 285 return this.usable; 286 } 287 288 /** 289 * Returns the color of the potion liquid. 290 */ 291 public int getLiquidColor() 292 { 293 return this.liquidColor; 294 } 295 }