diff options
author | sfan5 <sfan5@live.de> | 2022-07-04 01:06:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 01:06:42 +0200 |
commit | fc3460470aec8d73317d2b35edf195bfeec2852c (patch) | |
tree | acfee4e29064b04726bb65b1e0cf026c82834e28 /builtin | |
parent | 34f15259fa5546dc9abaf974ca5385c276443697 (diff) | |
download | minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.tar.gz minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.tar.bz2 minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.zip |
Add missing item alias metatables to async environment (#12458)
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/async/game.lua | 16 | ||||
-rw-r--r-- | builtin/game/register.lua | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/builtin/async/game.lua b/builtin/async/game.lua index 8cb9720b6..6512f0706 100644 --- a/builtin/async/game.lua +++ b/builtin/async/game.lua @@ -25,11 +25,13 @@ do local all = assert(core.transferred_globals) core.transferred_globals = nil - -- reassemble other tables all.registered_nodes = {} all.registered_craftitems = {} all.registered_tools = {} for k, v in pairs(all.registered_items) do + -- Disable further modification + setmetatable(v, {__newindex = {}}) + -- Reassemble the other tables if v.type == "node" then all.registered_nodes[k] = v elseif v.type == "craftitem" then @@ -43,3 +45,15 @@ do core[k] = v end end + +-- For tables that are indexed by item name: +-- If table[X] does not exist, default to table[core.registered_aliases[X]] +local alias_metatable = { + __index = function(t, name) + return rawget(t, core.registered_aliases[name]) + end +} +setmetatable(core.registered_items, alias_metatable) +setmetatable(core.registered_nodes, alias_metatable) +setmetatable(core.registered_craftitems, alias_metatable) +setmetatable(core.registered_tools, alias_metatable) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 0be107c36..ee4edabbf 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -1,4 +1,4 @@ --- Minetest: builtin/misc_register.lua +-- Minetest: builtin/register.lua local S = core.get_translator("__builtin") |