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

63 lines
2.9 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
2021-07-07 06:52:40 +00:00
index a492f0b8393c185f0464f0fb0e5d5dce4d0e3824..a0d6cc4eeda0a7a09724b6482da71c969abcfeb0 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-06-12 00:57:04 +00:00
@@ -764,7 +764,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-06-12 00:57:04 +00:00
@@ -1251,6 +1257,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();
2021-07-07 06:52:40 +00:00
@@ -3398,7 +3408,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;
}
2021-07-07 06:52:40 +00:00
@@ -4003,3 +4013,4 @@ public abstract class LivingEntity extends Entity {
2021-06-12 00:57:04 +00:00
this.setDeltaMovement((double) ((float) packet.getXd() / 8000.0F), (double) ((float) packet.getYd() / 8000.0F), (double) ((float) packet.getZd() / 8000.0F));
}
}
+
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2021-07-07 06:52:40 +00:00
index 45a8dc649983f1eec3d8eb065cb34d517c55300b..50267f9877898d7108edc057140e3e572eac9461 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
@@ -1702,6 +1702,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;
}