Paper/patches/server/0073-handle-NaN-health-absorb-values-and-repair-bad-data.patch

58 lines
2.9 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
2023-12-05 20:54:55 +01:00
index b76ac10fe0d4b860a4b30fae365cf38400afb456..1e2d3040bb3e8b1901fbc933caa5ad3b82d3468c 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
2023-12-05 20:54:55 +01:00
@@ -793,7 +793,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"));
2021-06-11 14:02:28 +02:00
+ // Paper start - jvm keeps optimizing the setter
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);
2021-06-11 14:02:28 +02:00
+ // Paper end
2023-06-07 20:49:17 +02:00
if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
2021-06-12 02:57:04 +02:00
this.getAttributes().load(nbt.getList("Attributes", 10));
2021-06-11 14:02:28 +02:00
}
2023-12-05 20:54:55 +01:00
@@ -1343,6 +1349,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
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();
2023-12-05 20:54:55 +01:00
@@ -3531,7 +3541,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
}
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
index 5107128b0868d46b1672df8c8f98018de87c9eff..3fe9b9a28829f6796a23fe337df3a677d2e8d19b 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
@@ -2209,6 +2209,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
this.health = health;
}