diff options
author | sfan5 <sfan5@live.de> | 2020-04-19 19:07:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-19 19:07:54 +0200 |
commit | 338195ff250bd7552ef8167348de2eb05e421c29 (patch) | |
tree | bb19ba9dfbf8cc72ceb351f12025718eb05d747b /src/script | |
parent | cdbe3c5e5784b34e548c58b08579ff55b3096fb9 (diff) | |
download | minetest-338195ff250bd7552ef8167348de2eb05e421c29.tar.gz minetest-338195ff250bd7552ef8167348de2eb05e421c29.tar.bz2 minetest-338195ff250bd7552ef8167348de2eb05e421c29.zip |
Fix alias handling of get_content_id (#9712)
fixes #9632
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_item.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 9f12d3ac7..0a403acbd 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -609,10 +609,21 @@ int ModApiItemMod::l_get_content_id(lua_State *L) NO_MAP_LOCK_REQUIRED; std::string name = luaL_checkstring(L, 1); + const IItemDefManager *idef = getGameDef(L)->getItemDefManager(); const NodeDefManager *ndef = getGameDef(L)->getNodeDefManager(); + + // If this is called at mod load time, NodeDefManager isn't aware of + // aliases yet, so we need to handle them manually + std::string alias_name = idef->getAlias(name); + content_t content_id; - if (!ndef->getId(name, content_id)) + if (alias_name != name) { + if (!ndef->getId(alias_name, content_id)) + throw LuaError("Unknown node: " + alias_name + + " (from alias " + name + ")"); + } else if (!ndef->getId(name, content_id)) { throw LuaError("Unknown node: " + name); + } lua_pushinteger(L, content_id); return 1; /* number of results */ |