1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix alias handling of get_content_id (#9712)

fixes #9632
This commit is contained in:
sfan5 2020-04-19 19:07:54 +02:00 committed by GitHub
parent cdbe3c5e57
commit 338195ff25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 22 deletions

View file

@ -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 */