diff options
author | paramat <paramat@users.noreply.github.com> | 2018-03-02 21:27:59 +0000 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2018-03-03 23:00:08 +0000 |
commit | 48493a979b4300d96ba17e2ef3a881641323f43e (patch) | |
tree | 975bc269a36a11dea11f1db02718076178880ff8 | |
parent | 07622bf9b49830aae2a5e12b5616471da6a8b19a (diff) | |
download | minetest-48493a979b4300d96ba17e2ef3a881641323f43e.tar.gz minetest-48493a979b4300d96ba17e2ef3a881641323f43e.tar.bz2 minetest-48493a979b4300d96ba17e2ef3a881641323f43e.zip |
Gennotify: Add 'minetest.get_decoration_id' API
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'.
-rw-r--r-- | doc/lua_api.txt | 5 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 27 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.h | 4 |
3 files changed, 35 insertions, 1 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 29be2a98c..ccc30a2a1 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -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)` diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index ccbe9a4b0..5bd49e386 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -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) { @@ -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); diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 44073620b..713069633 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -76,6 +76,10 @@ private: // 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); |