3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 04:20:08 +01:00

Rework max health values. Fixes BUKKIT-4398

Dieser Commit ist enthalten in:
Wesley Wolfe 2013-07-02 12:34:40 -05:00
Ursprung e79d26d7d7
Commit 22adf8a3ce
12 geänderte Dateien mit 21 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -1149,10 +1149,6 @@ public abstract class Entity {
// CraftBukkit start
if (this instanceof EntityLiving) {
EntityLiving entity = (EntityLiving) this;
// If the entity does not have a max health set yet, update it (it may have changed after loading the entity)
if (!nbttagcompound.hasKey("Bukkit.MaxHealth")) {
entity.maxHealth = entity.getMaxHealth();
}
// Reset the persistence for tamed animals
if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) {

Datei anzeigen

@ -304,7 +304,7 @@ public class EntityEnderDragon extends EntityInsentient implements IComplex, IMo
}
this.bC = null;
} else if (this.ticksLived % 10 == 0 && this.getHealth() < this.maxHealth) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth
} else if (this.ticksLived % 10 == 0 && this.getHealth() < this.getMaxHealth()) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth
// CraftBukkit start
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0D, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
this.world.getServer().getPluginManager().callEvent(event);

Datei anzeigen

@ -351,8 +351,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
--this.br;
}
// CraftBukkit - this.getMaxHealth() -> this.maxHealth
if (this.world.difficulty == 0 && this.getHealth() < this.maxHealth && this.world.getGameRules().getBoolean("naturalRegeneration") && this.ticksLived % 20 * 12 == 0) {
if (this.world.difficulty == 0 && this.getHealth() < this.getMaxHealth() && this.world.getGameRules().getBoolean("naturalRegeneration") && this.ticksLived % 20 * 12 == 0) {
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
}
@ -1402,7 +1401,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
}
public boolean bE() {
return this.getHealth() > 0.0F && this.getHealth() < this.maxHealth; // CraftBukkit - this.getMaxHealth() -> this.maxHealth
return this.getHealth() > 0.0F && this.getHealth() < this.getMaxHealth();
}
public void a(ItemStack itemstack, int i) {

Datei anzeigen

@ -6,10 +6,6 @@ import java.util.UUID;
//CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
//CraftBukkit end
public abstract class EntityInsentient extends EntityLiving {
@ -529,7 +525,7 @@ public abstract class EntityInsentient extends EntityLiving {
if (this.getGoalTarget() == null) {
return 3;
} else {
int i = (int) (this.getHealth() - this.maxHealth * 0.33F); // CraftBukkit - this.getMaxHealth() -> this.maxHealth
int i = (int) (this.getHealth() - this.getMaxHealth() * 0.33F);
i -= (3 - this.world.difficulty) * 4;
if (i < 0) {

Datei anzeigen

@ -9,7 +9,6 @@ import java.util.UUID;
// CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
// CraftBukkit end
@ -77,7 +76,6 @@ public abstract class EntityLiving extends Entity {
// CraftBukkit start
public int expToDrop;
public int maxAirTicks = 300;
public float maxHealth;
// CraftBukkit end
public EntityLiving(World world) {
@ -91,7 +89,6 @@ public abstract class EntityLiving extends Entity {
this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
this.aP = this.yaw;
this.Y = 0.5F;
maxHealth = this.getMaxHealth(); // CraftBukkit - We can't initialize maxHealth until this.ax() has been invoked.
}
protected void a() {
@ -241,14 +238,6 @@ public abstract class EntityLiving extends Entity {
return 0;
}
}
public float getScaledHealth() {
if (this.maxHealth != this.getMaxHealth() && this.getHealth() > 0) {
return this.getHealth() * this.getMaxHealth() / this.maxHealth + 1;
} else {
return this.getHealth();
}
}
// CraftBukkit end
public boolean isBaby() {
@ -327,7 +316,6 @@ public abstract class EntityLiving extends Entity {
public void b(NBTTagCompound nbttagcompound) {
nbttagcompound.setFloat("HealF", this.getHealth());
nbttagcompound.setShort("Health", (short) ((int) Math.ceil((double) this.getHealth())));
nbttagcompound.setFloat("Bukkit.MaxHealth", this.maxHealth); // CraftBukkit
nbttagcompound.setShort("HurtTime", (short) this.hurtTicks);
nbttagcompound.setShort("DeathTime", (short) this.deathTicks);
nbttagcompound.setShort("AttackTime", (short) this.attackTicks);
@ -391,9 +379,9 @@ public abstract class EntityLiving extends Entity {
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
if (nbtbase.getTypeId() == 5) {
this.maxHealth = ((NBTTagFloat) nbtbase).data;
this.a(GenericAttributes.a).a((double) ((NBTTagFloat) nbtbase).data);
} else if (nbtbase.getTypeId() == 3) {
this.maxHealth = (float) ((NBTTagInt) nbtbase).data;
this.a(GenericAttributes.a).a((double) ((NBTTagInt) nbtbase).data);
}
}
// CraftBukkit end
@ -404,7 +392,7 @@ public abstract class EntityLiving extends Entity {
NBTBase nbtbase = nbttagcompound.get("Health");
if (nbtbase == null) {
this.setHealth(this.maxHealth); // CraftBukkit - this.getMaxHealth() -> this.maxHealth
this.setHealth(this.getMaxHealth());
} else if (nbtbase.getTypeId() == 5) {
this.setHealth(((NBTTagFloat) nbtbase).data);
} else if (nbtbase.getTypeId() == 2) {
@ -587,12 +575,6 @@ public abstract class EntityLiving extends Entity {
if (!event.isCancelled()) {
this.setHealth((float) (this.getHealth() + event.getAmount()));
}
// TODO should we be doing this anymore
if (this.getHealth() > this.maxHealth) {
this.setHealth(this.maxHealth);
}
// CraftBukkit end
}
}

Datei anzeigen

@ -4,7 +4,6 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
@ -234,8 +233,8 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
if (this.getHealth() != this.bP || this.bQ != this.foodData.a() || this.foodData.e() == 0.0F != this.bR) {
// CraftBukkit - this.getHealth() -> this.getScaledHealth()
this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e()));
// CraftBukkit - this.getHealth() -> this.getScaledHealth() - Magic number 20 -> original max health
this.playerConnection.sendPacket(new Packet8UpdateHealth((float) (this.getHealth() * this.getMaxHealth() / 20.0D), this.foodData.a(), this.foodData.e()));
this.bP = this.getHealth();
this.bQ = this.foodData.a();
this.bR = this.foodData.e() == 0.0F;
@ -907,7 +906,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
this.newLevel = this.expLevel;
}
this.setHealth(this.maxHealth);
this.setHealth(this.getMaxHealth());
this.fireTicks = 0;
this.fallDistance = 0;
this.foodData = new FoodMetaData();

Datei anzeigen

@ -31,17 +31,11 @@ public class EntitySlime extends EntityInsentient implements IMonster {
// CraftBukkit - protected -> public
public void setSize(int i) {
boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit
this.datawatcher.watch(16, new Byte((byte) i));
this.a(0.6F * (float) i, 0.6F * (float) i);
this.setPosition(this.locX, this.locY, this.locZ);
this.a(GenericAttributes.a).a((double) (i * i));
// CraftBukkit start
if (updateMaxHealth) {
this.maxHealth = this.getMaxHealth();
}
this.setHealth(this.maxHealth);
// CraftBukkit end
this.setHealth(this.getMaxHealth());
this.b = i;
}

Datei anzeigen

@ -86,7 +86,7 @@ public class EntityWitch extends EntityMonster implements IRangedEntity {
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
short1 = 16307;
} else if (this.random.nextFloat() < 0.05F && this.getHealth() < this.maxHealth) { // CraftBukkit - this.getMaxHealth() -> this.maxHealth
} else if (this.random.nextFloat() < 0.05F && this.getHealth() < this.getMaxHealth()) {
short1 = 16341;
} else if (this.random.nextFloat() < 0.25F && this.getGoalTarget() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.getGoalTarget().e(this) > 121.0D) {
short1 = 16274;

Datei anzeigen

@ -446,7 +446,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
}
public boolean bR() {
return this.getHealth() <= this.maxHealth / 2.0F; // CraftBukkit - this.getMaxHealth() -> this.maxHealth
return this.getHealth() <= this.getMaxHealth() / 2.0F;
}
public EnumMonsterType getMonsterType() {

Datei anzeigen

@ -71,7 +71,7 @@ public class EntityWolf extends EntityTameableAnimal {
}
protected void bg() {
this.datawatcher.watch(18, Float.valueOf(this.getScaledHealth())); // CraftBukkit - this.getHealth() -> this.getScaledHealth()
this.datawatcher.watch(18, Float.valueOf(this.getHealth()));
}
protected void a() {
@ -100,8 +100,8 @@ public class EntityWolf extends EntityTameableAnimal {
}
protected String r() {
// CraftBukkit - getInt(18) < 10 -> < this.maxHealth / 2
return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getFloat(18) < this.maxHealth / 2 ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
// CraftBukkit - (getInt(18) < 10) -> (getInt(18) < this.getMaxHealth() / 2)
return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getFloat(18) < (this.getMaxHealth() / 2) ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
}
protected String aK() {
@ -265,17 +265,11 @@ public class EntityWolf extends EntityTameableAnimal {
if (!this.world.isStatic) {
// CraftBukkit - added event call and isCancelled check.
if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit
this.setTamed(true);
this.setPathEntity((PathEntity) null);
this.setGoalTarget((EntityLiving) null);
this.bp.setSitting(true);
// CraftBukkit start
if (updateMaxHealth) {
this.maxHealth = this.getMaxHealth();
}
this.setHealth(this.maxHealth);
// CraftBukkit end
this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
this.setOwnerName(entityhuman.getName());
this.j(true);
this.world.broadcastEntityEffect(this, (byte) 7);

Datei anzeigen

@ -81,7 +81,7 @@ public class MobEffectList {
public void tick(EntityLiving entityliving, int i) {
if (this.id == REGENERATION.id) {
if (entityliving.getHealth() < entityliving.maxHealth) { // CraftBukkit - .getMaxHealth() -> .maxHealth
if (entityliving.getHealth() < entityliving.getMaxHealth()) {
entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
}
} else if (this.id == POISON.id) {

Datei anzeigen

@ -19,6 +19,7 @@ import net.minecraft.server.EntitySnowball;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EntityPotion;
import net.minecraft.server.EntityWitherSkull;
import net.minecraft.server.GenericAttributes;
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.Packet42RemoveMobEffect;
@ -83,13 +84,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
}
public double getMaxHealth() {
return getHandle().maxHealth;
return getHandle().getMaxHealth();
}
public void setMaxHealth(double amount) {
Validate.isTrue(amount > 0, "Max health must be greater than 0");
getHandle().maxHealth = (float) amount;
getHandle().a(GenericAttributes.a).a(amount);
if (getHealth() > amount) {
setHealth(amount);