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