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-03-26 22:29:41 +02:00
|
|
|
index 9936fb67766dedba71b582316dd2bddd6567c342..2f161145789890fcd9bfd893b099f25a53c61034 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-03-14 19:36:39 +01:00
|
|
|
@@ -777,7 +777,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) {
|
|
|
|
- this.setAbsorptionAmount(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;
|
|
|
|
+ }
|
|
|
|
+ this.setAbsorptionAmount(absorptionAmount);
|
|
|
|
+ // Paper end
|
2021-06-12 02:57:04 +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
|
|
|
}
|
2023-03-14 19:36:39 +01:00
|
|
|
@@ -1264,6 +1270,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-03-14 19:36:39 +01:00
|
|
|
@@ -3432,7 +3442,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2021-06-11 14:02:28 +02: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
|
2023-06-01 01:36:57 +02:00
|
|
|
index 31785e1cee09977356ee2b65a7d41df2c959d1b2..16dc9546303d692c62b6a1538106019f6bbe149b 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
|
2023-06-01 01:36:57 +02:00
|
|
|
@@ -2165,6 +2165,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;
|
|
|
|
}
|
|
|
|
|