Paper/Spigot-Server-Patches/0068-handle-NaN-health-absorb-values-and-repair-bad-data.patch
Josh Roy 4c9bdf53ac
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5299)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
9d0ad318 Fix javadoc errors in previous commits
9501daa2 #578: Add methods to modify the rate of regeneration and starvation
197d8f3d #577: Add EntityExhaustionEvent

CraftBukkit Changes:
a021e334 #795: Add methods to modify the rate of regeneration and starvation
509e523c #792: Add EntityExhaustionEvent

Spigot Changes:
db99f821 Rebuild patches
2021-03-03 14:43:45 -08:00

58 lines
2.6 KiB
Diff

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 7c74a13d875d12d4264e394c682ab515a14f8915..1fb7e29b29adef72bd5a49c87d954973f46f9c81 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -609,7 +609,13 @@ public abstract class EntityLiving extends Entity {
@Override
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) {
this.getAttributeMap().a(nbttagcompound.getList("Attributes", 10));
}
@@ -1058,6 +1064,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();
@@ -2952,7 +2962,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 15a515535d6c8c71e0de4a7ab4c0a8759ca3537f..0a24eab942354a03d5ddf4899cf7a80401b669a4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1682,6 +1682,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}