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

61 lines
2.5 KiB
Diff
Raw Normal View History

2017-05-14 20:05:01 +02:00
From 3d32a01b2bdddf62287fb6e4d45db50f4392299b 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
2017-05-14 20:05:01 +02:00
index 2b20a0205..793353ac7 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2017-05-14 20:05:01 +02:00
@@ -482,7 +482,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-05-14 20:05:01 +02:00
@@ -785,6 +791,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();
2017-05-14 20:05:01 +02:00
@@ -2257,7 +2267,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
2017-05-14 20:05:01 +02:00
index 5839801f5..78aab5c63 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2017-05-14 20:05:01 +02:00
@@ -1385,6 +1385,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void setRealHealth(double health) {
+ if (Double.isNaN(health)) {return;} // Paper
this.health = health;
}
--
2017-05-14 20:05:01 +02:00
2.13.0