1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Apply review.

This commit is contained in:
SFENCE 2025-06-09 19:09:16 +02:00
parent 1df282c635
commit 0b423bdb22
7 changed files with 19 additions and 21 deletions

View file

@ -7849,12 +7849,12 @@ Global tables
* Values in this table may be modified directly.
Note: changes to initial properties will only affect entities spawned afterwards,
as they are only read when spawning.
* `core.object_refs`
* Map of active object references, indexed by active object id
* Obsolete: Use `core.objects_by_guid` instead.
GUIDs are strictly more useful than active object IDs.
* `core.objects_by_guid`
* Map of active object references, indexed by object GUID
* `core.object_refs`
* **Obsolete:** Use `core.objects_by_guid` instead.
GUIDs are strictly more useful than active object IDs.
* Map of active object references, indexed by active object id
* `core.luaentities`
* Map of Lua entities, indexed by active object id
* `core.registered_abms`
@ -8555,10 +8555,10 @@ child will follow movement and rotation of that bone.
* `get_guid()`: returns a global unique identifier (a string)
* For players, this is a player name.
* For Lua entities, this is a uniquely generated string, guaranteed not to collide with player names.
* Example: `@bGh3p2AbRE29Mb4biqX6OA`
* example: `@bGh3p2AbRE29Mb4biqX6OA`
* GUIDs only use printable ASCII characters.
* GUIDs are persisted internally between object reloads; their format is guaranteed not to change.
Thus you can store GUIDs to identify objects persistently.
* GUIDs persist internally between object reloads; their format is guaranteed not to change.
Thus you can use the GUID to identify an object in a particular world online nad offline.
#### Lua entity only (no-op for other objects)

View file

@ -598,7 +598,7 @@ Since protocol version 37:
* `s32` pitch * 1000
* `s32` roll * 1000
* if version2 >= 2:
* u8[16] guid
* `u8[16]` guid
# Itemstring Format

View file

@ -257,19 +257,15 @@ end
unittests.register("test_item_drop", test_item_drop, {map=true})
local function test_entity_guid(_, pos)
log = {}
local obj0 = core.add_entity(pos, "unittests:callbacks")
check_log({"on_activate(0)"})
local obj1 = core.add_entity(pos, "unittests:callbacks")
check_log({"on_activate(0)"})
local obj0 = core.add_entity(pos, "unittests:dummy")
local obj1 = core.add_entity(pos, "unittests:dummy")
assert(obj0 ~= obj1)
assert(obj0:get_guid() ~= obj1:get_guid())
assert(core.objects_by_guid[obj0:get_guid()] == obj0)
assert(core.objects_by_guid[obj1:get_guid()] == obj1)
obj0:remove()
check_log({"on_deactivate(true)"})
obj1:remove()
check_log({"on_deactivate(true)"})
end
unittests.register("test_entity_guid", test_entity_guid, {map=true})

View file

@ -209,6 +209,6 @@ unittests.register("test_player_hotbar_clamp", run_player_hotbar_clamp_tests, {p
-- Player get GUID
--
local function test_player_guid_tests(player)
assert(player:get_guid()==player:get_player_name())
assert(player:get_guid() == player:get_player_name())
end
unittests.register("test_player_guid", test_player_guid_tests, {player=true})

View file

@ -444,7 +444,9 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
objectstable = lua_gettop(L);
// objects_by_guid[guid] = object
lua_pushstring(L, cobj->getGUID().c_str());
auto guid = cobj->getGUID();
assert(!guid.empty());
lua_pushstring(L, guid.c_str());
lua_pushvalue(L, object);
lua_settable(L, objectstable);
}

View file

@ -309,7 +309,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
writeF1000(os, m_rotation.Y);
// version2. Increase this variable for new values
writeU8(os, 2); // PROTOCOL_VERSION >= 37
writeU8(os, 2);
writeF1000(os, m_rotation.X);
writeF1000(os, m_rotation.Z);

View file

@ -141,8 +141,8 @@ public:
virtual u16 getHP() const
{ return 0; }
/// Always returns the same unique string for the same object.
/// Because these strings are very short, copying them is not expensive.
/// @brief Returns an unique ID for this object (persistent across unload, server restarts).
/// @note Because these strings are very short, copying them is not expensive.
virtual std::string getGUID() = 0;
virtual void setArmorGroups(const ItemGroupList &armor_groups)