2020-05-06 17:48:49 +08:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-20 12:35:02 +08:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 27 Sep 2015 01:18:02 -0400
|
|
|
|
Subject: [PATCH] handle NaN health/absorb values and repair bad data
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
2020-09-11 07:47:58 +08:00
|
|
|
index a69eadd57a2ccb30eaa5f997feebf0cbb2300065..e9a67693f36345da1ef657a584f996928979188d 100644
|
2016-03-20 12:35:02 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2020-09-02 17:12:25 +08:00
|
|
|
@@ -603,7 +603,13 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 12:35:02 +08:00
|
|
|
|
2019-04-26 09:24:00 +08:00
|
|
|
@Override
|
2020-06-25 19:00:35 +08:00
|
|
|
public void loadData(NBTTagCompound nbttagcompound) {
|
2016-03-20 12:35:02 +08:00
|
|
|
- this.setAbsorptionHearts(nbttagcompound.getFloat("AbsorptionAmount"));
|
|
|
|
+ // Paper start - jvm keeps optimizing the setter
|
|
|
|
+ float absorptionAmount = nbttagcompound.getFloat("AbsorptionAmount");
|
|
|
|
+ if (Float.isNaN(absorptionAmount)) {
|
|
|
|
+ absorptionAmount = 0;
|
|
|
|
+ }
|
|
|
|
+ this.setAbsorptionHearts(absorptionAmount);
|
|
|
|
+ // Paper end
|
|
|
|
if (nbttagcompound.hasKeyOfType("Attributes", 9) && this.world != null && !this.world.isClientSide) {
|
2020-06-25 19:00:35 +08:00
|
|
|
this.getAttributeMap().a(nbttagcompound.getList("Attributes", 10));
|
2016-03-20 12:35:02 +08:00
|
|
|
}
|
2020-09-02 17:12:25 +08:00
|
|
|
@@ -1052,6 +1058,10 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 12:35:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setHealth(float f) {
|
|
|
|
+ // Paper start
|
|
|
|
+ if (Float.isNaN(f)) { f = getMaxHealth(); if (this.valid) {
|
|
|
|
+ System.err.println("[NAN-HEALTH] " + getName() + " had NaN health set");
|
|
|
|
+ } } // Paper end
|
|
|
|
// CraftBukkit start - Handle scaled health
|
|
|
|
if (this instanceof EntityPlayer) {
|
|
|
|
org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity();
|
2020-09-11 07:47:58 +08:00
|
|
|
@@ -2933,7 +2943,7 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 12:35:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAbsorptionHearts(float f) {
|
|
|
|
- if (f < 0.0F) {
|
|
|
|
+ if (f < 0.0F || Float.isNaN(f)) { // Paper
|
|
|
|
f = 0.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2020-08-25 10:22:08 +08:00
|
|
|
index 4140fef9aeb3a67c8a0e543c54b3df66ba50eb0b..90f04e16956e18f48a45d45f09d4f37eabc65478 100644
|
2016-03-20 12:35:02 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2020-08-25 10:22:08 +08:00
|
|
|
@@ -1607,6 +1607,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-03-20 12:35:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setRealHealth(double health) {
|
|
|
|
+ if (Double.isNaN(health)) {return;} // Paper
|
|
|
|
this.health = health;
|
|
|
|
}
|
|
|
|
|