1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-12-14 19:18:29 +01:00

Add persistent unique identifiers for objects (#14135)

This commit is contained in:
sfence
2025-07-09 10:40:26 +02:00
committed by GitHub
parent e0f8243629
commit 4f42b4308c
20 changed files with 257 additions and 19 deletions

View File

@@ -50,7 +50,14 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
rotation.X = readF1000(is);
rotation.Z = readF1000(is);
// if (version2 < 2)
if (version2 < 2) {
m_guid = env->getGUIDGenerator().next();
break;
}
m_guid.deSerialize(is);
// if (version2 < 3)
// break;
// <read new values>
break;
@@ -70,6 +77,14 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &d
m_rotation = rotation;
}
LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
const std::string &state) :
UnitSAO(env, pos),
m_init_name(name), m_init_state(state),
m_guid(env->getGUIDGenerator().next())
{
}
LuaEntitySAO::~LuaEntitySAO()
{
if(m_registered){
@@ -294,11 +309,13 @@ void LuaEntitySAO::getStaticData(std::string *result) const
writeF1000(os, m_rotation.Y);
// version2. Increase this variable for new values
writeU8(os, 1); // PROTOCOL_VERSION >= 37
writeU8(os, 2);
writeF1000(os, m_rotation.X);
writeF1000(os, m_rotation.Z);
m_guid.serialize(os);
// <write new values>
*result = os.str();
@@ -414,6 +431,13 @@ u16 LuaEntitySAO::getHP() const
return m_hp;
}
std::string LuaEntitySAO::getGUID() const
{
// The "@" ensures that entity GUIDs are easily recognizable
// and makes it obvious that they can't collide with player names.
return "@" + m_guid.base64();
}
void LuaEntitySAO::setVelocity(v3f velocity)
{
m_velocity = velocity;