From 8908a9101608d3343023b470743ef63f1c44b0b7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 26 May 2022 15:45:34 +0200 Subject: Get rid of node metadata when it becomes empty fixes #8943 --- src/script/lua_api/l_nodemeta.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/script/lua_api/l_nodemeta.cpp') diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 1d052685e..514a1b78b 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -40,7 +40,7 @@ NodeMetaRef* NodeMetaRef::checkobject(lua_State *L, int narg) Metadata* NodeMetaRef::getmeta(bool auto_create) { if (m_is_local) - return m_meta; + return m_local_meta; NodeMetadata *meta = m_env->getMap().getNodeMetadata(m_p); if (meta == NULL && auto_create) { @@ -62,9 +62,12 @@ void NodeMetaRef::clearMeta() void NodeMetaRef::reportMetadataChange(const std::string *name) { SANITY_CHECK(!m_is_local); - // NOTE: This same code is in rollback_interface.cpp // Inform other things that the metadata has changed - NodeMetadata *meta = dynamic_cast(m_meta); + NodeMetadata *meta = dynamic_cast(getmeta(false)); + + // If the metadata is now empty, get rid of it + if (meta && meta->empty()) + clearMeta(); MapEditEvent event; event.type = MEET_BLOCK_NODE_METADATA_CHANGED; @@ -174,8 +177,8 @@ NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env): } NodeMetaRef::NodeMetaRef(Metadata *meta): - m_meta(meta), - m_is_local(true) + m_is_local(true), + m_local_meta(meta) { } -- cgit v1.2.3