aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0078-handle-NaN-health-absorb-values-and-repair-bad-data.patch
blob: bb5ee99fa0a89cd211ee817771ea2de1e67e6d10 (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 801577d2c9e6eacd8e3038f5b3cdb026c62a5d09..24e6d6c356cccf656cd20bcea069f5fdf123e4c8 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -833,7 +833,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
 
     @Override
     public void readAdditionalSaveData(CompoundTag nbt) {
-        this.internalSetAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
+        // Paper start - Check for NaN
+        float absorptionAmount = nbt.getFloat("AbsorptionAmount");
+        if (Float.isNaN(absorptionAmount)) {
+            absorptionAmount = 0;
+        }
+        this.internalSetAbsorptionAmount(absorptionAmount);
+        // Paper end - Check for NaN
         if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
             this.getAttributes().load(nbt.getList("Attributes", 10));
         }
@@ -1365,6 +1371,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public void setHealth(float health) {
+        // Paper start - Check for NaN
+        if (Float.isNaN(health)) { health = getMaxHealth(); if (this.valid) {
+            System.err.println("[NAN-HEALTH] " + getScoreboardName() + " had NaN health set");
+        } } // Paper end - Check for NaN
         // CraftBukkit start - Handle scaled health
         if (this instanceof ServerPlayer) {
             org.bukkit.craftbukkit.entity.CraftPlayer player = ((ServerPlayer) this).getBukkitEntity();
@@ -3643,7 +3653,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public final void setAbsorptionAmount(float absorptionAmount) {
-        this.internalSetAbsorptionAmount(Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()));
+        this.internalSetAbsorptionAmount(!Float.isNaN(absorptionAmount) ? Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()) : 0.0F); // Paper - Check for NaN
     }
 
     protected void internalSetAbsorptionAmount(float absorptionAmount) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 9743f5b8b6e1cbbe43788a42c02bb7cfbdd8f380..d616f6c1fe63e3fe9d811d670dbc78a44e7afcbd 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2327,6 +2327,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
     }
 
     public void setRealHealth(double health) {
+        if (Double.isNaN(health)) {return;} // Paper - Check for NaN
         this.health = health;
     }