aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0073-handle-NaN-health-absorb-values-and-repair-bad-data.patch
blob: bc96345c4ae584cca7cb2a0dc427e3b3bc70f052 (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
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/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 1238da8b035a0b0dd3d00557ca0de7a82f5fdf53..5e40ee2695b7ed50fddc0e8226f0b1b4879cd510 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -795,7 +795,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
 
     @Override
     public void readAdditionalSaveData(CompoundTag nbt) {
-        this.setAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
+        // Paper start - jvm keeps optimizing the setter
+        float absorptionAmount = nbt.getFloat("AbsorptionAmount");
+        if (Float.isNaN(absorptionAmount)) {
+            absorptionAmount = 0;
+        }
+        this.setAbsorptionAmount(absorptionAmount);
+        // Paper end
         if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
             this.getAttributes().load(nbt.getList("Attributes", 10));
         }
@@ -1313,6 +1319,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public void setHealth(float health) {
+        // Paper start
+        if (Float.isNaN(health)) { health = getMaxHealth(); if (this.valid) {
+            System.err.println("[NAN-HEALTH] " + getScoreboardName() + " had NaN health set");
+        } } // Paper end
         // CraftBukkit start - Handle scaled health
         if (this instanceof ServerPlayer) {
             org.bukkit.craftbukkit.entity.CraftPlayer player = ((ServerPlayer) this).getBukkitEntity();
@@ -3482,7 +3492,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public void setAbsorptionAmount(float amount) {
-        if (amount < 0.0F) {
+        if (amount < 0.0F || Float.isNaN(amount)) { // Paper
             amount = 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 cc62d67e60f5f6ee313d4e20a6f206fec8545df1..ae9467c7de52d9214443f36540d3069c67e98441 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2092,6 +2092,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
     }
 
     public void setRealHealth(double health) {
+        if (Double.isNaN(health)) {return;} // Paper
         this.health = health;
     }