Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
Rework max health values. Fixes BUKKIT-4398
Dieser Commit ist enthalten in:
Ursprung
e79d26d7d7
Commit
22adf8a3ce
@ -1149,10 +1149,6 @@ public abstract class Entity {
|
|||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
if (this instanceof EntityLiving) {
|
if (this instanceof EntityLiving) {
|
||||||
EntityLiving entity = (EntityLiving) this;
|
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
|
// Reset the persistence for tamed animals
|
||||||
if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) {
|
if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) {
|
||||||
|
@ -304,7 +304,7 @@ public class EntityEnderDragon extends EntityInsentient implements IComplex, IMo
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.bC = null;
|
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
|
// CraftBukkit start
|
||||||
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0D, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
|
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0D, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL);
|
||||||
this.world.getServer().getPluginManager().callEvent(event);
|
this.world.getServer().getPluginManager().callEvent(event);
|
||||||
|
@ -351,8 +351,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
|
|||||||
--this.br;
|
--this.br;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
if (this.world.difficulty == 0 && this.getHealth() < this.getMaxHealth() && this.world.getGameRules().getBoolean("naturalRegeneration") && this.ticksLived % 20 * 12 == 0) {
|
||||||
if (this.world.difficulty == 0 && this.getHealth() < this.maxHealth && this.world.getGameRules().getBoolean("naturalRegeneration") && this.ticksLived % 20 * 12 == 0) {
|
|
||||||
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
|
// CraftBukkit - added regain reason of "REGEN" for filtering purposes.
|
||||||
this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
|
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() {
|
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) {
|
public void a(ItemStack itemstack, int i) {
|
||||||
|
@ -6,10 +6,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
//CraftBukkit start
|
//CraftBukkit start
|
||||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
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 {
|
public abstract class EntityInsentient extends EntityLiving {
|
||||||
|
|
||||||
@ -529,7 +525,7 @@ public abstract class EntityInsentient extends EntityLiving {
|
|||||||
if (this.getGoalTarget() == null) {
|
if (this.getGoalTarget() == null) {
|
||||||
return 3;
|
return 3;
|
||||||
} else {
|
} 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;
|
i -= (3 - this.world.difficulty) * 4;
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
|
@ -9,7 +9,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@ -77,7 +76,6 @@ public abstract class EntityLiving extends Entity {
|
|||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public int expToDrop;
|
public int expToDrop;
|
||||||
public int maxAirTicks = 300;
|
public int maxAirTicks = 300;
|
||||||
public float maxHealth;
|
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public EntityLiving(World world) {
|
public EntityLiving(World world) {
|
||||||
@ -91,7 +89,6 @@ public abstract class EntityLiving extends Entity {
|
|||||||
this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
|
this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
|
||||||
this.aP = this.yaw;
|
this.aP = this.yaw;
|
||||||
this.Y = 0.5F;
|
this.Y = 0.5F;
|
||||||
maxHealth = this.getMaxHealth(); // CraftBukkit - We can't initialize maxHealth until this.ax() has been invoked.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void a() {
|
protected void a() {
|
||||||
@ -241,14 +238,6 @@ public abstract class EntityLiving extends Entity {
|
|||||||
return 0;
|
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
|
// CraftBukkit end
|
||||||
|
|
||||||
public boolean isBaby() {
|
public boolean isBaby() {
|
||||||
@ -327,7 +316,6 @@ public abstract class EntityLiving extends Entity {
|
|||||||
public void b(NBTTagCompound nbttagcompound) {
|
public void b(NBTTagCompound nbttagcompound) {
|
||||||
nbttagcompound.setFloat("HealF", this.getHealth());
|
nbttagcompound.setFloat("HealF", this.getHealth());
|
||||||
nbttagcompound.setShort("Health", (short) ((int) Math.ceil((double) 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("HurtTime", (short) this.hurtTicks);
|
||||||
nbttagcompound.setShort("DeathTime", (short) this.deathTicks);
|
nbttagcompound.setShort("DeathTime", (short) this.deathTicks);
|
||||||
nbttagcompound.setShort("AttackTime", (short) this.attackTicks);
|
nbttagcompound.setShort("AttackTime", (short) this.attackTicks);
|
||||||
@ -391,9 +379,9 @@ public abstract class EntityLiving extends Entity {
|
|||||||
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
|
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
|
||||||
NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
|
NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
|
||||||
if (nbtbase.getTypeId() == 5) {
|
if (nbtbase.getTypeId() == 5) {
|
||||||
this.maxHealth = ((NBTTagFloat) nbtbase).data;
|
this.a(GenericAttributes.a).a((double) ((NBTTagFloat) nbtbase).data);
|
||||||
} else if (nbtbase.getTypeId() == 3) {
|
} else if (nbtbase.getTypeId() == 3) {
|
||||||
this.maxHealth = (float) ((NBTTagInt) nbtbase).data;
|
this.a(GenericAttributes.a).a((double) ((NBTTagInt) nbtbase).data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@ -404,7 +392,7 @@ public abstract class EntityLiving extends Entity {
|
|||||||
NBTBase nbtbase = nbttagcompound.get("Health");
|
NBTBase nbtbase = nbttagcompound.get("Health");
|
||||||
|
|
||||||
if (nbtbase == null) {
|
if (nbtbase == null) {
|
||||||
this.setHealth(this.maxHealth); // CraftBukkit - this.getMaxHealth() -> this.maxHealth
|
this.setHealth(this.getMaxHealth());
|
||||||
} else if (nbtbase.getTypeId() == 5) {
|
} else if (nbtbase.getTypeId() == 5) {
|
||||||
this.setHealth(((NBTTagFloat) nbtbase).data);
|
this.setHealth(((NBTTagFloat) nbtbase).data);
|
||||||
} else if (nbtbase.getTypeId() == 2) {
|
} else if (nbtbase.getTypeId() == 2) {
|
||||||
@ -587,12 +575,6 @@ public abstract class EntityLiving extends Entity {
|
|||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
this.setHealth((float) (this.getHealth() + event.getAmount()));
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
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) {
|
if (this.getHealth() != this.bP || this.bQ != this.foodData.a() || this.foodData.e() == 0.0F != this.bR) {
|
||||||
// CraftBukkit - this.getHealth() -> this.getScaledHealth()
|
// CraftBukkit - this.getHealth() -> this.getScaledHealth() - Magic number 20 -> original max health
|
||||||
this.playerConnection.sendPacket(new Packet8UpdateHealth(this.getScaledHealth(), this.foodData.a(), this.foodData.e()));
|
this.playerConnection.sendPacket(new Packet8UpdateHealth((float) (this.getHealth() * this.getMaxHealth() / 20.0D), this.foodData.a(), this.foodData.e()));
|
||||||
this.bP = this.getHealth();
|
this.bP = this.getHealth();
|
||||||
this.bQ = this.foodData.a();
|
this.bQ = this.foodData.a();
|
||||||
this.bR = this.foodData.e() == 0.0F;
|
this.bR = this.foodData.e() == 0.0F;
|
||||||
@ -907,7 +906,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|||||||
this.newLevel = this.expLevel;
|
this.newLevel = this.expLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setHealth(this.maxHealth);
|
this.setHealth(this.getMaxHealth());
|
||||||
this.fireTicks = 0;
|
this.fireTicks = 0;
|
||||||
this.fallDistance = 0;
|
this.fallDistance = 0;
|
||||||
this.foodData = new FoodMetaData();
|
this.foodData = new FoodMetaData();
|
||||||
|
@ -31,17 +31,11 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
|||||||
|
|
||||||
// CraftBukkit - protected -> public
|
// CraftBukkit - protected -> public
|
||||||
public void setSize(int i) {
|
public void setSize(int i) {
|
||||||
boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit
|
|
||||||
this.datawatcher.watch(16, new Byte((byte) i));
|
this.datawatcher.watch(16, new Byte((byte) i));
|
||||||
this.a(0.6F * (float) i, 0.6F * (float) i);
|
this.a(0.6F * (float) i, 0.6F * (float) i);
|
||||||
this.setPosition(this.locX, this.locY, this.locZ);
|
this.setPosition(this.locX, this.locY, this.locZ);
|
||||||
this.a(GenericAttributes.a).a((double) (i * i));
|
this.a(GenericAttributes.a).a((double) (i * i));
|
||||||
// CraftBukkit start
|
this.setHealth(this.getMaxHealth());
|
||||||
if (updateMaxHealth) {
|
|
||||||
this.maxHealth = this.getMaxHealth();
|
|
||||||
}
|
|
||||||
this.setHealth(this.maxHealth);
|
|
||||||
// CraftBukkit end
|
|
||||||
this.b = i;
|
this.b = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public class EntityWitch extends EntityMonster implements IRangedEntity {
|
|||||||
|
|
||||||
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
|
if (this.random.nextFloat() < 0.15F && this.isBurning() && !this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
|
||||||
short1 = 16307;
|
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;
|
short1 = 16341;
|
||||||
} else if (this.random.nextFloat() < 0.25F && this.getGoalTarget() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.getGoalTarget().e(this) > 121.0D) {
|
} else if (this.random.nextFloat() < 0.25F && this.getGoalTarget() != null && !this.hasEffect(MobEffectList.FASTER_MOVEMENT) && this.getGoalTarget().e(this) > 121.0D) {
|
||||||
short1 = 16274;
|
short1 = 16274;
|
||||||
|
@ -446,7 +446,7 @@ public class EntityWither extends EntityMonster implements IRangedEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean bR() {
|
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() {
|
public EnumMonsterType getMonsterType() {
|
||||||
|
@ -71,7 +71,7 @@ public class EntityWolf extends EntityTameableAnimal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void bg() {
|
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() {
|
protected void a() {
|
||||||
@ -100,8 +100,8 @@ public class EntityWolf extends EntityTameableAnimal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String r() {
|
protected String r() {
|
||||||
// CraftBukkit - getInt(18) < 10 -> < this.maxHealth / 2
|
// 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.maxHealth / 2 ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
|
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() {
|
protected String aK() {
|
||||||
@ -265,17 +265,11 @@ public class EntityWolf extends EntityTameableAnimal {
|
|||||||
if (!this.world.isStatic) {
|
if (!this.world.isStatic) {
|
||||||
// CraftBukkit - added event call and isCancelled check.
|
// CraftBukkit - added event call and isCancelled check.
|
||||||
if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
|
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.setTamed(true);
|
||||||
this.setPathEntity((PathEntity) null);
|
this.setPathEntity((PathEntity) null);
|
||||||
this.setGoalTarget((EntityLiving) null);
|
this.setGoalTarget((EntityLiving) null);
|
||||||
this.bp.setSitting(true);
|
this.bp.setSitting(true);
|
||||||
// CraftBukkit start
|
this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
|
||||||
if (updateMaxHealth) {
|
|
||||||
this.maxHealth = this.getMaxHealth();
|
|
||||||
}
|
|
||||||
this.setHealth(this.maxHealth);
|
|
||||||
// CraftBukkit end
|
|
||||||
this.setOwnerName(entityhuman.getName());
|
this.setOwnerName(entityhuman.getName());
|
||||||
this.j(true);
|
this.j(true);
|
||||||
this.world.broadcastEntityEffect(this, (byte) 7);
|
this.world.broadcastEntityEffect(this, (byte) 7);
|
||||||
|
@ -81,7 +81,7 @@ public class MobEffectList {
|
|||||||
|
|
||||||
public void tick(EntityLiving entityliving, int i) {
|
public void tick(EntityLiving entityliving, int i) {
|
||||||
if (this.id == REGENERATION.id) {
|
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
|
entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
|
||||||
}
|
}
|
||||||
} else if (this.id == POISON.id) {
|
} else if (this.id == POISON.id) {
|
||||||
|
@ -19,6 +19,7 @@ import net.minecraft.server.EntitySnowball;
|
|||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.EntityPotion;
|
import net.minecraft.server.EntityPotion;
|
||||||
import net.minecraft.server.EntityWitherSkull;
|
import net.minecraft.server.EntityWitherSkull;
|
||||||
|
import net.minecraft.server.GenericAttributes;
|
||||||
import net.minecraft.server.MobEffect;
|
import net.minecraft.server.MobEffect;
|
||||||
import net.minecraft.server.MobEffectList;
|
import net.minecraft.server.MobEffectList;
|
||||||
import net.minecraft.server.Packet42RemoveMobEffect;
|
import net.minecraft.server.Packet42RemoveMobEffect;
|
||||||
@ -83,13 +84,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getMaxHealth() {
|
public double getMaxHealth() {
|
||||||
return getHandle().maxHealth;
|
return getHandle().getMaxHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxHealth(double amount) {
|
public void setMaxHealth(double amount) {
|
||||||
Validate.isTrue(amount > 0, "Max health must be greater than 0");
|
Validate.isTrue(amount > 0, "Max health must be greater than 0");
|
||||||
|
|
||||||
getHandle().maxHealth = (float) amount;
|
getHandle().a(GenericAttributes.a).a(amount);
|
||||||
|
|
||||||
if (getHealth() > amount) {
|
if (getHealth() > amount) {
|
||||||
setHealth(amount);
|
setHealth(amount);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren