PaperMC/patches/server/0074-handle-NaN-health-absorb-values-and-repair-bad-data.patch

58 lines
3 KiB
Diff
Raw Normal View History

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-10-22 20:04:31 +02:00
index 4fa5e7127549e090338b11e6493413a3fab254a0..14d9e62c86309676ddd7eed19cce2f4b30a59b94 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-10-22 20:04:31 +02:00
@@ -833,7 +833,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"));
+ // 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);
+ // 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-10-22 20:04:31 +02:00
@@ -1373,6 +1379,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
public void setHealth(float health) {
+ // 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");
+ } } // 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-10-22 20:04:31 +02:00
@@ -3841,7 +3851,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()));
+ 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-10-25 13:52:04 +02:00
index e904d8558c425d3b2027053f4083999f0deb36fb..d578d65883f23cc4aaa5b0a7cf1fc88bb337f3a5 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-10-24 19:29:35 +02:00
@@ -2365,6 +2365,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper - Check for NaN
2021-06-11 14:02:28 +02:00
this.health = health;
}