Fix entity rotation in existing worlds (#7989)

This commit is contained in:
SmallJoker 2018-12-24 00:22:27 +01:00 committed by Paramat
parent b8b33a6423
commit 67049eba3c

@ -350,26 +350,43 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
s16 hp = 1; s16 hp = 1;
v3f velocity; v3f velocity;
v3f rotation; v3f rotation;
if (!data.empty()) {
while (!data.empty()) { // breakable, run for one iteration
std::istringstream is(data, std::ios::binary); std::istringstream is(data, std::ios::binary);
// read version // 'version' does not allow to incrementally extend the parameter list thus
// we need another variable to build on top of 'version=1'. Ugly hack but works™
u8 version2 = 0;
u8 version = readU8(is); u8 version = readU8(is);
// check if version is supported
if(version == 0){ name = deSerializeString(is);
name = deSerializeString(is); state = deSerializeLongString(is);
state = deSerializeLongString(is);
} if (version < 1)
else if(version == 1){ break;
name = deSerializeString(is);
state = deSerializeLongString(is); hp = readS16(is);
hp = readS16(is); velocity = readV3F1000(is);
velocity = readV3F1000(is); // yaw must be yaw to be backwards-compatible
rotation = readV3F1000(is); rotation.Y = readF1000(is);
}
if (is.good()) // EOF for old formats
version2 = readU8(is);
if (version2 < 1) // PROTOCOL_VERSION < 37
break;
// version2 >= 1
rotation.X = readF1000(is);
rotation.Z = readF1000(is);
// if (version2 < 2)
// break;
// <read new values>
break;
} }
// create object // create object
infostream<<"LuaEntitySAO::create(name=\""<<name<<"\" state=\"" infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\""
<<state<<"\")"<<std::endl; << state << "\")" << std::endl;
LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state); LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state);
sao->m_hp = hp; sao->m_hp = hp;
sao->m_velocity = velocity; sao->m_velocity = velocity;
@ -527,7 +544,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
{ {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
// protocol >= 14 // PROTOCOL_VERSION >= 37
writeU8(os, 1); // version writeU8(os, 1); // version
os << serializeString(""); // name os << serializeString(""); // name
writeU8(os, 0); // is_player writeU8(os, 0); // is_player
@ -572,7 +589,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
{ {
verbosestream<<FUNCTION_NAME<<std::endl; verbosestream<<FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
// version // version must be 1 to keep backwards-compatibility. See version2
writeU8(os, 1); writeU8(os, 1);
// name // name
os<<serializeString(m_init_name); os<<serializeString(m_init_name);
@ -584,12 +601,18 @@ void LuaEntitySAO::getStaticData(std::string *result) const
} else { } else {
os<<serializeLongString(m_init_state); os<<serializeLongString(m_init_state);
} }
// hp
writeS16(os, m_hp); writeS16(os, m_hp);
// velocity
writeV3F1000(os, m_velocity); writeV3F1000(os, m_velocity);
// rotation // yaw
writeV3F1000(os, m_rotation); writeF1000(os, m_rotation.Y);
// version2. Increase this variable for new values
writeU8(os, 1); // PROTOCOL_VERSION >= 37
writeF1000(os, m_rotation.X);
writeF1000(os, m_rotation.Z);
// <write new values>
*result = os.str(); *result = os.str();
} }