Skip to content

Commit

Permalink
Add get_biome_id(biome_name) callback
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
duane-r authored and est31 committed Oct 2, 2015
1 parent 21944a0 commit a5bdfb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,9 @@ and `minetest.auth_reload` call the authetification handler.
* `get_gen_notify()`: returns a flagstring and a table with the deco_ids
* `minetest.get_mapgen_object(objectname)`
* Return requested mapgen object if available (see "Mapgen objects")
* `minetest.get_biome_id(biome_name)`
* Returns the biome id, as used in the biomemap Mapgen object, for a
given biome_name string.
* `minetest.get_mapgen_params()` Returns mapgen parameters, a table containing
`mgname`, `seed`, `chunksize`, `water_level`, and `flags`.
* `minetest.set_mapgen_params(MapgenParams)`
Expand Down
25 changes: 25 additions & 0 deletions src/script/lua_api/l_mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/script/lua_api/l_mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a5bdfb6

Please sign in to comment.