mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 12:19:56 +01:00
72e87abc2d
Co-authored-by: Paul Sauve <paul@technove.co>
58 lines
2.7 KiB
Diff
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 53e666df97e74bbb8e96207ebc50e3e9acc455de..8435d0c62c716d4cce5d8b512d8a42658f774876 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -794,7 +794,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));
|
|
}
|
|
@@ -1312,6 +1318,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();
|
|
@@ -3472,7 +3482,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 df91d5f9161e9bf65556191a3079ae0f008ab698..a6d9dcf8487c63a0469f5fec27bef131b444942a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -2149,6 +2149,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
public void setRealHealth(double health) {
|
|
+ if (Double.isNaN(health)) {return;} // Paper
|
|
this.health = health;
|
|
}
|
|
|