2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-20 04:35:02 +00: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
|
|
|
|
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
index 9b12e15a6c377ae90193596a35114dd452cf6e0c..acbd10432b09172f7541b2f4081d1aa9812194ac 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
@@ -702,7 +702,13 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 04:35:02 +00:00
|
|
|
|
2019-04-26 01:24:00 +00:00
|
|
|
@Override
|
2020-06-25 11:00:35 +00:00
|
|
|
public void loadData(NBTTagCompound nbttagcompound) {
|
2016-03-20 04:35:02 +00: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 11:00:35 +00:00
|
|
|
this.getAttributeMap().a(nbttagcompound.getList("Attributes", 10));
|
2016-03-20 04:35:02 +00:00
|
|
|
}
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1151,6 +1157,10 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 04:35:02 +00: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();
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3045,7 +3055,7 @@ public abstract class EntityLiving extends Entity {
|
2016-03-20 04:35:02 +00: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
|
2021-03-16 07:19:45 +00:00
|
|
|
index 144faef77e69c6c3bf963327179a51bb4c37cc18..b4a2758ee246252d6076e861b45d11dae6e33096 100644
|
2016-03-20 04:35:02 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2021-03-03 22:43:45 +00:00
|
|
|
@@ -1682,6 +1682,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-03-20 04:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setRealHealth(double health) {
|
|
|
|
+ if (Double.isNaN(health)) {return;} // Paper
|
|
|
|
this.health = health;
|
|
|
|
}
|
|
|
|
|