potion cleanup

This commit is contained in:
Sen 2025-03-26 21:07:23 +01:00
parent 460a58e062
commit e108650cd4
30 changed files with 644 additions and 968 deletions

View file

@ -1329,9 +1329,9 @@ public class EntityHorse extends EntityAnimal implements IInvBasic
{
this.motionY = this.getHorseJumpStrength() * (double)this.jumpPower;
if (this.hasEffect(Potion.jump))
if (this.hasEffect(Potion.JUMP))
{
this.motionY += (double)((float)(this.getEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
this.motionY += (double)((float)(this.getEffect(Potion.JUMP).getAmplifier() + 1) * 0.1F);
}
this.setHorseJumping(true);

View file

@ -342,7 +342,7 @@ public class EntityRabbit extends EntityAnimal {
}).isEmpty())
this.setInLove(null);
if(state.getBlock() == Blocks.blue_mushroom)
this.addEffect(new PotionEffect(Potion.moveSpeed.id, this.rand.range(400, 2600), this.rand.chance(0, 1, 5)));
this.addEffect(new PotionEffect(Potion.SPEED, this.rand.range(400, 2600), this.rand.chance(0, 1, 5)));
this.worldObj.destroyBlock(pos, false);
this.worldObj.setState(pos, Blocks.air.getState(), 2);
}

View file

@ -111,11 +111,11 @@ public class EntityArachnoid extends EntityNPC
if (livingdata instanceof EntityArachnoid.GroupData)
{
int i = ((EntityArachnoid.GroupData)livingdata).potionEffectId;
Potion i = ((EntityArachnoid.GroupData)livingdata).potionEffectId;
if (i > 0 && Potion.POTION_TYPES[i] != null)
if (i != null)
{
this.addEffect(new PotionEffect(i, Integer.MAX_VALUE));
this.addEffect(new PotionEffect(i, Integer.MAX_VALUE, 0));
}
if(((EntityArachnoid.GroupData)livingdata).isChild)
@ -228,7 +228,7 @@ public class EntityArachnoid extends EntityNPC
{
if(super.attackEntityAsMob(entityIn)) {
if(entityIn instanceof EntityLiving && this.rand.chance(50))
((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.poison.id, this.rand.range(14, 35) * 20, 0));
((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.POISON, this.rand.range(14, 35) * 20, 0));
return true;
}
return false;
@ -248,7 +248,7 @@ public class EntityArachnoid extends EntityNPC
public static class GroupData
{
public int potionEffectId;
public Potion potionEffectId;
public boolean isChild;
public GroupData(boolean isChild) {
@ -257,7 +257,7 @@ public class EntityArachnoid extends EntityNPC
public void pickEffect(Random rand)
{
this.potionEffectId = rand.pick(Potion.moveSpeed.id, Potion.moveSpeed.id, Potion.damageBoost.id, Potion.regeneration.id);
this.potionEffectId = rand.pick(Potion.SPEED, Potion.SPEED, Potion.STRENGTH, Potion.REGENERATION);
}
}
}

View file

@ -5,6 +5,7 @@ import game.ai.EntityMoveHelper;
import game.block.Block;
import game.entity.attributes.Attributes;
import game.entity.types.EntityLiving;
import game.potion.Potion;
import game.rng.Random;
import game.util.ExtMath;
import game.world.BlockPos;
@ -112,6 +113,11 @@ public abstract class EntityFlyingNPC extends EntityNPC
return false;
}
public boolean isPotionApplicable(Potion potion)
{
return potion != Potion.FLYING && super.isPotionApplicable(potion);
}
static class AILookAround extends EntityAIBase
{
private EntityFlyingNPC parentEntity;

View file

@ -64,7 +64,7 @@ public class EntityMage extends EntityNPC
// i = 8237;
// }
// else
if (this.rand.floatv() < 0.15F && this.isBurning() && !this.hasEffect(Potion.fireResistance))
if (this.rand.floatv() < 0.15F && this.isBurning() && !this.hasEffect(Potion.FIRE_RESISTANCE))
{
i = 16307;
}
@ -72,11 +72,11 @@ public class EntityMage extends EntityNPC
{
i = 16341;
}
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.SPEED) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
{
i = 16274;
}
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
else if (this.rand.floatv() < 0.25F && this.getAttackTarget() != null && !this.hasEffect(Potion.SPEED) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
{
i = 16274;
}

View file

@ -798,15 +798,15 @@ public abstract class EntityNPC extends EntityLiving
double d3 = target.posZ + target.motionZ - this.posZ;
float f = ExtMath.sqrtd(d1 * d1 + d3 * d3);
if (f >= 8.0F && !target.hasEffect(Potion.moveSlowdown))
if (f >= 8.0F && !target.hasEffect(Potion.SLOWNESS))
{
entitypotion.setPotionDamage(32698);
}
else if (target.getHealth() >= 8 && !target.hasEffect(Potion.poison))
else if (target.getHealth() >= 8 && !target.hasEffect(Potion.POISON))
{
entitypotion.setPotionDamage(32660);
}
else if (f <= 3.0F && !target.hasEffect(Potion.weakness) && this.rand.floatv() < 0.25F)
else if (f <= 3.0F && !target.hasEffect(Potion.WEAKNESS) && this.rand.floatv() < 0.25F)
{
entitypotion.setPotionDamage(32696);
}
@ -2404,7 +2404,7 @@ public abstract class EntityNPC extends EntityLiving
this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
boolean canSprint = true; // (float)this.getFoodStats().getFoodLevel() > 6.0F || this.allowFlying;
if (this.onGround && !flag1 && !flag2 && this.gm.moveForward >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.blindness))
if (this.onGround && !flag1 && !flag2 && this.gm.moveForward >= f && !this.isSprinting() && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.BLINDNESS))
{
if (this.sprintToggleTimer <= 0 && !this.gm.sprint)
{
@ -2416,7 +2416,7 @@ public abstract class EntityNPC extends EntityLiving
}
}
if (!this.isSprinting() && this.gm.moveForward >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.blindness) && this.gm.sprint)
if (!this.isSprinting() && this.gm.moveForward >= f && canSprint && !this.isUsingItem() && !this.hasEffect(Potion.BLINDNESS) && this.gm.sprint)
{
this.setSprinting(true);
}
@ -2426,7 +2426,7 @@ public abstract class EntityNPC extends EntityLiving
this.setSprinting(false);
}
if (this.hasEffect(Potion.flying) || this.noclip)
if (this.hasEffect(Potion.FLYING) || this.noclip)
{
if (this.noclip)
{
@ -3037,7 +3037,7 @@ public abstract class EntityNPC extends EntityLiving
protected void onFinishedEffect(PotionEffect effect) {
super.onFinishedEffect(effect);
if(this.isPlayer() && effect.getPotionID() == Potion.flying.id)
if(this.isPlayer() && effect.getPotion() == Potion.FLYING)
this.flying = false;
// super.onFinishedEffect(effect);
if(this.connection != null)
@ -3380,19 +3380,19 @@ public abstract class EntityNPC extends EntityLiving
}
}
if (this.hasEffect(Potion.digSpeed))
if (this.hasEffect(Potion.HASTE))
{
int speed = this.getEffect(Potion.digSpeed).getAmplifier();
int speed = this.getEffect(Potion.HASTE).getAmplifier();
if(speed >= 255)
return 1000000.0f;
f *= 1.0F + (float)(speed + 1) * 0.2F;
}
if (this.hasEffect(Potion.digSlowdown))
if (this.hasEffect(Potion.FATIGUE))
{
float f1 = 1.0F;
switch (this.getEffect(Potion.digSlowdown).getAmplifier())
switch (this.getEffect(Potion.FATIGUE).getAmplifier())
{
case 0:
f1 = 0.3F;
@ -3527,7 +3527,7 @@ public abstract class EntityNPC extends EntityLiving
// this.foodStats.readNBT(tagCompund);
// this.readCapabilitiesFromNBT(tagCompund);
this.flying = tagCompund.getBoolean("flying") && this.hasEffect(Potion.flying);
this.flying = tagCompund.getBoolean("flying") && this.hasEffect(Potion.FLYING);
// if(tagCompund.hasKey("speed", 99))
// this.speed = tagCompund.getFloat("speed");
// this.disableDamagePersist = tagCompund.getBoolean("alwaysInvulnerable");
@ -3803,7 +3803,7 @@ public abstract class EntityNPC extends EntityLiving
if (f > 0 || f1 > 0)
{
boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInLiquid() && !this.hasEffect(Potion.blindness) && this.vehicle == null && targetEntity instanceof EntityLiving;
boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInLiquid() && !this.hasEffect(Potion.BLINDNESS) && this.vehicle == null && targetEntity instanceof EntityLiving;
if (flag && f > 0)
{
@ -4118,7 +4118,7 @@ public abstract class EntityNPC extends EntityLiving
this.addStat((int)Math.round((double)distance * 100.0D));
}
if(!this.hasEffect(Potion.flying))
if(!this.hasEffect(Potion.FLYING))
super.fall(distance, damageMultiplier);
}
}

View file

@ -108,7 +108,7 @@ public class EntityBox extends EntityProjectile
//
// if (i > 0)
// {
((EntityLiving)movingObject.entity).addEffect(new PotionEffect(Potion.moveSlowdown.id, 20 * this.rand.range(35, 55), this.rand.chance(1, 2, 5)));
((EntityLiving)movingObject.entity).addEffect(new PotionEffect(Potion.SLOWNESS, 20 * this.rand.range(35, 55), this.rand.chance(1, 2, 5)));
// }
}
}

View file

@ -124,11 +124,13 @@ public class EntityPotion extends EntityThrowable implements IObjectData
for (PotionEffect potioneffect : list)
{
int i = potioneffect.getPotionID();
Potion i = potioneffect.getPotion();
if(!entitylivingbase.isPotionApplicable(i))
continue;
if (Potion.POTION_TYPES[i].isInstant())
if (i.isInstant())
{
Potion.POTION_TYPES[i].affectEntity(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1);
i.onImpact(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1);
}
else
{

View file

@ -75,7 +75,7 @@ public abstract class EntityLiving extends Entity
private AttributeMap attributes;
private final List<CombatEntry> combat = Lists.<CombatEntry>newArrayList();
private final Map<Integer, PotionEffect> effects = Maps.<Integer, PotionEffect>newHashMap();
private final Map<Potion, PotionEffect> effects = Maps.<Potion, PotionEffect>newEnumMap(Potion.class);
public int soundTimer;
protected int xpValue;
private EntityLookHelper lookHelper;
@ -373,7 +373,7 @@ public abstract class EntityLiving extends Entity
// if(this.isPlayer())
// Log.SERVER.info("rad:" + radiation);
if(radiation >= 0.0f) {
this.addEffect(new PotionEffect(Potion.radiation.id, ExtMath.clampi((int)(radiation * 5.0f), 10, 32766),
this.addEffect(new PotionEffect(Potion.RADIATION, ExtMath.clampi((int)(radiation * 5.0f), 10, 32766),
ExtMath.clampi((int)(radiation / 20.0f), 0, 255)));
}
}
@ -565,7 +565,7 @@ public abstract class EntityLiving extends Entity
for (PotionEffect potioneffect : this.effects.values())
{
nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
nbttaglist.appendTag(potioneffect.toNbt());
}
tagCompound.setTag("ActiveEffects", nbttaglist);
@ -615,11 +615,11 @@ public abstract class EntityLiving extends Entity
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
PotionEffect potioneffect = PotionEffect.fromNbt(nbttagcompound);
if (potioneffect != null)
if (potioneffect != null && !potioneffect.getPotion().isInstant())
{
this.effects.put(Integer.valueOf(potioneffect.getPotionID()), potioneffect);
this.effects.put(potioneffect.getPotion(), potioneffect);
}
}
}
@ -665,12 +665,12 @@ public abstract class EntityLiving extends Entity
protected void updateEffects()
{
Iterator<Integer> iterator = this.effects.keySet().iterator();
Iterator<Potion> iterator = this.effects.keySet().iterator();
while (iterator.hasNext())
{
Integer integer = (Integer)iterator.next();
PotionEffect potioneffect = (PotionEffect)this.effects.get(integer);
Potion potion = iterator.next();
PotionEffect potioneffect = this.effects.get(potion);
if (!potioneffect.onUpdate(this))
{
@ -680,7 +680,7 @@ public abstract class EntityLiving extends Entity
this.onFinishedEffect(potioneffect);
}
}
else if (potioneffect.getDuration() % 600 == 0)
else if (potioneffect.getRemaining() % 600 == 0)
{
this.onChangedEffect(potioneffect, false);
}
@ -758,14 +758,14 @@ public abstract class EntityLiving extends Entity
public void clearEffects(boolean negative)
{
Iterator<Integer> iterator = this.effects.keySet().iterator();
Iterator<Potion> iterator = this.effects.keySet().iterator();
while (iterator.hasNext())
{
Integer integer = (Integer)iterator.next();
PotionEffect potioneffect = (PotionEffect)this.effects.get(integer);
Potion potion = iterator.next();
PotionEffect potioneffect = this.effects.get(potion);
if (!this.worldObj.client && (!negative || Potion.POTION_TYPES[potioneffect.getPotionID()].isBadEffect()))
if (!this.worldObj.client && (!negative || potioneffect.getPotion().isBadEffect()))
{
iterator.remove();
this.onFinishedEffect(potioneffect);
@ -778,14 +778,14 @@ public abstract class EntityLiving extends Entity
return this.effects.values();
}
public boolean hasEffect(int potionId)
{
return this.effects.containsKey(Integer.valueOf(potionId));
}
// public boolean hasEffect(int potionId)
// {
// return this.effects.containsKey(Integer.valueOf(potionId));
// }
public boolean hasEffect(Potion potionIn)
{
return this.effects.containsKey(Integer.valueOf(potionIn.id));
return this.effects.containsKey(potionIn);
}
/**
@ -793,7 +793,7 @@ public abstract class EntityLiving extends Entity
*/
public PotionEffect getEffect(Potion potionIn)
{
return (PotionEffect)this.effects.get(Integer.valueOf(potionIn.id));
return this.effects.get(potionIn);
}
/**
@ -801,22 +801,22 @@ public abstract class EntityLiving extends Entity
*/
public void addEffect(PotionEffect potioneffectIn)
{
if (this.isPotionApplicable(potioneffectIn))
if (!potioneffectIn.getPotion().isInstant() && this.isPotionApplicable(potioneffectIn.getPotion()))
{
if (this.effects.containsKey(Integer.valueOf(potioneffectIn.getPotionID())))
if (this.effects.containsKey(potioneffectIn.getPotion()))
{
((PotionEffect)this.effects.get(Integer.valueOf(potioneffectIn.getPotionID()))).combine(potioneffectIn);
this.onChangedEffect((PotionEffect)this.effects.get(Integer.valueOf(potioneffectIn.getPotionID())), true);
this.effects.put(potioneffectIn.getPotion(), this.effects.get(potioneffectIn.getPotion()).combine(potioneffectIn));
this.onChangedEffect(this.effects.get(potioneffectIn.getPotion()), true);
}
else
{
this.effects.put(Integer.valueOf(potioneffectIn.getPotionID()), potioneffectIn);
this.effects.put(potioneffectIn.getPotion(), potioneffectIn);
this.onNewEffect(potioneffectIn);
}
}
}
public boolean isPotionApplicable(PotionEffect potioneffectIn)
public boolean isPotionApplicable(Potion potion)
{
// if (this.getCreatureType() == CreatureType.UNDEAD)
// {
@ -839,17 +839,17 @@ public abstract class EntityLiving extends Entity
/**
* Remove the speified potion effect from this entity.
*/
public void removeEffectClient(int potionId)
public void removeEffectClient(Potion potionId)
{
this.effects.remove(Integer.valueOf(potionId));
this.effects.remove(potionId);
}
/**
* Remove the specified potion effect from this entity.
*/
public void removeEffect(int potionId)
public void removeEffect(Potion potion)
{
PotionEffect potioneffect = (PotionEffect)this.effects.remove(Integer.valueOf(potionId));
PotionEffect potioneffect = this.effects.remove(potion);
if (potioneffect != null)
{
@ -863,7 +863,7 @@ public abstract class EntityLiving extends Entity
if (!this.worldObj.client)
{
Potion.POTION_TYPES[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier());
id.getPotion().addModifiers(this, this.getAttributeMap(), id.getAmplifier());
}
}
@ -873,8 +873,8 @@ public abstract class EntityLiving extends Entity
if (added && !this.worldObj.client)
{
Potion.POTION_TYPES[id.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), id.getAmplifier());
Potion.POTION_TYPES[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier());
id.getPotion().removeModifiers(this, this.getAttributeMap(), id.getAmplifier());
id.getPotion().addModifiers(this, this.getAttributeMap(), id.getAmplifier());
}
}
@ -884,7 +884,7 @@ public abstract class EntityLiving extends Entity
if (!this.worldObj.client)
{
Potion.POTION_TYPES[effect.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), effect.getAmplifier());
effect.getPotion().removeModifiers(this, this.getAttributeMap(), effect.getAmplifier());
}
}
@ -917,7 +917,7 @@ public abstract class EntityLiving extends Entity
}
public boolean isImmuneToFire() {
return this.hasEffect(Potion.fireResistance);
return this.hasEffect(Potion.FIRE_RESISTANCE);
}
/**
@ -1217,7 +1217,7 @@ public abstract class EntityLiving extends Entity
{
damageMultiplier = Math.max(0.0f, damageMultiplier - (1.65f - (float)this.worldObj.gravity * 1.65f));
super.fall(distance, damageMultiplier);
PotionEffect potioneffect = this.getEffect(Potion.jump);
PotionEffect potioneffect = this.getEffect(Potion.JUMP);
float f = potioneffect != null ? (float)(potioneffect.getAmplifier() + 1) : 0.0F;
int i = ExtMath.ceilf((distance - 3.0F - f) * damageMultiplier);
@ -1303,9 +1303,9 @@ public abstract class EntityLiving extends Entity
*/
protected int applyPotionDamageCalculations(DamageSource source, int damage)
{
if (this.hasEffect(Potion.resistance) && source != DamageSource.outOfWorld)
if (this.hasEffect(Potion.RESISTANCE) && source != DamageSource.outOfWorld)
{
int i = (this.getEffect(Potion.resistance).getAmplifier() + 1) * 5;
int i = (this.getEffect(Potion.RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f = (float)damage * (float)j;
damage = (int)(f / 25.0F);
@ -1638,9 +1638,9 @@ public abstract class EntityLiving extends Entity
{
this.motionY = (double)this.getJumpUpwardsMotion();
if (this.hasEffect(Potion.jump))
if (this.hasEffect(Potion.JUMP))
{
this.motionY += (double)((float)(this.getEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
this.motionY += (double)((float)(this.getEffect(Potion.JUMP).getAmplifier() + 1) * 0.1F);
}
if (this.isSprinting())