geforkt von Mirrors/Paper
58 Zeilen
2.9 KiB
Diff
58 Zeilen
2.9 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 9b9e02f27f4281d3d39130521b1cc4e6979f8ea5..2cf9d80494c6b70992d8ec74fe1697c6522bd952 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.internalSetAbsorptionAmount(nbt.getFloat("AbsorptionAmount"));
|
|
+ // Paper start - jvm keeps optimizing the setter
|
|
+ float absorptionAmount = nbt.getFloat("AbsorptionAmount");
|
|
+ if (Float.isNaN(absorptionAmount)) {
|
|
+ absorptionAmount = 0;
|
|
+ }
|
|
+ this.internalSetAbsorptionAmount(absorptionAmount);
|
|
+ // Paper end
|
|
if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
|
|
this.getAttributes().load(nbt.getList("Attributes", 10));
|
|
}
|
|
@@ -1344,6 +1350,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();
|
|
@@ -3529,7 +3539,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
}
|
|
|
|
public final void setAbsorptionAmount(float absorptionAmount) {
|
|
- this.internalSetAbsorptionAmount(Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()));
|
|
+ this.internalSetAbsorptionAmount(!Float.isNaN(absorptionAmount) ? Mth.clamp(absorptionAmount, 0.0F, this.getMaxAbsorption()) : 0.0F); // Paper
|
|
}
|
|
|
|
protected void internalSetAbsorptionAmount(float absorptionAmount) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index e542d86dbf44e91058ad026e1bf9105d92fa687c..7363c80d35d4ff61d771fb77125a4e520f745bba 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -2167,6 +2167,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
public void setRealHealth(double health) {
|
|
+ if (Double.isNaN(health)) {return;} // Paper
|
|
this.health = health;
|
|
}
|
|
|