From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar 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 d038c65e8a3d4a0000465e9d3ac7c4915b1b1015..2cf58d6e086c1d6cc86ed689eb0d1cdc89b69477 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -784,7 +784,13 @@ public abstract class LivingEntity extends Entity { @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)); } @@ -1271,6 +1277,10 @@ public abstract class LivingEntity extends Entity { } 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(); @@ -3447,7 +3457,7 @@ public abstract class LivingEntity extends Entity { } 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 15257f9236d0c32c1c74a15ce4e7decf4d9f2f91..1e1deab4d8be5523a55daf072d7e12b08d36b560 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2011,6 +2011,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } public void setRealHealth(double health) { + if (Double.isNaN(health)) {return;} // Paper this.health = health; }