diff options
author | Duane Robertson <duane@duanerobertson.com> | 2015-09-29 12:38:08 -0500 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-10-02 22:49:31 +0200 |
commit | a5bdfb6b3cfddaac1e961bd8c8780c74ccde3567 (patch) | |
tree | 3844d522cc817395be35dfac4d9d61f562d0854e /src/script/lua_api | |
parent | 21944a0d3c5284f6bf1e61286ddbcc2ab2f1e2aa (diff) | |
download | minetest-a5bdfb6b3cfddaac1e961bd8c8780c74ccde3567.tar.gz minetest-a5bdfb6b3cfddaac1e961bd8c8780c74ccde3567.tar.bz2 minetest-a5bdfb6b3cfddaac1e961bd8c8780c74ccde3567.zip |
Add get_biome_id(biome_name) callback
It returns the index used in mg->biomemap for a given biome name.
The biomemap is useless without this unless you re-register all existing biomes,
which could cause problems for anyone else trying to use biomemap.
With this, you can quickly create a lookup table of ids and names.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 25 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.h | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index dcb611f47..784ceabcc 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -450,6 +450,30 @@ size_t get_biome_list(lua_State *L, int index, /////////////////////////////////////////////////////////////////////////////// +// get_biome_id(biomename) +// returns the biome id used in biomemap +int ModApiMapgen::l_get_biome_id(lua_State *L) +{ + const char *biome_str = lua_tostring(L, 1); + if (!biome_str) + return 0; + + BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + + if (!bmgr) + return 0; + + Biome *biome = (Biome *) bmgr->getByName(biome_str); + + if (!biome || biome->index == OBJDEF_INVALID_INDEX) + return 0; + + lua_pushinteger(L, biome->index); + + return 1; +} + + // get_mapgen_object(objectname) // returns the requested object used during map generation int ModApiMapgen::l_get_mapgen_object(lua_State *L) @@ -1257,6 +1281,7 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L) void ModApiMapgen::Initialize(lua_State *L, int top) { + API_FCT(get_biome_id); API_FCT(get_mapgen_object); API_FCT(get_mapgen_params); diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 7440d1285..4768f934d 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -24,6 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc., class ModApiMapgen : public ModApiBase { private: + // get_biome_id(biomename) + // returns the biome id used in biomemap + static int l_get_biome_id(lua_State *L); + // get_mapgen_object(objectname) // returns the requested object used during map generation static int l_get_mapgen_object(lua_State *L); |