Paper/Spigot-Server-Patches/0067-handle-NaN-health-absorb-values-and-repair-bad-data.patch

58 lines
2.6 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
index 9c9af548fe32ab1dd3eecdb4fe4aacf255b39e22..8cb1537114c4aa3d6835e46e9e70de2fa67fac6a 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2020-06-25 13:00:35 +02:00
@@ -602,7 +602,13 @@ public abstract class EntityLiving extends Entity {
2019-04-26 03:24:00 +02:00
@Override
2020-06-25 13:00:35 +02:00
public void loadData(NBTTagCompound nbttagcompound) {
- 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 13:00:35 +02:00
this.getAttributeMap().a(nbttagcompound.getList("Attributes", 10));
}
2020-06-25 13:00:35 +02:00
@@ -1051,6 +1057,10 @@ public abstract class EntityLiving extends Entity {
}
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();
@@ -2909,7 +2919,7 @@ public abstract class EntityLiving extends Entity {
}
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
index 34a3e269c59d1797c764a2dc6c5ba9e646792084..2e8105fe1d0f5f953ac8ba94df3e8eb66b7813d7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1611,6 +1611,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}