summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/WSSAnvil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index b47d3eddd..35fdaa8d8 100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -3154,9 +3154,28 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N
a_Entity.SetYaw(Rotation[0]);
a_Entity.SetRoll(Rotation[1]);
- // Load health:
+ // Depending on the Minecraft version, the entity's health is
+ // stored either as a float Health tag (HealF prior to 1.9) or
+ // as a short Health tag. The float tags should be preferred.
int Health = a_NBT.FindChildByName(a_TagIdx, "Health");
- a_Entity.SetHealth(Health > 0 ? a_NBT.GetShort(Health) : a_Entity.GetMaxHealth());
+ int HealF = a_NBT.FindChildByName(a_TagIdx, "HealF");
+
+ if (Health > 0 && a_NBT.GetType(Health) == TAG_Float)
+ {
+ a_Entity.SetHealth(a_NBT.GetFloat(Health));
+ }
+ else if (HealF > 0)
+ {
+ a_Entity.SetHealth(a_NBT.GetFloat(HealF));
+ }
+ else if (Health > 0)
+ {
+ a_Entity.SetHealth(static_cast<float>(a_NBT.GetShort(Health)));
+ }
+ else
+ {
+ a_Entity.SetHealth(a_Entity.GetMaxHealth());
+ }
return true;
}