mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 09:19:38 +01:00
61 lines
2.5 KiB
Diff
61 lines
2.5 KiB
Diff
From 50673c9e6a2f18b9997e5ef316a0ce67fb2f846e 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
|
|
index 4b9e65b..ebd0475 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
@@ -463,7 +463,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));
|
|
}
|
|
@@ -748,6 +754,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();
|
|
@@ -2092,7 +2102,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
|
|
index a168a77..fe5084e 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1371,6 +1371,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
public void setRealHealth(double health) {
|
|
+ if (Double.isNaN(health)) {return;} // Paper
|
|
this.health = health;
|
|
}
|
|
|
|
--
|
|
2.8.0
|
|
|