Paper/patches/server/0073-handle-NaN-health-absorb-values-and-repair-bad-data.patch
Nassim Jahnke 058d7c1aa3
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
13eb4146 SPIGOT-5217, SPIGOT-6183: Add RespawnReason to PlayerRespawnEvent

CraftBukkit Changes:
5ee3419b7 SPIGOT-5217, SPIGOT-6183: Add RespawnReason to PlayerRespawnEvent

Spigot Changes:
514cf03a Rebuild patches and add RespawnReason.PLUGIN to Player#respawn
2023-04-10 10:03:36 +02:00

58 lines
2.7 KiB
Diff

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 9936fb67766dedba71b582316dd2bddd6567c342..2f161145789890fcd9bfd893b099f25a53c61034 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -777,7 +777,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
@Override
public void readAdditionalSaveData(CompoundTag nbt) {
- this.setAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
+ // Paper start - jvm keeps optimizing the setter
+ float absorptionAmount = nbt.getFloat("AbsorptionAmount");
+ if (Float.isNaN(absorptionAmount)) {
+ absorptionAmount = 0;
+ }
+ this.setAbsorptionAmount(absorptionAmount);
+ // Paper end
if (nbt.contains("Attributes", 9) && this.level != null && !this.level.isClientSide) {
this.getAttributes().load(nbt.getList("Attributes", 10));
}
@@ -1264,6 +1270,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
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();
@@ -3432,7 +3442,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
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 618e0f885089223596c290c9a42f67d24f43e3be..532b62d9cbfd9e7586b4df84fb0f1598a5e19e02 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2157,6 +2157,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}