| 1 | package net.minecraft.potion;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.Set;
|
| 6 | import java.util.UUID;
|
| 7 | import java.util.Map.Entry;
|
| 8 | import net.minecraft.entity.Entity;
|
| 9 | import net.minecraft.entity.EntityLivingBase;
|
| 10 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 11 | import net.minecraft.entity.ai.attributes.AttributeModifier;
|
| 12 | import net.minecraft.entity.ai.attributes.BaseAttributeMap;
|
| 13 | import net.minecraft.entity.ai.attributes.IAttribute;
|
| 14 | import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
| 15 | import net.minecraft.entity.player.EntityPlayer;
|
| 16 | import net.minecraft.util.DamageSource;
|
| 17 | import net.minecraft.util.ResourceLocation;
|
| 18 | import net.minecraft.util.StringUtils;
|
| 19 |
|
| 20 | public class Potion
|
| 21 | {
|
| 22 | /** The array of potion types. */
|
| 23 | public static final Potion[] potionTypes = new Potion[32];
|
| 24 | private static final Map<ResourceLocation, Potion> field_180150_I = Maps.<ResourceLocation, Potion>newHashMap();
|
| 25 | public static final Potion field_180151_b = null;
|
| 26 | public static final Potion moveSpeed = (new Potion(1, new ResourceLocation("speed"), false, 8171462)).setPotionName("potion.moveSpeed").setIconIndex(0, 0).registerPotionAttributeModifier(SharedMonsterAttributes.movementSpeed, "91AEAA56-376B-4498-935B-2F7F68070635", 0.20000000298023224D, 2);
|
| 27 | public static final Potion moveSlowdown = (new Potion(2, new ResourceLocation("slowness"), true, 5926017)).setPotionName("potion.moveSlowdown").setIconIndex(1, 0).registerPotionAttributeModifier(SharedMonsterAttributes.movementSpeed, "7107DE5E-7CE8-4030-940E-514C1F160890", -0.15000000596046448D, 2);
|
| 28 | public static final Potion digSpeed = (new Potion(3, new ResourceLocation("haste"), false, 14270531)).setPotionName("potion.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D);
|
| 29 | public static final Potion digSlowdown = (new Potion(4, new ResourceLocation("mining_fatigue"), true, 4866583)).setPotionName("potion.digSlowDown").setIconIndex(3, 0);
|
| 30 | public static final Potion damageBoost = (new PotionAttackDamage(5, new ResourceLocation("strength"), false, 9643043)).setPotionName("potion.damageBoost").setIconIndex(4, 0).registerPotionAttributeModifier(SharedMonsterAttributes.attackDamage, "648D7064-6A60-4F59-8ABE-C2C23A6DD7A9", 2.5D, 2);
|
| 31 | public static final Potion heal = (new PotionHealth(6, new ResourceLocation("instant_health"), false, 16262179)).setPotionName("potion.heal");
|
| 32 | public static final Potion harm = (new PotionHealth(7, new ResourceLocation("instant_damage"), true, 4393481)).setPotionName("potion.harm");
|
| 33 | public static final Potion jump = (new Potion(8, new ResourceLocation("jump_boost"), false, 2293580)).setPotionName("potion.jump").setIconIndex(2, 1);
|
| 34 | public static final Potion confusion = (new Potion(9, new ResourceLocation("nausea"), true, 5578058)).setPotionName("potion.confusion").setIconIndex(3, 1).setEffectiveness(0.25D);
|
| 35 |
|
| 36 | /** The regeneration Potion object. */
|
| 37 | public static final Potion regeneration = (new Potion(10, new ResourceLocation("regeneration"), false, 13458603)).setPotionName("potion.regeneration").setIconIndex(7, 0).setEffectiveness(0.25D);
|
| 38 | public static final Potion resistance = (new Potion(11, new ResourceLocation("resistance"), false, 10044730)).setPotionName("potion.resistance").setIconIndex(6, 1);
|
| 39 |
|
| 40 | /** The fire resistance Potion object. */
|
| 41 | public static final Potion fireResistance = (new Potion(12, new ResourceLocation("fire_resistance"), false, 14981690)).setPotionName("potion.fireResistance").setIconIndex(7, 1);
|
| 42 |
|
| 43 | /** The water breathing Potion object. */
|
| 44 | public static final Potion waterBreathing = (new Potion(13, new ResourceLocation("water_breathing"), false, 3035801)).setPotionName("potion.waterBreathing").setIconIndex(0, 2);
|
| 45 |
|
| 46 | /** The invisibility Potion object. */
|
| 47 | public static final Potion invisibility = (new Potion(14, new ResourceLocation("invisibility"), false, 8356754)).setPotionName("potion.invisibility").setIconIndex(0, 1);
|
| 48 |
|
| 49 | /** The blindness Potion object. */
|
| 50 | public static final Potion blindness = (new Potion(15, new ResourceLocation("blindness"), true, 2039587)).setPotionName("potion.blindness").setIconIndex(5, 1).setEffectiveness(0.25D);
|
| 51 |
|
| 52 | /** The night vision Potion object. */
|
| 53 | public static final Potion nightVision = (new Potion(16, new ResourceLocation("night_vision"), false, 2039713)).setPotionName("potion.nightVision").setIconIndex(4, 1);
|
| 54 |
|
| 55 | /** The hunger Potion object. */
|
| 56 | public static final Potion hunger = (new Potion(17, new ResourceLocation("hunger"), true, 5797459)).setPotionName("potion.hunger").setIconIndex(1, 1);
|
| 57 |
|
| 58 | /** The weakness Potion object. */
|
| 59 | public static final Potion weakness = (new PotionAttackDamage(18, new ResourceLocation("weakness"), true, 4738376)).setPotionName("potion.weakness").setIconIndex(5, 0).registerPotionAttributeModifier(SharedMonsterAttributes.attackDamage, "22653B89-116E-49DC-9B6B-9971489B5BE5", 2.0D, 0);
|
| 60 |
|
| 61 | /** The poison Potion object. */
|
| 62 | public static final Potion poison = (new Potion(19, new ResourceLocation("poison"), true, 5149489)).setPotionName("potion.poison").setIconIndex(6, 0).setEffectiveness(0.25D);
|
| 63 |
|
| 64 | /** The wither Potion object. */
|
| 65 | public static final Potion wither = (new Potion(20, new ResourceLocation("wither"), true, 3484199)).setPotionName("potion.wither").setIconIndex(1, 2).setEffectiveness(0.25D);
|
| 66 |
|
| 67 | /** The health boost Potion object. */
|
| 68 | public static final Potion healthBoost = (new PotionHealthBoost(21, new ResourceLocation("health_boost"), false, 16284963)).setPotionName("potion.healthBoost").setIconIndex(2, 2).registerPotionAttributeModifier(SharedMonsterAttributes.maxHealth, "5D6F0BA2-1186-46AC-B896-C61C5CEE99CC", 4.0D, 0);
|
| 69 |
|
| 70 | /** The absorption Potion object. */
|
| 71 | public static final Potion absorption = (new PotionAbsorption(22, new ResourceLocation("absorption"), false, 2445989)).setPotionName("potion.absorption").setIconIndex(2, 2);
|
| 72 |
|
| 73 | /** The saturation Potion object. */
|
| 74 | public static final Potion saturation = (new PotionHealth(23, new ResourceLocation("saturation"), false, 16262179)).setPotionName("potion.saturation");
|
| 75 | public static final Potion field_180153_z = null;
|
| 76 | public static final Potion field_180147_A = null;
|
| 77 | public static final Potion field_180148_B = null;
|
| 78 | public static final Potion field_180149_C = null;
|
| 79 | public static final Potion field_180143_D = null;
|
| 80 | public static final Potion field_180144_E = null;
|
| 81 | public static final Potion field_180145_F = null;
|
| 82 | public static final Potion field_180146_G = null;
|
| 83 |
|
| 84 | /** The Id of a Potion object. */
|
| 85 | public final int id;
|
| 86 | private final Map<IAttribute, AttributeModifier> attributeModifierMap = Maps.<IAttribute, AttributeModifier>newHashMap();
|
| 87 |
|
| 88 | /**
|
| 89 | * This field indicated if the effect is 'bad' - negative - for the entity.
|
| 90 | */
|
| 91 | private final boolean isBadEffect;
|
| 92 |
|
| 93 | /** Is the color of the liquid for this potion. */
|
| 94 | private final int liquidColor;
|
| 95 |
|
| 96 | /** The name of the Potion. */
|
| 97 | private String name = "";
|
| 98 |
|
| 99 | /** The index for the icon displayed when the potion effect is active. */
|
| 100 | private int statusIconIndex = -1;
|
| 101 | private double effectiveness;
|
| 102 | private boolean usable;
|
| 103 |
|
| 104 | protected Potion(int potionID, ResourceLocation location, boolean badEffect, int potionColor)
|
| 105 | {
|
| 106 | this.id = potionID;
|
| 107 | potionTypes[potionID] = this;
|
| 108 | field_180150_I.put(location, this);
|
| 109 | this.isBadEffect = badEffect;
|
| 110 |
|
| 111 | if (badEffect)
|
| 112 | {
|
| 113 | this.effectiveness = 0.5D;
|
| 114 | }
|
| 115 | else
|
| 116 | {
|
| 117 | this.effectiveness = 1.0D;
|
| 118 | }
|
| 119 |
|
| 120 | this.liquidColor = potionColor;
|
| 121 | }
|
| 122 |
|
| 123 | public static Potion getPotionFromResourceLocation(String location)
|
| 124 | {
|
| 125 | return (Potion)field_180150_I.get(new ResourceLocation(location));
|
| 126 | }
|
| 127 |
|
| 128 | public static Set<ResourceLocation> getPotionLocations()
|
| 129 | {
|
| 130 | return field_180150_I.keySet();
|
| 131 | }
|
| 132 |
|
| 133 | /**
|
| 134 | * Sets the index for the icon displayed in the player's inventory when the status is active.
|
| 135 | */
|
| 136 | protected Potion setIconIndex(int p_76399_1_, int p_76399_2_)
|
| 137 | {
|
| 138 | this.statusIconIndex = p_76399_1_ + p_76399_2_ * 8;
|
| 139 | return this;
|
| 140 | }
|
| 141 |
|
| 142 | /**
|
| 143 | * returns the ID of the potion
|
| 144 | */
|
| 145 | public int getId()
|
| 146 | {
|
| 147 | return this.id;
|
| 148 | }
|
| 149 |
|
| 150 | public void performEffect(EntityLivingBase entityLivingBaseIn, int p_76394_2_)
|
| 151 | {
|
| 152 | if (this.id == regeneration.id)
|
| 153 | {
|
| 154 | if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth())
|
| 155 | {
|
| 156 | entityLivingBaseIn.heal(1.0F);
|
| 157 | }
|
| 158 | }
|
| 159 | else if (this.id == poison.id)
|
| 160 | {
|
| 161 | if (entityLivingBaseIn.getHealth() > 1.0F)
|
| 162 | {
|
| 163 | entityLivingBaseIn.attackEntityFrom(DamageSource.magic, 1.0F);
|
| 164 | }
|
| 165 | }
|
| 166 | else if (this.id == wither.id)
|
| 167 | {
|
| 168 | entityLivingBaseIn.attackEntityFrom(DamageSource.wither, 1.0F);
|
| 169 | }
|
| 170 | else if (this.id == hunger.id && entityLivingBaseIn instanceof EntityPlayer)
|
| 171 | {
|
| 172 | ((EntityPlayer)entityLivingBaseIn).addExhaustion(0.025F * (float)(p_76394_2_ + 1));
|
| 173 | }
|
| 174 | else if (this.id == saturation.id && entityLivingBaseIn instanceof EntityPlayer)
|
| 175 | {
|
| 176 | if (!entityLivingBaseIn.worldObj.isRemote)
|
| 177 | {
|
| 178 | ((EntityPlayer)entityLivingBaseIn).getFoodStats().addStats(p_76394_2_ + 1, 1.0F);
|
| 179 | }
|
| 180 | }
|
| 181 | else if ((this.id != heal.id || entityLivingBaseIn.isEntityUndead()) && (this.id != harm.id || !entityLivingBaseIn.isEntityUndead()))
|
| 182 | {
|
| 183 | if (this.id == harm.id && !entityLivingBaseIn.isEntityUndead() || this.id == heal.id && entityLivingBaseIn.isEntityUndead())
|
| 184 | {
|
| 185 | entityLivingBaseIn.attackEntityFrom(DamageSource.magic, (float)(6 << p_76394_2_));
|
| 186 | }
|
| 187 | }
|
| 188 | else
|
| 189 | {
|
| 190 | entityLivingBaseIn.heal((float)Math.max(4 << p_76394_2_, 0));
|
| 191 | }
|
| 192 | }
|
| 193 |
|
| 194 | public void affectEntity(Entity p_180793_1_, Entity p_180793_2_, EntityLivingBase entityLivingBaseIn, int p_180793_4_, double p_180793_5_)
|
| 195 | {
|
| 196 | if ((this.id != heal.id || entityLivingBaseIn.isEntityUndead()) && (this.id != harm.id || !entityLivingBaseIn.isEntityUndead()))
|
| 197 | {
|
| 198 | if (this.id == harm.id && !entityLivingBaseIn.isEntityUndead() || this.id == heal.id && entityLivingBaseIn.isEntityUndead())
|
| 199 | {
|
| 200 | int j = (int)(p_180793_5_ * (double)(6 << p_180793_4_) + 0.5D);
|
| 201 |
|
| 202 | if (p_180793_1_ == null)
|
| 203 | {
|
| 204 | entityLivingBaseIn.attackEntityFrom(DamageSource.magic, (float)j);
|
| 205 | }
|
| 206 | else
|
| 207 | {
|
| 208 | entityLivingBaseIn.attackEntityFrom(DamageSource.causeIndirectMagicDamage(p_180793_1_, p_180793_2_), (float)j);
|
| 209 | }
|
| 210 | }
|
| 211 | }
|
| 212 | else
|
| 213 | {
|
| 214 | int i = (int)(p_180793_5_ * (double)(4 << p_180793_4_) + 0.5D);
|
| 215 | entityLivingBaseIn.heal((float)i);
|
| 216 | }
|
| 217 | }
|
| 218 |
|
| 219 | /**
|
| 220 | * Returns true if the potion has an instant effect instead of a continuous one (eg Harming)
|
| 221 | */
|
| 222 | public boolean isInstant()
|
| 223 | {
|
| 224 | return false;
|
| 225 | }
|
| 226 |
|
| 227 | /**
|
| 228 | * checks if Potion effect is ready to be applied this tick.
|
| 229 | */
|
| 230 | public boolean isReady(int p_76397_1_, int p_76397_2_)
|
| 231 | {
|
| 232 | if (this.id == regeneration.id)
|
| 233 | {
|
| 234 | int k = 50 >> p_76397_2_;
|
| 235 | return k > 0 ? p_76397_1_ % k == 0 : true;
|
| 236 | }
|
| 237 | else if (this.id == poison.id)
|
| 238 | {
|
| 239 | int j = 25 >> p_76397_2_;
|
| 240 | return j > 0 ? p_76397_1_ % j == 0 : true;
|
| 241 | }
|
| 242 | else if (this.id == wither.id)
|
| 243 | {
|
| 244 | int i = 40 >> p_76397_2_;
|
| 245 | return i > 0 ? p_76397_1_ % i == 0 : true;
|
| 246 | }
|
| 247 | else
|
| 248 | {
|
| 249 | return this.id == hunger.id;
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | /**
|
| 254 | * Set the potion name.
|
| 255 | */
|
| 256 | public Potion setPotionName(String nameIn)
|
| 257 | {
|
| 258 | this.name = nameIn;
|
| 259 | return this;
|
| 260 | }
|
| 261 |
|
| 262 | /**
|
| 263 | * returns the name of the potion
|
| 264 | */
|
| 265 | public String getName()
|
| 266 | {
|
| 267 | return this.name;
|
| 268 | }
|
| 269 |
|
| 270 | /**
|
| 271 | * Returns true if the potion has a associated status icon to display in then inventory when active.
|
| 272 | */
|
| 273 | public boolean hasStatusIcon()
|
| 274 | {
|
| 275 | return this.statusIconIndex >= 0;
|
| 276 | }
|
| 277 |
|
| 278 | /**
|
| 279 | * Returns the index for the icon to display when the potion is active.
|
| 280 | */
|
| 281 | public int getStatusIconIndex()
|
| 282 | {
|
| 283 | return this.statusIconIndex;
|
| 284 | }
|
| 285 |
|
| 286 | /**
|
| 287 | * This method returns true if the potion effect is bad - negative - for the entity.
|
| 288 | */
|
| 289 | public boolean isBadEffect()
|
| 290 | {
|
| 291 | return this.isBadEffect;
|
| 292 | }
|
| 293 |
|
| 294 | public static String getDurationString(PotionEffect effect)
|
| 295 | {
|
| 296 | if (effect.getIsPotionDurationMax())
|
| 297 | {
|
| 298 | return "**:**";
|
| 299 | }
|
| 300 | else
|
| 301 | {
|
| 302 | int i = effect.getDuration();
|
| 303 | return StringUtils.ticksToElapsedTime(i);
|
| 304 | }
|
| 305 | }
|
| 306 |
|
| 307 | protected Potion setEffectiveness(double effectivenessIn)
|
| 308 | {
|
| 309 | this.effectiveness = effectivenessIn;
|
| 310 | return this;
|
| 311 | }
|
| 312 |
|
| 313 | public double getEffectiveness()
|
| 314 | {
|
| 315 | return this.effectiveness;
|
| 316 | }
|
| 317 |
|
| 318 | public boolean isUsable()
|
| 319 | {
|
| 320 | return this.usable;
|
| 321 | }
|
| 322 |
|
| 323 | /**
|
| 324 | * Returns the color of the potion liquid.
|
| 325 | */
|
| 326 | public int getLiquidColor()
|
| 327 | {
|
| 328 | return this.liquidColor;
|
| 329 | }
|
| 330 |
|
| 331 | /**
|
| 332 | * Used by potions to register the attribute they modify.
|
| 333 | */
|
| 334 | public Potion registerPotionAttributeModifier(IAttribute p_111184_1_, String p_111184_2_, double p_111184_3_, int p_111184_5_)
|
| 335 | {
|
| 336 | AttributeModifier attributemodifier = new AttributeModifier(UUID.fromString(p_111184_2_), this.getName(), p_111184_3_, p_111184_5_);
|
| 337 | this.attributeModifierMap.put(p_111184_1_, attributemodifier);
|
| 338 | return this;
|
| 339 | }
|
| 340 |
|
| 341 | public Map<IAttribute, AttributeModifier> getAttributeModifierMap()
|
| 342 | {
|
| 343 | return this.attributeModifierMap;
|
| 344 | }
|
| 345 |
|
| 346 | public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, BaseAttributeMap p_111187_2_, int amplifier)
|
| 347 | {
|
| 348 | for (Entry<IAttribute, AttributeModifier> entry : this.attributeModifierMap.entrySet())
|
| 349 | {
|
| 350 | IAttributeInstance iattributeinstance = p_111187_2_.getAttributeInstance((IAttribute)entry.getKey());
|
| 351 |
|
| 352 | if (iattributeinstance != null)
|
| 353 | {
|
| 354 | iattributeinstance.removeModifier((AttributeModifier)entry.getValue());
|
| 355 | }
|
| 356 | }
|
| 357 | }
|
| 358 |
|
| 359 | public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, BaseAttributeMap p_111185_2_, int amplifier)
|
| 360 | {
|
| 361 | for (Entry<IAttribute, AttributeModifier> entry : this.attributeModifierMap.entrySet())
|
| 362 | {
|
| 363 | IAttributeInstance iattributeinstance = p_111185_2_.getAttributeInstance((IAttribute)entry.getKey());
|
| 364 |
|
| 365 | if (iattributeinstance != null)
|
| 366 | {
|
| 367 | AttributeModifier attributemodifier = (AttributeModifier)entry.getValue();
|
| 368 | iattributeinstance.removeModifier(attributemodifier);
|
| 369 | iattributeinstance.applyModifier(new AttributeModifier(attributemodifier.getID(), this.getName() + " " + amplifier, this.getAttributeModifierAmount(amplifier, attributemodifier), attributemodifier.getOperation()));
|
| 370 | }
|
| 371 | }
|
| 372 | }
|
| 373 |
|
| 374 | public double getAttributeModifierAmount(int p_111183_1_, AttributeModifier modifier)
|
| 375 | {
|
| 376 | return modifier.getAmount() * (double)(p_111183_1_ + 1);
|
| 377 | }
|
| 378 | }
|
| 379 |
|