summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
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
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')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp2
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp23
2 files changed, 22 insertions, 3 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 12f767abf..78573572d 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -431,7 +431,7 @@ void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_C
m_Writer.AddDouble("", a_Entity->GetYaw());
m_Writer.AddDouble("", a_Entity->GetPitch());
m_Writer.EndList();
- m_Writer.AddShort("Health", static_cast<Int16>(a_Entity->GetHealth()));
+ m_Writer.AddFloat("Health", a_Entity->GetHealth());
}
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;
}