summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage/WSSAnvil.cpp
diff options
context:
space:
mode:
authorFabian <fenstein12@googlemail.com>2017-11-22 14:47:52 +0100
committerAlexander Harkness <me@bearbin.net>2017-11-22 14:47:52 +0100
commit0dd172b80ffc949cf87119ad2003589d7eb82c46 (patch)
treea7af747aa95241297f07104c138cfc66cf7f6c97 /src/WorldStorage/WSSAnvil.cpp
parentcBlockRail: Fix assertion failure (#4075) (diff)
downloadcuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar.gz
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar.bz2
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar.lz
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar.xz
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.tar.zst
cuberite-0dd172b80ffc949cf87119ad2003589d7eb82c46.zip
Diffstat (limited to 'src/WorldStorage/WSSAnvil.cpp')
-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;
}