Skip to content

Commit

Permalink
Gennotify: Add 'minetest.get_decoration_id' API
Browse files Browse the repository at this point in the history
Returns the decoration ID for the provided decoration name string.
For use with gennotify, to know the decoration IDs for use in
'minetest.set_gen_notify'.
  • Loading branch information
paramat committed Mar 3, 2018
1 parent 07622bf commit 48493a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -2842,8 +2842,11 @@ and `minetest.auth_reload` call the authentication handler.
* decoration
* The second parameter is a list of IDS of decorations which notification
is requested for.
* `get_gen_notify()`
* `minetest.get_gen_notify()`
* Returns a flagstring and a table with the `deco_id`s.
* `minetest.get_decoration_id(decoration_name)
* Returns the decoration ID number for the provided decoration name string,
or `nil` on failure.
* `minetest.get_mapgen_object(objectname)`
* Return requested mapgen object if available (see "Mapgen objects")
* `minetest.get_heat(pos)`
Expand Down
27 changes: 27 additions & 0 deletions src/script/lua_api/l_mapgen.cpp
Expand Up @@ -1006,6 +1006,32 @@ int ModApiMapgen::l_get_gen_notify(lua_State *L)
}


// get_decoration_id(decoration_name)
// returns the decoration ID as used in gennotify
int ModApiMapgen::l_get_decoration_id(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;

const char *deco_str = luaL_checkstring(L, 1);
if (!deco_str)
return 0;

DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr;

if (!dmgr)
return 0;

Decoration *deco = (Decoration *)dmgr->getByName(deco_str);

if (!deco)
return 0;

lua_pushinteger(L, deco->index);

return 1;
}


// register_biome({lots of stuff})
int ModApiMapgen::l_register_biome(lua_State *L)
{
Expand Down Expand Up @@ -1696,6 +1722,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
API_FCT(get_noiseparams);
API_FCT(set_gen_notify);
API_FCT(get_gen_notify);
API_FCT(get_decoration_id);

API_FCT(register_biome);
API_FCT(register_decoration);
Expand Down
4 changes: 4 additions & 0 deletions src/script/lua_api/l_mapgen.h
Expand Up @@ -76,6 +76,10 @@ class ModApiMapgen : public ModApiBase
// get_gen_notify()
static int l_get_gen_notify(lua_State *L);

// get_decoration_id(decoration_name)
// returns the decoration ID as used in gennotify
static int l_get_decoration_id(lua_State *L);

// register_biome({lots of stuff})
static int l_register_biome(lua_State *L);

Expand Down

0 comments on commit 48493a9

Please sign in to comment.