base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,462 @@
package net.minecraft.potion;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class Potion extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<Potion>
{
public static final RegistryNamespaced<ResourceLocation, Potion> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(Potion.class);
/** Contains a Map of the AttributeModifiers registered by potions */
private final Map<IAttribute, AttributeModifier> attributeModifierMap = Maps.<IAttribute, AttributeModifier>newHashMap();
/** This field indicated if the effect is 'bad' - negative - for the entity. */
private final boolean isBadEffect;
/** Is the color of the liquid for this potion. */
private final int liquidColor;
/** The name of the Potion. */
private String name = "";
/** The index for the icon displayed when the potion effect is active. */
private int statusIconIndex = -1;
private double effectiveness;
private boolean beneficial;
/**
* Gets a Potion from the potion registry using a numeric Id.
*/
@Nullable
public static Potion getPotionById(int potionID)
{
return REGISTRY.getObjectById(potionID);
}
/**
* Gets the numeric Id associated with a potion.
*/
public static int getIdFromPotion(Potion potionIn)
{
return REGISTRY.getIDForObject(potionIn);
}
@Nullable
public static Potion getPotionFromResourceLocation(String location)
{
return REGISTRY.getObject(new ResourceLocation(location));
}
protected Potion(boolean isBadEffectIn, int liquidColorIn)
{
this.isBadEffect = isBadEffectIn;
if (isBadEffectIn)
{
this.effectiveness = 0.5D;
}
else
{
this.effectiveness = 1.0D;
}
this.liquidColor = liquidColorIn;
}
/**
* Sets the index for the icon displayed in the player's inventory when the status is active.
*/
protected Potion setIconIndex(int p_76399_1_, int p_76399_2_)
{
this.statusIconIndex = p_76399_1_ + p_76399_2_ * 8;
return this;
}
public void performEffect(EntityLivingBase entityLivingBaseIn, int amplifier)
{
if (this == MobEffects.REGENERATION)
{
if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth())
{
entityLivingBaseIn.heal(1.0F);
}
}
else if (this == MobEffects.POISON)
{
if (entityLivingBaseIn.getHealth() > 1.0F)
{
entityLivingBaseIn.attackEntityFrom(DamageSource.MAGIC, 1.0F);
}
}
else if (this == MobEffects.WITHER)
{
entityLivingBaseIn.attackEntityFrom(DamageSource.WITHER, 1.0F);
}
else if (this == MobEffects.HUNGER && entityLivingBaseIn instanceof EntityPlayer)
{
((EntityPlayer)entityLivingBaseIn).addExhaustion(0.005F * (float)(amplifier + 1));
}
else if (this == MobEffects.SATURATION && entityLivingBaseIn instanceof EntityPlayer)
{
if (!entityLivingBaseIn.world.isRemote)
{
((EntityPlayer)entityLivingBaseIn).getFoodStats().addStats(amplifier + 1, 1.0F);
}
}
else if ((this != MobEffects.INSTANT_HEALTH || entityLivingBaseIn.isEntityUndead()) && (this != MobEffects.INSTANT_DAMAGE || !entityLivingBaseIn.isEntityUndead()))
{
if (this == MobEffects.INSTANT_DAMAGE && !entityLivingBaseIn.isEntityUndead() || this == MobEffects.INSTANT_HEALTH && entityLivingBaseIn.isEntityUndead())
{
entityLivingBaseIn.attackEntityFrom(DamageSource.MAGIC, (float)(6 << amplifier));
}
}
else
{
entityLivingBaseIn.heal((float)Math.max(4 << amplifier, 0));
}
}
public void affectEntity(@Nullable Entity source, @Nullable Entity indirectSource, EntityLivingBase entityLivingBaseIn, int amplifier, double health)
{
if ((this != MobEffects.INSTANT_HEALTH || entityLivingBaseIn.isEntityUndead()) && (this != MobEffects.INSTANT_DAMAGE || !entityLivingBaseIn.isEntityUndead()))
{
if (this == MobEffects.INSTANT_DAMAGE && !entityLivingBaseIn.isEntityUndead() || this == MobEffects.INSTANT_HEALTH && entityLivingBaseIn.isEntityUndead())
{
int j = (int)(health * (double)(6 << amplifier) + 0.5D);
if (source == null)
{
entityLivingBaseIn.attackEntityFrom(DamageSource.MAGIC, (float)j);
}
else
{
entityLivingBaseIn.attackEntityFrom(DamageSource.causeIndirectMagicDamage(source, indirectSource), (float)j);
}
}
}
else
{
int i = (int)(health * (double)(4 << amplifier) + 0.5D);
entityLivingBaseIn.heal((float)i);
}
}
/**
* checks if Potion effect is ready to be applied this tick.
*/
public boolean isReady(int duration, int amplifier)
{
if (this == MobEffects.REGENERATION)
{
int k = 50 >> amplifier;
if (k > 0)
{
return duration % k == 0;
}
else
{
return true;
}
}
else if (this == MobEffects.POISON)
{
int j = 25 >> amplifier;
if (j > 0)
{
return duration % j == 0;
}
else
{
return true;
}
}
else if (this == MobEffects.WITHER)
{
int i = 40 >> amplifier;
if (i > 0)
{
return duration % i == 0;
}
else
{
return true;
}
}
else
{
return this == MobEffects.HUNGER;
}
}
/**
* Returns true if the potion has an instant effect instead of a continuous one (eg Harming)
*/
public boolean isInstant()
{
return false;
}
/**
* Set the potion name.
*/
public Potion setPotionName(String nameIn)
{
this.name = nameIn;
return this;
}
/**
* returns the name of the potion
*/
public String getName()
{
return this.name;
}
protected Potion setEffectiveness(double effectivenessIn)
{
this.effectiveness = effectivenessIn;
return this;
}
/**
* Returns true if the potion has a associated status icon to display in then inventory when active.
*/
@SideOnly(Side.CLIENT)
public boolean hasStatusIcon()
{
return this.statusIconIndex >= 0;
}
/**
* Returns the index for the icon to display when the potion is active.
*/
@SideOnly(Side.CLIENT)
public int getStatusIconIndex()
{
return this.statusIconIndex;
}
/**
* This method returns true if the potion effect is bad - negative - for the entity.
*/
public boolean isBadEffect()
{
return this.isBadEffect;
}
@SideOnly(Side.CLIENT)
public static String getPotionDurationString(PotionEffect effect, float durationFactor)
{
if (effect.getIsPotionDurationMax())
{
return "**:**";
}
else
{
int i = MathHelper.floor((float)effect.getDuration() * durationFactor);
return StringUtils.ticksToElapsedTime(i);
}
}
/**
* Returns the color of the potion liquid.
*/
public int getLiquidColor()
{
return this.liquidColor;
}
/**
* Used by potions to register the attribute they modify.
*/
public Potion registerPotionAttributeModifier(IAttribute attribute, String uniqueId, double ammount, int operation)
{
AttributeModifier attributemodifier = new AttributeModifier(UUID.fromString(uniqueId), this.getName(), ammount, operation);
this.attributeModifierMap.put(attribute, attributemodifier);
return this;
}
public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
{
for (Entry<IAttribute, AttributeModifier> entry : this.attributeModifierMap.entrySet())
{
IAttributeInstance iattributeinstance = attributeMapIn.getAttributeInstance(entry.getKey());
if (iattributeinstance != null)
{
iattributeinstance.removeModifier(entry.getValue());
}
}
}
@SideOnly(Side.CLIENT)
public Map<IAttribute, AttributeModifier> getAttributeModifierMap()
{
return this.attributeModifierMap;
}
public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
{
for (Entry<IAttribute, AttributeModifier> entry : this.attributeModifierMap.entrySet())
{
IAttributeInstance iattributeinstance = attributeMapIn.getAttributeInstance(entry.getKey());
if (iattributeinstance != null)
{
AttributeModifier attributemodifier = entry.getValue();
iattributeinstance.removeModifier(attributemodifier);
iattributeinstance.applyModifier(new AttributeModifier(attributemodifier.getID(), this.getName() + " " + amplifier, this.getAttributeModifierAmount(amplifier, attributemodifier), attributemodifier.getOperation()));
}
}
}
public double getAttributeModifierAmount(int amplifier, AttributeModifier modifier)
{
return modifier.getAmount() * (double)(amplifier + 1);
}
/* ======================================== FORGE START =====================================*/
/**
* If the Potion effect should be displayed in the players inventory
* @param effect the active PotionEffect
* @return true to display it (default), false to hide it.
*/
public boolean shouldRender(PotionEffect effect) { return true; }
/**
* If the standard PotionEffect text (name and duration) should be drawn when this potion is active.
* @param effect the active PotionEffect
* @return true to draw the standard text
*/
public boolean shouldRenderInvText(PotionEffect effect)
{
return true;
}
/**
* If the Potion effect should be displayed in the player's ingame HUD
* @param effect the active PotionEffect
* @return true to display it (default), false to hide it.
*/
public boolean shouldRenderHUD(PotionEffect effect)
{
return true;
}
/**
* Called to draw the this Potion onto the player's inventory when it's active.
* This can be used to e.g. render Potion icons from your own texture.
* @param x the x coordinate
* @param y the y coordinate
* @param effect the active PotionEffect
* @param mc the Minecraft instance, for convenience
*/
@SideOnly(Side.CLIENT)
public void renderInventoryEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc) { }
/**
* Called to draw the this Potion onto the player's ingame HUD when it's active.
* This can be used to e.g. render Potion icons from your own texture.
* @param x the x coordinate
* @param y the y coordinate
* @param effect the active PotionEffect
* @param mc the Minecraft instance, for convenience
* @param alpha the alpha value, blinks when the potion is about to run out
*/
@SideOnly(Side.CLIENT)
public void renderHUDEffect(int x, int y, PotionEffect effect, net.minecraft.client.Minecraft mc, float alpha) { }
/**
* Get a fresh list of items that can cure this Potion.
* All new PotionEffects created from this Potion will call this to initialize the default curative items
* @see PotionEffect#getCurativeItems
* @return A list of items that can cure this Potion
*/
public java.util.List<net.minecraft.item.ItemStack> getCurativeItems()
{
java.util.ArrayList<net.minecraft.item.ItemStack> ret = new java.util.ArrayList<net.minecraft.item.ItemStack>();
ret.add(new net.minecraft.item.ItemStack(net.minecraft.init.Items.MILK_BUCKET));
return ret;
}
/**
* Used for determining {@code PotionEffect} sort order in GUIs.
* Defaults to the {@code PotionEffect}'s liquid color.
* @param potionEffect the {@code PotionEffect} instance containing the potion
* @return a value used to sort {@code PotionEffect}s in GUIs
*/
public int getGuiSortColor(PotionEffect potionEffect)
{
return this.getLiquidColor();
}
/* ======================================== FORGE END =====================================*/
/**
* Get if the potion is beneficial to the player. Beneficial potions are shown on the first row of the HUD
*/
@SideOnly(Side.CLIENT)
public boolean isBeneficial()
{
return this.beneficial;
}
/**
* Set that the potion is beneficial to the player. Beneficial potions are shown on the first row of the HUD
*/
public Potion setBeneficial()
{
this.beneficial = true;
return this;
}
public static void registerPotions()
{
REGISTRY.register(1, new ResourceLocation("speed"), (new Potion(false, 8171462)).setPotionName("effect.moveSpeed").setIconIndex(0, 0).registerPotionAttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED, "91AEAA56-376B-4498-935B-2F7F68070635", 0.20000000298023224D, 2).setBeneficial());
REGISTRY.register(2, new ResourceLocation("slowness"), (new Potion(true, 5926017)).setPotionName("effect.moveSlowdown").setIconIndex(1, 0).registerPotionAttributeModifier(SharedMonsterAttributes.MOVEMENT_SPEED, "7107DE5E-7CE8-4030-940E-514C1F160890", -0.15000000596046448D, 2));
REGISTRY.register(3, new ResourceLocation("haste"), (new Potion(false, 14270531)).setPotionName("effect.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D).setBeneficial().registerPotionAttributeModifier(SharedMonsterAttributes.ATTACK_SPEED, "AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3", 0.10000000149011612D, 2));
REGISTRY.register(4, new ResourceLocation("mining_fatigue"), (new Potion(true, 4866583)).setPotionName("effect.digSlowDown").setIconIndex(3, 0).registerPotionAttributeModifier(SharedMonsterAttributes.ATTACK_SPEED, "55FCED67-E92A-486E-9800-B47F202C4386", -0.10000000149011612D, 2));
REGISTRY.register(5, new ResourceLocation("strength"), (new PotionAttackDamage(false, 9643043, 3.0D)).setPotionName("effect.damageBoost").setIconIndex(4, 0).registerPotionAttributeModifier(SharedMonsterAttributes.ATTACK_DAMAGE, "648D7064-6A60-4F59-8ABE-C2C23A6DD7A9", 0.0D, 0).setBeneficial());
REGISTRY.register(6, new ResourceLocation("instant_health"), (new PotionHealth(false, 16262179)).setPotionName("effect.heal").setBeneficial());
REGISTRY.register(7, new ResourceLocation("instant_damage"), (new PotionHealth(true, 4393481)).setPotionName("effect.harm").setBeneficial());
REGISTRY.register(8, new ResourceLocation("jump_boost"), (new Potion(false, 2293580)).setPotionName("effect.jump").setIconIndex(2, 1).setBeneficial());
REGISTRY.register(9, new ResourceLocation("nausea"), (new Potion(true, 5578058)).setPotionName("effect.confusion").setIconIndex(3, 1).setEffectiveness(0.25D));
REGISTRY.register(10, new ResourceLocation("regeneration"), (new Potion(false, 13458603)).setPotionName("effect.regeneration").setIconIndex(7, 0).setEffectiveness(0.25D).setBeneficial());
REGISTRY.register(11, new ResourceLocation("resistance"), (new Potion(false, 10044730)).setPotionName("effect.resistance").setIconIndex(6, 1).setBeneficial());
REGISTRY.register(12, new ResourceLocation("fire_resistance"), (new Potion(false, 14981690)).setPotionName("effect.fireResistance").setIconIndex(7, 1).setBeneficial());
REGISTRY.register(13, new ResourceLocation("water_breathing"), (new Potion(false, 3035801)).setPotionName("effect.waterBreathing").setIconIndex(0, 2).setBeneficial());
REGISTRY.register(14, new ResourceLocation("invisibility"), (new Potion(false, 8356754)).setPotionName("effect.invisibility").setIconIndex(0, 1).setBeneficial());
REGISTRY.register(15, new ResourceLocation("blindness"), (new Potion(true, 2039587)).setPotionName("effect.blindness").setIconIndex(5, 1).setEffectiveness(0.25D));
REGISTRY.register(16, new ResourceLocation("night_vision"), (new Potion(false, 2039713)).setPotionName("effect.nightVision").setIconIndex(4, 1).setBeneficial());
REGISTRY.register(17, new ResourceLocation("hunger"), (new Potion(true, 5797459)).setPotionName("effect.hunger").setIconIndex(1, 1));
REGISTRY.register(18, new ResourceLocation("weakness"), (new PotionAttackDamage(true, 4738376, -4.0D)).setPotionName("effect.weakness").setIconIndex(5, 0).registerPotionAttributeModifier(SharedMonsterAttributes.ATTACK_DAMAGE, "22653B89-116E-49DC-9B6B-9971489B5BE5", 0.0D, 0));
REGISTRY.register(19, new ResourceLocation("poison"), (new Potion(true, 5149489)).setPotionName("effect.poison").setIconIndex(6, 0).setEffectiveness(0.25D));
REGISTRY.register(20, new ResourceLocation("wither"), (new Potion(true, 3484199)).setPotionName("effect.wither").setIconIndex(1, 2).setEffectiveness(0.25D));
REGISTRY.register(21, new ResourceLocation("health_boost"), (new PotionHealthBoost(false, 16284963)).setPotionName("effect.healthBoost").setIconIndex(7, 2).registerPotionAttributeModifier(SharedMonsterAttributes.MAX_HEALTH, "5D6F0BA2-1186-46AC-B896-C61C5CEE99CC", 4.0D, 0).setBeneficial());
REGISTRY.register(22, new ResourceLocation("absorption"), (new PotionAbsorption(false, 2445989)).setPotionName("effect.absorption").setIconIndex(2, 2).setBeneficial());
REGISTRY.register(23, new ResourceLocation("saturation"), (new PotionHealth(false, 16262179)).setPotionName("effect.saturation").setBeneficial());
REGISTRY.register(24, new ResourceLocation("glowing"), (new Potion(false, 9740385)).setPotionName("effect.glowing").setIconIndex(4, 2));
REGISTRY.register(25, new ResourceLocation("levitation"), (new Potion(true, 13565951)).setPotionName("effect.levitation").setIconIndex(3, 2));
REGISTRY.register(26, new ResourceLocation("luck"), (new Potion(false, 3381504)).setPotionName("effect.luck").setIconIndex(5, 2).setBeneficial().registerPotionAttributeModifier(SharedMonsterAttributes.LUCK, "03C3C89D-7037-4B42-869F-B146BCB64D2E", 1.0D, 0));
REGISTRY.register(27, new ResourceLocation("unluck"), (new Potion(true, 12624973)).setPotionName("effect.unluck").setIconIndex(6, 2).registerPotionAttributeModifier(SharedMonsterAttributes.LUCK, "CC5AF142-2BD2-4215-B636-2605AED11727", -1.0D, 0));
}
}

View File

@@ -0,0 +1,24 @@
package net.minecraft.potion;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
public class PotionAbsorption extends Potion
{
protected PotionAbsorption(boolean isBadEffectIn, int liquidColorIn)
{
super(isBadEffectIn, liquidColorIn);
}
public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
{
entityLivingBaseIn.setAbsorptionAmount(entityLivingBaseIn.getAbsorptionAmount() - (float)(4 * (amplifier + 1)));
super.removeAttributesModifiersFromEntity(entityLivingBaseIn, attributeMapIn, amplifier);
}
public void applyAttributesModifiersToEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
{
entityLivingBaseIn.setAbsorptionAmount(entityLivingBaseIn.getAbsorptionAmount() + (float)(4 * (amplifier + 1)));
super.applyAttributesModifiersToEntity(entityLivingBaseIn, attributeMapIn, amplifier);
}
}

View File

@@ -0,0 +1,19 @@
package net.minecraft.potion;
import net.minecraft.entity.ai.attributes.AttributeModifier;
public class PotionAttackDamage extends Potion
{
protected final double bonusPerLevel;
protected PotionAttackDamage(boolean isBadEffectIn, int liquidColorIn, double bonusPerLevelIn)
{
super(isBadEffectIn, liquidColorIn);
this.bonusPerLevel = bonusPerLevelIn;
}
public double getAttributeModifierAmount(int amplifier, AttributeModifier modifier)
{
return this.bonusPerLevel * (double)(amplifier + 1);
}
}

View File

@@ -0,0 +1,355 @@
package net.minecraft.potion;
import com.google.common.collect.ComparisonChain;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class PotionEffect implements Comparable<PotionEffect>
{
private static final Logger LOGGER = LogManager.getLogger();
private final Potion potion;
/** The duration of the potion effect */
private int duration;
/** The amplifier of the potion effect */
private int amplifier;
/** Whether the potion is a splash potion */
private boolean isSplashPotion;
/** Whether the potion effect came from a beacon */
private boolean isAmbient;
/** True if potion effect duration is at maximum, false otherwise. */
@SideOnly(Side.CLIENT)
private boolean isPotionDurationMax;
private boolean showParticles;
/** List of ItemStack that can cure the potion effect **/
private java.util.List<net.minecraft.item.ItemStack> curativeItems;
public PotionEffect(Potion potionIn)
{
this(potionIn, 0, 0);
}
public PotionEffect(Potion potionIn, int durationIn)
{
this(potionIn, durationIn, 0);
}
public PotionEffect(Potion potionIn, int durationIn, int amplifierIn)
{
this(potionIn, durationIn, amplifierIn, false, true);
}
public PotionEffect(Potion potionIn, int durationIn, int amplifierIn, boolean ambientIn, boolean showParticlesIn)
{
this.potion = potionIn;
this.duration = durationIn;
this.amplifier = amplifierIn;
this.isAmbient = ambientIn;
this.showParticles = showParticlesIn;
}
public PotionEffect(PotionEffect other)
{
this.potion = other.potion;
this.duration = other.duration;
this.amplifier = other.amplifier;
this.isAmbient = other.isAmbient;
this.showParticles = other.showParticles;
this.curativeItems = other.curativeItems == null ? null : new java.util.ArrayList<net.minecraft.item.ItemStack>(other.curativeItems);
}
/**
* merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied
* potion effect is assumed to be greater.
*/
public void combine(PotionEffect other)
{
if (this.potion != other.potion)
{
LOGGER.warn("This method should only be called for matching effects!");
}
if (other.amplifier > this.amplifier)
{
this.amplifier = other.amplifier;
this.duration = other.duration;
}
else if (other.amplifier == this.amplifier && this.duration < other.duration)
{
this.duration = other.duration;
}
else if (!other.isAmbient && this.isAmbient)
{
this.isAmbient = other.isAmbient;
}
this.showParticles = other.showParticles;
}
public Potion getPotion()
{
return this.potion;
}
public int getDuration()
{
return this.duration;
}
public int getAmplifier()
{
return this.amplifier;
}
/**
* Gets whether this potion effect originated from a beacon
*/
public boolean getIsAmbient()
{
return this.isAmbient;
}
/**
* Gets whether this potion effect will show ambient particles or not.
*/
public boolean doesShowParticles()
{
return this.showParticles;
}
public boolean onUpdate(EntityLivingBase entityIn)
{
if (this.duration > 0)
{
if (this.potion.isReady(this.duration, this.amplifier))
{
this.performEffect(entityIn);
}
this.deincrementDuration();
}
return this.duration > 0;
}
private int deincrementDuration()
{
return --this.duration;
}
public void performEffect(EntityLivingBase entityIn)
{
if (this.duration > 0)
{
this.potion.performEffect(entityIn, this.amplifier);
}
}
public String getEffectName()
{
return this.potion.getName();
}
public String toString()
{
String s;
if (this.amplifier > 0)
{
s = this.getEffectName() + " x " + (this.amplifier + 1) + ", Duration: " + this.duration;
}
else
{
s = this.getEffectName() + ", Duration: " + this.duration;
}
if (this.isSplashPotion)
{
s = s + ", Splash: true";
}
if (!this.showParticles)
{
s = s + ", Particles: false";
}
return s;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (!(p_equals_1_ instanceof PotionEffect))
{
return false;
}
else
{
PotionEffect potioneffect = (PotionEffect)p_equals_1_;
return this.duration == potioneffect.duration && this.amplifier == potioneffect.amplifier && this.isSplashPotion == potioneffect.isSplashPotion && this.isAmbient == potioneffect.isAmbient && this.potion.equals(potioneffect.potion);
}
}
public int hashCode()
{
int i = this.potion.hashCode();
i = 31 * i + this.duration;
i = 31 * i + this.amplifier;
i = 31 * i + (this.isSplashPotion ? 1 : 0);
i = 31 * i + (this.isAmbient ? 1 : 0);
return i;
}
/**
* Write a custom potion effect to a potion item's NBT data.
*/
public NBTTagCompound writeCustomPotionEffectToNBT(NBTTagCompound nbt)
{
nbt.setByte("Id", (byte)Potion.getIdFromPotion(this.getPotion()));
nbt.setByte("Amplifier", (byte)this.getAmplifier());
nbt.setInteger("Duration", this.getDuration());
nbt.setBoolean("Ambient", this.getIsAmbient());
nbt.setBoolean("ShowParticles", this.doesShowParticles());
writeCurativeItems(nbt);
return nbt;
}
/**
* Read a custom potion effect from a potion item's NBT data.
*/
public static PotionEffect readCustomPotionEffectFromNBT(NBTTagCompound nbt)
{
int i = nbt.getByte("Id") & 0xFF;
Potion potion = Potion.getPotionById(i);
if (potion == null)
{
return null;
}
else
{
int j = nbt.getByte("Amplifier");
int k = nbt.getInteger("Duration");
boolean flag = nbt.getBoolean("Ambient");
boolean flag1 = true;
if (nbt.hasKey("ShowParticles", 1))
{
flag1 = nbt.getBoolean("ShowParticles");
}
return readCurativeItems(new PotionEffect(potion, k, j < 0 ? 0 : j, flag, flag1), nbt);
}
}
/**
* Toggle the isPotionDurationMax field.
*/
@SideOnly(Side.CLIENT)
public void setPotionDurationMax(boolean maxDuration)
{
this.isPotionDurationMax = maxDuration;
}
public int compareTo(PotionEffect p_compareTo_1_)
{
int i = 32147;
return (this.getDuration() <= 32147 || p_compareTo_1_.getDuration() <= 32147) && (!this.getIsAmbient() || !p_compareTo_1_.getIsAmbient()) ? ComparisonChain.start().compare(Boolean.valueOf(this.getIsAmbient()), Boolean.valueOf(p_compareTo_1_.getIsAmbient())).compare(this.getDuration(), p_compareTo_1_.getDuration()).compare(this.getPotion().getGuiSortColor(this), p_compareTo_1_.getPotion().getGuiSortColor(p_compareTo_1_)).result() : ComparisonChain.start().compare(Boolean.valueOf(this.getIsAmbient()), Boolean.valueOf(p_compareTo_1_.getIsAmbient())).compare(this.getPotion().getGuiSortColor(this), p_compareTo_1_.getPotion().getGuiSortColor(p_compareTo_1_)).result();
}
/**
* Get the value of the isPotionDurationMax field.
*/
@SideOnly(Side.CLIENT)
public boolean getIsPotionDurationMax()
{
return this.isPotionDurationMax;
}
/* ======================================== FORGE START =====================================*/
/***
* Returns a list of curative items for the potion effect
* By default, this list is initialized using {@link Potion#getCurativeItems}
*
* @return The list (ItemStack) of curative items for the potion effect
*/
public java.util.List<net.minecraft.item.ItemStack> getCurativeItems()
{
if (this.curativeItems == null) //Lazy load this so that we don't create a circular dep on Items.
{
this.curativeItems = getPotion().getCurativeItems();
}
return this.curativeItems;
}
/***
* Checks the given ItemStack to see if it is in the list of curative items for the potion effect
* @param stack The ItemStack being checked against the list of curative items for this PotionEffect
* @return true if the given ItemStack is in the list of curative items for this PotionEffect, false otherwise
*/
public boolean isCurativeItem(net.minecraft.item.ItemStack stack)
{
for (net.minecraft.item.ItemStack curativeItem : this.getCurativeItems())
{
if (curativeItem.isItemEqual(stack))
{
return true;
}
}
return false;
}
/***
* Sets the list of curative items for this potion effect, overwriting any already present
* @param curativeItems The list of ItemStacks being set to the potion effect
*/
public void setCurativeItems(java.util.List<net.minecraft.item.ItemStack> curativeItems)
{
this.curativeItems = curativeItems;
}
/***
* Adds the given stack to the list of curative items for this PotionEffect
* @param stack The ItemStack being added to the curative item list
*/
public void addCurativeItem(net.minecraft.item.ItemStack stack)
{
if (!this.isCurativeItem(stack))
{
this.getCurativeItems().add(stack);
}
}
private void writeCurativeItems(NBTTagCompound nbt)
{
net.minecraft.nbt.NBTTagList list = new net.minecraft.nbt.NBTTagList();
for (net.minecraft.item.ItemStack stack : getCurativeItems())
{
list.appendTag(stack.writeToNBT(new NBTTagCompound()));
}
nbt.setTag("CurativeItems", list);
}
private static PotionEffect readCurativeItems(PotionEffect effect, NBTTagCompound nbt)
{
if (nbt.hasKey("CurativeItems", net.minecraftforge.common.util.Constants.NBT.TAG_LIST))
{
java.util.List<net.minecraft.item.ItemStack> items = new java.util.ArrayList<net.minecraft.item.ItemStack>();
net.minecraft.nbt.NBTTagList list = nbt.getTagList("CurativeItems", net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.tagCount(); i++)
{
items.add(new net.minecraft.item.ItemStack(list.getCompoundTagAt(i)));
}
effect.setCurativeItems(items);
}
return effect;
}
}

View File

@@ -0,0 +1,25 @@
package net.minecraft.potion;
public class PotionHealth extends Potion
{
public PotionHealth(boolean isBadEffectIn, int liquidColorIn)
{
super(isBadEffectIn, liquidColorIn);
}
/**
* Returns true if the potion has an instant effect instead of a continuous one (eg Harming)
*/
public boolean isInstant()
{
return true;
}
/**
* checks if Potion effect is ready to be applied this tick.
*/
public boolean isReady(int duration, int amplifier)
{
return duration >= 1;
}
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.potion;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AbstractAttributeMap;
public class PotionHealthBoost extends Potion
{
public PotionHealthBoost(boolean isBadEffectIn, int liquidColorIn)
{
super(isBadEffectIn, liquidColorIn);
}
public void removeAttributesModifiersFromEntity(EntityLivingBase entityLivingBaseIn, AbstractAttributeMap attributeMapIn, int amplifier)
{
super.removeAttributesModifiersFromEntity(entityLivingBaseIn, attributeMapIn, amplifier);
if (entityLivingBaseIn.getHealth() > entityLivingBaseIn.getMaxHealth())
{
entityLivingBaseIn.setHealth(entityLivingBaseIn.getMaxHealth());
}
}
}

View File

@@ -0,0 +1,243 @@
package net.minecraft.potion;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFishFood;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
public class PotionHelper
{
private static final List<PotionHelper.MixPredicate<PotionType>> POTION_TYPE_CONVERSIONS = Lists.<PotionHelper.MixPredicate<PotionType>>newArrayList();
private static final List<PotionHelper.MixPredicate<Item>> POTION_ITEM_CONVERSIONS = Lists.<PotionHelper.MixPredicate<Item>>newArrayList();
private static final List<Ingredient> POTION_ITEMS = Lists.<Ingredient>newArrayList();
private static final Predicate<ItemStack> IS_POTION_ITEM = new Predicate<ItemStack>()
{
public boolean apply(ItemStack p_apply_1_)
{
for (Ingredient ingredient : PotionHelper.POTION_ITEMS)
{
if (ingredient.apply(p_apply_1_))
{
return true;
}
}
return false;
}
};
public static boolean isReagent(ItemStack stack)
{
return isItemConversionReagent(stack) || isTypeConversionReagent(stack);
}
protected static boolean isItemConversionReagent(ItemStack stack)
{
int i = 0;
for (int j = POTION_ITEM_CONVERSIONS.size(); i < j; ++i)
{
if ((POTION_ITEM_CONVERSIONS.get(i)).reagent.apply(stack))
{
return true;
}
}
return false;
}
protected static boolean isTypeConversionReagent(ItemStack stack)
{
int i = 0;
for (int j = POTION_TYPE_CONVERSIONS.size(); i < j; ++i)
{
if ((POTION_TYPE_CONVERSIONS.get(i)).reagent.apply(stack))
{
return true;
}
}
return false;
}
public static boolean hasConversions(ItemStack input, ItemStack reagent)
{
if (!IS_POTION_ITEM.apply(input))
{
return false;
}
else
{
return hasItemConversions(input, reagent) || hasTypeConversions(input, reagent);
}
}
protected static boolean hasItemConversions(ItemStack input, ItemStack reagent)
{
Item item = input.getItem();
int i = 0;
for (int j = POTION_ITEM_CONVERSIONS.size(); i < j; ++i)
{
PotionHelper.MixPredicate<Item> mixpredicate = (PotionHelper.MixPredicate)POTION_ITEM_CONVERSIONS.get(i);
if (mixpredicate.input == item && mixpredicate.reagent.apply(reagent))
{
return true;
}
}
return false;
}
protected static boolean hasTypeConversions(ItemStack input, ItemStack reagent)
{
PotionType potiontype = PotionUtils.getPotionFromItem(input);
int i = 0;
for (int j = POTION_TYPE_CONVERSIONS.size(); i < j; ++i)
{
PotionHelper.MixPredicate<PotionType> mixpredicate = (PotionHelper.MixPredicate)POTION_TYPE_CONVERSIONS.get(i);
if (mixpredicate.input == potiontype && mixpredicate.reagent.apply(reagent))
{
return true;
}
}
return false;
}
public static ItemStack doReaction(ItemStack reagent, ItemStack potionIn)
{
if (!potionIn.isEmpty())
{
PotionType potiontype = PotionUtils.getPotionFromItem(potionIn);
Item item = potionIn.getItem();
int i = 0;
for (int j = POTION_ITEM_CONVERSIONS.size(); i < j; ++i)
{
PotionHelper.MixPredicate<Item> mixpredicate = (PotionHelper.MixPredicate)POTION_ITEM_CONVERSIONS.get(i);
if (mixpredicate.input == item && mixpredicate.reagent.apply(reagent))
{
return PotionUtils.addPotionToItemStack(new ItemStack((Item)mixpredicate.output), potiontype);
}
}
i = 0;
for (int k = POTION_TYPE_CONVERSIONS.size(); i < k; ++i)
{
PotionHelper.MixPredicate<PotionType> mixpredicate1 = (PotionHelper.MixPredicate)POTION_TYPE_CONVERSIONS.get(i);
if (mixpredicate1.input == potiontype && mixpredicate1.reagent.apply(reagent))
{
return PotionUtils.addPotionToItemStack(new ItemStack(item), (PotionType)mixpredicate1.output);
}
}
}
return potionIn;
}
public static void init()
{
addContainer(Items.POTIONITEM);
addContainer(Items.SPLASH_POTION);
addContainer(Items.LINGERING_POTION);
addContainerRecipe(Items.POTIONITEM, Items.GUNPOWDER, Items.SPLASH_POTION);
addContainerRecipe(Items.SPLASH_POTION, Items.DRAGON_BREATH, Items.LINGERING_POTION);
addMix(PotionTypes.WATER, Items.SPECKLED_MELON, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.GHAST_TEAR, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.RABBIT_FOOT, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.BLAZE_POWDER, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.SPIDER_EYE, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.SUGAR, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.MAGMA_CREAM, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.GLOWSTONE_DUST, PotionTypes.THICK);
addMix(PotionTypes.WATER, Items.REDSTONE, PotionTypes.MUNDANE);
addMix(PotionTypes.WATER, Items.NETHER_WART, PotionTypes.AWKWARD);
addMix(PotionTypes.AWKWARD, Items.GOLDEN_CARROT, PotionTypes.NIGHT_VISION);
addMix(PotionTypes.NIGHT_VISION, Items.REDSTONE, PotionTypes.LONG_NIGHT_VISION);
addMix(PotionTypes.NIGHT_VISION, Items.FERMENTED_SPIDER_EYE, PotionTypes.INVISIBILITY);
addMix(PotionTypes.LONG_NIGHT_VISION, Items.FERMENTED_SPIDER_EYE, PotionTypes.LONG_INVISIBILITY);
addMix(PotionTypes.INVISIBILITY, Items.REDSTONE, PotionTypes.LONG_INVISIBILITY);
addMix(PotionTypes.AWKWARD, Items.MAGMA_CREAM, PotionTypes.FIRE_RESISTANCE);
addMix(PotionTypes.FIRE_RESISTANCE, Items.REDSTONE, PotionTypes.LONG_FIRE_RESISTANCE);
addMix(PotionTypes.AWKWARD, Items.RABBIT_FOOT, PotionTypes.LEAPING);
addMix(PotionTypes.LEAPING, Items.REDSTONE, PotionTypes.LONG_LEAPING);
addMix(PotionTypes.LEAPING, Items.GLOWSTONE_DUST, PotionTypes.STRONG_LEAPING);
addMix(PotionTypes.LEAPING, Items.FERMENTED_SPIDER_EYE, PotionTypes.SLOWNESS);
addMix(PotionTypes.LONG_LEAPING, Items.FERMENTED_SPIDER_EYE, PotionTypes.LONG_SLOWNESS);
addMix(PotionTypes.SLOWNESS, Items.REDSTONE, PotionTypes.LONG_SLOWNESS);
addMix(PotionTypes.SWIFTNESS, Items.FERMENTED_SPIDER_EYE, PotionTypes.SLOWNESS);
addMix(PotionTypes.LONG_SWIFTNESS, Items.FERMENTED_SPIDER_EYE, PotionTypes.LONG_SLOWNESS);
addMix(PotionTypes.AWKWARD, Items.SUGAR, PotionTypes.SWIFTNESS);
addMix(PotionTypes.SWIFTNESS, Items.REDSTONE, PotionTypes.LONG_SWIFTNESS);
addMix(PotionTypes.SWIFTNESS, Items.GLOWSTONE_DUST, PotionTypes.STRONG_SWIFTNESS);
addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(Items.FISH, 1, ItemFishFood.FishType.PUFFERFISH.getMetadata())), PotionTypes.WATER_BREATHING);
addMix(PotionTypes.WATER_BREATHING, Items.REDSTONE, PotionTypes.LONG_WATER_BREATHING);
addMix(PotionTypes.AWKWARD, Items.SPECKLED_MELON, PotionTypes.HEALING);
addMix(PotionTypes.HEALING, Items.GLOWSTONE_DUST, PotionTypes.STRONG_HEALING);
addMix(PotionTypes.HEALING, Items.FERMENTED_SPIDER_EYE, PotionTypes.HARMING);
addMix(PotionTypes.STRONG_HEALING, Items.FERMENTED_SPIDER_EYE, PotionTypes.STRONG_HARMING);
addMix(PotionTypes.HARMING, Items.GLOWSTONE_DUST, PotionTypes.STRONG_HARMING);
addMix(PotionTypes.POISON, Items.FERMENTED_SPIDER_EYE, PotionTypes.HARMING);
addMix(PotionTypes.LONG_POISON, Items.FERMENTED_SPIDER_EYE, PotionTypes.HARMING);
addMix(PotionTypes.STRONG_POISON, Items.FERMENTED_SPIDER_EYE, PotionTypes.STRONG_HARMING);
addMix(PotionTypes.AWKWARD, Items.SPIDER_EYE, PotionTypes.POISON);
addMix(PotionTypes.POISON, Items.REDSTONE, PotionTypes.LONG_POISON);
addMix(PotionTypes.POISON, Items.GLOWSTONE_DUST, PotionTypes.STRONG_POISON);
addMix(PotionTypes.AWKWARD, Items.GHAST_TEAR, PotionTypes.REGENERATION);
addMix(PotionTypes.REGENERATION, Items.REDSTONE, PotionTypes.LONG_REGENERATION);
addMix(PotionTypes.REGENERATION, Items.GLOWSTONE_DUST, PotionTypes.STRONG_REGENERATION);
addMix(PotionTypes.AWKWARD, Items.BLAZE_POWDER, PotionTypes.STRENGTH);
addMix(PotionTypes.STRENGTH, Items.REDSTONE, PotionTypes.LONG_STRENGTH);
addMix(PotionTypes.STRENGTH, Items.GLOWSTONE_DUST, PotionTypes.STRONG_STRENGTH);
addMix(PotionTypes.WATER, Items.FERMENTED_SPIDER_EYE, PotionTypes.WEAKNESS);
addMix(PotionTypes.WEAKNESS, Items.REDSTONE, PotionTypes.LONG_WEAKNESS);
}
public static void addContainerRecipe(ItemPotion p_193355_0_, Item p_193355_1_, ItemPotion p_193355_2_)
{
POTION_ITEM_CONVERSIONS.add(new PotionHelper.MixPredicate(p_193355_0_, Ingredient.fromItems(p_193355_1_), p_193355_2_));
}
public static void addContainer(ItemPotion p_193354_0_)
{
POTION_ITEMS.add(Ingredient.fromItems(p_193354_0_));
}
public static void addMix(PotionType p_193357_0_, Item p_193357_1_, PotionType p_193357_2_)
{
addMix(p_193357_0_, Ingredient.fromItems(p_193357_1_), p_193357_2_);
}
public static void addMix(PotionType p_193356_0_, Ingredient p_193356_1_, PotionType p_193356_2_)
{
POTION_TYPE_CONVERSIONS.add(new PotionHelper.MixPredicate(p_193356_0_, p_193356_1_, p_193356_2_));
}
public static class MixPredicate<T>
{
final T input;
final Ingredient reagent;
final T output;
public MixPredicate(T p_i47570_1_, Ingredient p_i47570_2_, T p_i47570_3_)
{
this.input = p_i47570_1_;
this.reagent = p_i47570_2_;
this.output = p_i47570_3_;
}
}
}

View File

@@ -0,0 +1,117 @@
package net.minecraft.potion;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.UnmodifiableIterator;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.init.MobEffects;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
public class PotionType extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<PotionType>
{
@Deprecated // unused
private static final ResourceLocation EMPTY = new ResourceLocation("empty");
public static final RegistryNamespacedDefaultedByKey<ResourceLocation, PotionType> REGISTRY = net.minecraftforge.registries.GameData.getWrapperDefaulted(PotionType.class);
private static int nextPotionTypeId;
/** The unlocalized name of this PotionType. If null, the registry name is used. */
private final String baseName;
private final ImmutableList<PotionEffect> effects;
@Nullable
public static PotionType getPotionTypeForName(String p_185168_0_)
{
return REGISTRY.getObject(new ResourceLocation(p_185168_0_));
}
public PotionType(PotionEffect... p_i46739_1_)
{
this((String)null, p_i46739_1_);
}
public PotionType(@Nullable String p_i46740_1_, PotionEffect... p_i46740_2_)
{
this.baseName = p_i46740_1_;
this.effects = ImmutableList.copyOf(p_i46740_2_);
}
/**
* Gets the name of this PotionType with a prefix (such as "Splash" or "Lingering") prepended
*/
public String getNamePrefixed(String p_185174_1_)
{
return this.baseName == null ? p_185174_1_ + ((ResourceLocation)REGISTRY.getNameForObject(this)).getResourcePath() : p_185174_1_ + this.baseName;
}
public List<PotionEffect> getEffects()
{
return this.effects;
}
public static void registerPotionTypes()
{
registerPotionType("empty", new PotionType(new PotionEffect[0]));
registerPotionType("water", new PotionType(new PotionEffect[0]));
registerPotionType("mundane", new PotionType(new PotionEffect[0]));
registerPotionType("thick", new PotionType(new PotionEffect[0]));
registerPotionType("awkward", new PotionType(new PotionEffect[0]));
registerPotionType("night_vision", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.NIGHT_VISION, 3600)}));
registerPotionType("long_night_vision", new PotionType("night_vision", new PotionEffect[] {new PotionEffect(MobEffects.NIGHT_VISION, 9600)}));
registerPotionType("invisibility", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.INVISIBILITY, 3600)}));
registerPotionType("long_invisibility", new PotionType("invisibility", new PotionEffect[] {new PotionEffect(MobEffects.INVISIBILITY, 9600)}));
registerPotionType("leaping", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.JUMP_BOOST, 3600)}));
registerPotionType("long_leaping", new PotionType("leaping", new PotionEffect[] {new PotionEffect(MobEffects.JUMP_BOOST, 9600)}));
registerPotionType("strong_leaping", new PotionType("leaping", new PotionEffect[] {new PotionEffect(MobEffects.JUMP_BOOST, 1800, 1)}));
registerPotionType("fire_resistance", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.FIRE_RESISTANCE, 3600)}));
registerPotionType("long_fire_resistance", new PotionType("fire_resistance", new PotionEffect[] {new PotionEffect(MobEffects.FIRE_RESISTANCE, 9600)}));
registerPotionType("swiftness", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.SPEED, 3600)}));
registerPotionType("long_swiftness", new PotionType("swiftness", new PotionEffect[] {new PotionEffect(MobEffects.SPEED, 9600)}));
registerPotionType("strong_swiftness", new PotionType("swiftness", new PotionEffect[] {new PotionEffect(MobEffects.SPEED, 1800, 1)}));
registerPotionType("slowness", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.SLOWNESS, 1800)}));
registerPotionType("long_slowness", new PotionType("slowness", new PotionEffect[] {new PotionEffect(MobEffects.SLOWNESS, 4800)}));
registerPotionType("water_breathing", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.WATER_BREATHING, 3600)}));
registerPotionType("long_water_breathing", new PotionType("water_breathing", new PotionEffect[] {new PotionEffect(MobEffects.WATER_BREATHING, 9600)}));
registerPotionType("healing", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.INSTANT_HEALTH, 1)}));
registerPotionType("strong_healing", new PotionType("healing", new PotionEffect[] {new PotionEffect(MobEffects.INSTANT_HEALTH, 1, 1)}));
registerPotionType("harming", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.INSTANT_DAMAGE, 1)}));
registerPotionType("strong_harming", new PotionType("harming", new PotionEffect[] {new PotionEffect(MobEffects.INSTANT_DAMAGE, 1, 1)}));
registerPotionType("poison", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.POISON, 900)}));
registerPotionType("long_poison", new PotionType("poison", new PotionEffect[] {new PotionEffect(MobEffects.POISON, 1800)}));
registerPotionType("strong_poison", new PotionType("poison", new PotionEffect[] {new PotionEffect(MobEffects.POISON, 432, 1)}));
registerPotionType("regeneration", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.REGENERATION, 900)}));
registerPotionType("long_regeneration", new PotionType("regeneration", new PotionEffect[] {new PotionEffect(MobEffects.REGENERATION, 1800)}));
registerPotionType("strong_regeneration", new PotionType("regeneration", new PotionEffect[] {new PotionEffect(MobEffects.REGENERATION, 450, 1)}));
registerPotionType("strength", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.STRENGTH, 3600)}));
registerPotionType("long_strength", new PotionType("strength", new PotionEffect[] {new PotionEffect(MobEffects.STRENGTH, 9600)}));
registerPotionType("strong_strength", new PotionType("strength", new PotionEffect[] {new PotionEffect(MobEffects.STRENGTH, 1800, 1)}));
registerPotionType("weakness", new PotionType(new PotionEffect[] {new PotionEffect(MobEffects.WEAKNESS, 1800)}));
registerPotionType("long_weakness", new PotionType("weakness", new PotionEffect[] {new PotionEffect(MobEffects.WEAKNESS, 4800)}));
registerPotionType("luck", new PotionType("luck", new PotionEffect[] {new PotionEffect(MobEffects.LUCK, 6000)}));
REGISTRY.validateKey();
}
protected static void registerPotionType(String p_185173_0_, PotionType p_185173_1_)
{
REGISTRY.register(nextPotionTypeId++, new ResourceLocation(p_185173_0_), p_185173_1_);
}
public boolean hasInstantEffect()
{
if (!this.effects.isEmpty())
{
UnmodifiableIterator unmodifiableiterator = this.effects.iterator();
while (unmodifiableiterator.hasNext())
{
PotionEffect potioneffect = (PotionEffect)unmodifiableiterator.next();
if (potioneffect.getPotion().isInstant())
{
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,288 @@
package net.minecraft.potion;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttribute;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PotionUtils
{
/**
* Creates a List of PotionEffect from data on the passed ItemStack's NBTTagCompound.
*/
public static List<PotionEffect> getEffectsFromStack(ItemStack stack)
{
return getEffectsFromTag(stack.getTagCompound());
}
public static List<PotionEffect> mergeEffects(PotionType potionIn, Collection<PotionEffect> effects)
{
List<PotionEffect> list = Lists.<PotionEffect>newArrayList();
list.addAll(potionIn.getEffects());
list.addAll(effects);
return list;
}
/**
* Creates a list of PotionEffect from data on a NBTTagCompound.
*/
public static List<PotionEffect> getEffectsFromTag(@Nullable NBTTagCompound tag)
{
List<PotionEffect> list = Lists.<PotionEffect>newArrayList();
list.addAll(getPotionTypeFromNBT(tag).getEffects());
addCustomPotionEffectToList(tag, list);
return list;
}
public static List<PotionEffect> getFullEffectsFromItem(ItemStack itemIn)
{
return getFullEffectsFromTag(itemIn.getTagCompound());
}
public static List<PotionEffect> getFullEffectsFromTag(@Nullable NBTTagCompound tag)
{
List<PotionEffect> list = Lists.<PotionEffect>newArrayList();
addCustomPotionEffectToList(tag, list);
return list;
}
public static void addCustomPotionEffectToList(@Nullable NBTTagCompound tag, List<PotionEffect> effectList)
{
if (tag != null && tag.hasKey("CustomPotionEffects", 9))
{
NBTTagList nbttaglist = tag.getTagList("CustomPotionEffects", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
if (potioneffect != null)
{
effectList.add(potioneffect);
}
}
}
}
public static int getColor(ItemStack p_190932_0_)
{
NBTTagCompound nbttagcompound = p_190932_0_.getTagCompound();
if (nbttagcompound != null && nbttagcompound.hasKey("CustomPotionColor", 99))
{
return nbttagcompound.getInteger("CustomPotionColor");
}
else
{
return getPotionFromItem(p_190932_0_) == PotionTypes.EMPTY ? 16253176 : getPotionColorFromEffectList(getEffectsFromStack(p_190932_0_));
}
}
public static int getPotionColor(PotionType potionIn)
{
return potionIn == PotionTypes.EMPTY ? 16253176 : getPotionColorFromEffectList(potionIn.getEffects());
}
public static int getPotionColorFromEffectList(Collection<PotionEffect> effects)
{
int i = 3694022;
if (effects.isEmpty())
{
return 3694022;
}
else
{
float f = 0.0F;
float f1 = 0.0F;
float f2 = 0.0F;
int j = 0;
for (PotionEffect potioneffect : effects)
{
if (potioneffect.doesShowParticles())
{
int k = potioneffect.getPotion().getLiquidColor();
int l = potioneffect.getAmplifier() + 1;
f += (float)(l * (k >> 16 & 255)) / 255.0F;
f1 += (float)(l * (k >> 8 & 255)) / 255.0F;
f2 += (float)(l * (k >> 0 & 255)) / 255.0F;
j += l;
}
}
if (j == 0)
{
return 0;
}
else
{
f = f / (float)j * 255.0F;
f1 = f1 / (float)j * 255.0F;
f2 = f2 / (float)j * 255.0F;
return (int)f << 16 | (int)f1 << 8 | (int)f2;
}
}
}
public static PotionType getPotionFromItem(ItemStack itemIn)
{
return getPotionTypeFromNBT(itemIn.getTagCompound());
}
/**
* If no correct potion is found, returns the default one : PotionTypes.water
*/
public static PotionType getPotionTypeFromNBT(@Nullable NBTTagCompound tag)
{
return tag == null ? PotionTypes.EMPTY : PotionType.getPotionTypeForName(tag.getString("Potion"));
}
public static ItemStack addPotionToItemStack(ItemStack itemIn, PotionType potionIn)
{
ResourceLocation resourcelocation = PotionType.REGISTRY.getNameForObject(potionIn);
if (potionIn == PotionTypes.EMPTY)
{
if (itemIn.hasTagCompound())
{
NBTTagCompound nbttagcompound = itemIn.getTagCompound();
nbttagcompound.removeTag("Potion");
if (nbttagcompound.hasNoTags())
{
itemIn.setTagCompound((NBTTagCompound)null);
}
}
}
else
{
NBTTagCompound nbttagcompound1 = itemIn.hasTagCompound() ? itemIn.getTagCompound() : new NBTTagCompound();
nbttagcompound1.setString("Potion", resourcelocation.toString());
itemIn.setTagCompound(nbttagcompound1);
}
return itemIn;
}
public static ItemStack appendEffects(ItemStack itemIn, Collection<PotionEffect> effects)
{
if (effects.isEmpty())
{
return itemIn;
}
else
{
NBTTagCompound nbttagcompound = (NBTTagCompound)MoreObjects.firstNonNull(itemIn.getTagCompound(), new NBTTagCompound());
NBTTagList nbttaglist = nbttagcompound.getTagList("CustomPotionEffects", 9);
for (PotionEffect potioneffect : effects)
{
nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
}
nbttagcompound.setTag("CustomPotionEffects", nbttaglist);
itemIn.setTagCompound(nbttagcompound);
return itemIn;
}
}
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> lores, float durationFactor)
{
List<PotionEffect> list = getEffectsFromStack(itemIn);
List<Tuple<String, AttributeModifier>> list1 = Lists.<Tuple<String, AttributeModifier>>newArrayList();
if (list.isEmpty())
{
String s = I18n.translateToLocal("effect.none").trim();
lores.add(TextFormatting.GRAY + s);
}
else
{
for (PotionEffect potioneffect : list)
{
String s1 = I18n.translateToLocal(potioneffect.getEffectName()).trim();
Potion potion = potioneffect.getPotion();
Map<IAttribute, AttributeModifier> map = potion.getAttributeModifierMap();
if (!map.isEmpty())
{
for (Entry<IAttribute, AttributeModifier> entry : map.entrySet())
{
AttributeModifier attributemodifier = entry.getValue();
AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.getAttributeModifierAmount(potioneffect.getAmplifier(), attributemodifier), attributemodifier.getOperation());
list1.add(new Tuple(((IAttribute)entry.getKey()).getName(), attributemodifier1));
}
}
if (potioneffect.getAmplifier() > 0)
{
s1 = s1 + " " + I18n.translateToLocal("potion.potency." + potioneffect.getAmplifier()).trim();
}
if (potioneffect.getDuration() > 20)
{
s1 = s1 + " (" + Potion.getPotionDurationString(potioneffect, durationFactor) + ")";
}
if (potion.isBadEffect())
{
lores.add(TextFormatting.RED + s1);
}
else
{
lores.add(TextFormatting.BLUE + s1);
}
}
}
if (!list1.isEmpty())
{
lores.add("");
lores.add(TextFormatting.DARK_PURPLE + I18n.translateToLocal("potion.whenDrank"));
for (Tuple<String, AttributeModifier> tuple : list1)
{
AttributeModifier attributemodifier2 = tuple.getSecond();
double d0 = attributemodifier2.getAmount();
double d1;
if (attributemodifier2.getOperation() != 1 && attributemodifier2.getOperation() != 2)
{
d1 = attributemodifier2.getAmount();
}
else
{
d1 = attributemodifier2.getAmount() * 100.0D;
}
if (d0 > 0.0D)
{
lores.add(TextFormatting.BLUE + I18n.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.translateToLocal("attribute.name." + (String)tuple.getFirst())));
}
else if (d0 < 0.0D)
{
d1 = d1 * -1.0D;
lores.add(TextFormatting.RED + I18n.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.translateToLocal("attribute.name." + (String)tuple.getFirst())));
}
}
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.potion;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;