aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0091-handle-NaN-health-absorb-values-and-repair-bad-data.patch
blob: b5489ba6d6893e6269b7ad3eb342385ff5fac880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 80095f37e49793ab660d09206d3bf6155a6115c5 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 d11e01b..df4d8d8 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -465,7 +465,13 @@ public abstract class EntityLiving extends Entity {
     }
 
     public void a(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) {
             GenericAttributes.a(this.getAttributeMap(), nbttagcompound.getList("Attributes", 10));
         }
@@ -752,6 +758,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();
@@ -2102,7 +2112,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 c018773..2b555c9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1375,6 +1375,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
     }
 
     public void setRealHealth(double health) {
+        if (Double.isNaN(health)) {return;} // Paper
         this.health = health;
     }
 
-- 
2.8.2