Store Health as a float (#4073)
* Fix #4024 * Fix clang error * Add comment * Fix behaviour * Save Health as float * Changed m_Health to float * Remove redundant static_cast * Fix casts
This commit is contained in:
committed by
Alexander Harkness
parent
ef091fe24b
commit
0dd172b80f
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user