testserver/patches/server/0069-handle-NaN-health-abso...

58 lines
2.6 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00: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
index cb611587ad1b929627576a330e398d980595c48a..a1137e8602a2d2670df4ddff01d7aee5d3599991 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2021-11-23 12:15:10 +00:00
@@ -759,7 +759,13 @@ public abstract class LivingEntity extends Entity {
2021-06-11 12:02:28 +00:00
@Override
2021-06-12 00:57:04 +00:00
public void readAdditionalSaveData(CompoundTag nbt) {
- this.setAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
2021-06-11 12:02:28 +00:00
+ // Paper start - jvm keeps optimizing the setter
2021-06-12 00:57:04 +00:00
+ float absorptionAmount = nbt.getFloat("AbsorptionAmount");
2021-06-11 12:02:28 +00:00
+ if (Float.isNaN(absorptionAmount)) {
+ absorptionAmount = 0;
+ }
+ this.setAbsorptionAmount(absorptionAmount);
+ // Paper end
2021-06-12 00:57:04 +00:00
if (nbt.contains("Attributes", 9) && this.level != null && !this.level.isClientSide) {
this.getAttributes().load(nbt.getList("Attributes", 10));
2021-06-11 12:02:28 +00:00
}
2021-11-23 12:15:10 +00:00
@@ -1246,6 +1252,10 @@ public abstract class LivingEntity extends Entity {
2021-06-11 12:02:28 +00: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();
@@ -3397,7 +3407,7 @@ public abstract class LivingEntity extends Entity {
2021-06-11 12:02:28 +00:00
}
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 a332a025655219acdbbecb4ec86e280e4dd7dac3..12985cf9731b70bb1811efb04afe25e5c9fdc851 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1792,6 +1792,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 12:02:28 +00:00
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}