Paper/Spigot-Server-Patches/0078-handle-NaN-health-absorb-values-and-repair-bad-data.patch

61 lines
2.5 KiB
Diff
Raw Normal View History

2018-03-26 02:06:44 +02:00
From 73ac346074556ad06db864c7e3667a6b7f6fbb4f 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/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2018-03-26 02:06:44 +02:00
index 7e2cc66d7..a92b89d7c 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2017-11-08 17:13:57 +01:00
@@ -488,7 +488,13 @@ public abstract class EntityLiving extends Entity {
}
public void a(NBTTagCompound nbttagcompound) {
- this.setAbsorptionHearts(nbttagcompound.getFloat("AbsorptionAmount"));
+ // Paper start - jvm keeps optimizing the setter
+ float absorptionAmount = nbttagcompound.getFloat("AbsorptionAmount");
+ if (Float.isNaN(absorptionAmount)) {
+ absorptionAmount = 0;
+ }
+ this.setAbsorptionHearts(absorptionAmount);
+ // Paper end
if (nbttagcompound.hasKeyOfType("Attributes", 9) && this.world != null && !this.world.isClientSide) {
GenericAttributes.a(this.getAttributeMap(), nbttagcompound.getList("Attributes", 10));
}
2017-11-08 17:13:57 +01:00
@@ -791,6 +797,10 @@ public abstract class EntityLiving extends Entity {
}
public void setHealth(float f) {
+ // Paper start
+ if (Float.isNaN(f)) { f = getMaxHealth(); if (this.valid) {
+ System.err.println("[NAN-HEALTH] " + getName() + " had NaN health set");
+ } } // Paper end
// CraftBukkit start - Handle scaled health
if (this instanceof EntityPlayer) {
org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity();
2018-03-26 02:06:44 +02:00
@@ -2265,7 +2275,7 @@ public abstract class EntityLiving extends Entity {
}
public void setAbsorptionHearts(float f) {
- if (f < 0.0F) {
+ if (f < 0.0F || Float.isNaN(f)) { // Paper
f = 0.0F;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2018-02-12 19:04:05 +01:00
index 45b11d87c..aa7751059 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2018-02-12 19:04:05 +01:00
@@ -1460,6 +1460,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}
--
2018-03-26 02:06:44 +02:00
2.16.2