2021-06-11 14:02:28 +02:00
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
2024-07-06 21:19:14 +02:00
index e7b308ba4a253b270aebebd19e2671514c5357ca..fae7c493c9be741f019fc49f45a59976e6b01ed7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2024-07-06 21:19:14 +02:00
@@ -808,7 +808,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
@Override
2021-06-12 02:57:04 +02:00
public void readAdditionalSaveData(CompoundTag nbt) {
2023-09-21 22:14:58 +02:00
- this.internalSetAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
2024-01-23 14:34:17 +01:00
+ // Paper start - Check for NaN
2021-06-12 02:57:04 +02:00
+ float absorptionAmount = nbt.getFloat("AbsorptionAmount");
2021-06-11 14:02:28 +02:00
+ if (Float.isNaN(absorptionAmount)) {
+ absorptionAmount = 0;
+ }
2023-09-21 22:14:58 +02:00
+ this.internalSetAbsorptionAmount(absorptionAmount);
2024-01-23 14:34:17 +01:00
+ // Paper end - Check for NaN
2024-06-13 19:30:39 +02:00
if (nbt.contains("attributes", 9) && this.level() != null && !this.level().isClientSide) {
this.getAttributes().load(nbt.getList("attributes", 10));
2021-06-11 14:02:28 +02:00
}
2024-07-06 21:19:14 +02:00
@@ -1342,6 +1348,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
public void setHealth(float health) {
2024-01-23 14:34:17 +01:00
+ // Paper start - Check for NaN
2021-06-11 14:02:28 +02:00
+ if (Float.isNaN(health)) { health = getMaxHealth(); if (this.valid) {
+ System.err.println("[NAN-HEALTH] " + getScoreboardName() + " had NaN health set");
2024-01-23 14:34:17 +01:00
+ } } // Paper end - Check for NaN
2021-06-11 14:02:28 +02:00
// CraftBukkit start - Handle scaled health
if (this instanceof ServerPlayer) {
org.bukkit.craftbukkit.entity.CraftPlayer player = ((ServerPlayer) this).getBukkitEntity();
2024-07-06 21:19:14 +02:00
@@ -3688,7 +3698,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
2023-09-21 22:14:58 +02:00
public final void setAbsorptionAmount(float absorptionAmount) {
- this.internalSetAbsorptionAmount(Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()));
2024-01-23 14:34:17 +01:00
+ this.internalSetAbsorptionAmount(!Float.isNaN(absorptionAmount) ? Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()) : 0.0F); // Paper - Check for NaN
2023-09-21 22:14:58 +02:00
}
2021-06-11 14:02:28 +02:00
2023-09-21 22:14:58 +02:00
protected void internalSetAbsorptionAmount(float absorptionAmount) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-07-06 21:19:14 +02:00
index f0ec24cf686fa7e1a025c8f9c8c6722f77c29e14..8a30e4d7b6542de3e6bea37cc2a6cbabd2bb9555 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-07-06 21:19:14 +02:00
@@ -2338,6 +2338,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
public void setRealHealth(double health) {
2024-01-23 14:34:17 +01:00
+ if (Double.isNaN(health)) {return;} // Paper - Check for NaN
2021-06-11 14:02:28 +02:00
this.health = health;
}