]> git.lizzy.rs Git - minetest.git/commitdiff
Biome API: Add 'get_biome_name(biome_id)' API
authorparamat <paramat@users.noreply.github.com>
Fri, 9 Mar 2018 23:16:23 +0000 (23:16 +0000)
committerparamat <mat.gregory@virginmedia.com>
Sun, 11 Mar 2018 23:06:17 +0000 (23:06 +0000)
Change name of default biome to a more suitable lowercase 'default'.

doc/lua_api.txt
src/mapgen/mg_biome.cpp
src/script/lua_api/l_mapgen.cpp
src/script/lua_api/l_mapgen.h

index 65e1a4eacb9e63a32151747626727c1ea108e710..9e9356be6d061f554ad629ea6278950bfd2bed54 100644 (file)
@@ -2959,6 +2959,10 @@ handler.
 * `minetest.get_biome_id(biome_name)`
     * Returns the biome id, as used in the biomemap Mapgen object and returned
       by `minetest.get_biome_data(pos)`, for a given biome_name string.
+* `minetest.get_biome_name(biome_id)`
+    * Returns the biome name string for the provided biome id, or `nil` on
+      failure.
+    * If no biomes have been registered, such as in mgv6, returns `default`.
 * `minetest.get_mapgen_params()`
     * Deprecated: use `minetest.get_mapgen_setting(name)` instead.
     * Returns a table containing:
index 38017ea9da4177c5d470ee447d99fd323bbc49a7..376f2d4483aedf3e3a47534bb1bf7f060232ea9e 100644 (file)
@@ -40,7 +40,7 @@ BiomeManager::BiomeManager(Server *server) :
        // Create default biome to be used in case none exist
        Biome *b = new Biome;
 
-       b->name            = "Default";
+       b->name            = "default";
        b->flags           = 0;
        b->depth_top       = 0;
        b->depth_filler    = -MAX_MAP_GENERATION_LIMIT;
index f5c76ec6e827e49a6cac0facf64c8e2598ccee87..263273cc34ab30d850ad579d258f4d3125cc7914 100644 (file)
@@ -476,12 +476,10 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
                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;
 
@@ -491,6 +489,25 @@ int ModApiMapgen::l_get_biome_id(lua_State *L)
 }
 
 
+// get_biome_name(biome_id)
+// returns the biome name string
+int ModApiMapgen::l_get_biome_name(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+
+       int biome_id = luaL_checkinteger(L, 1);
+
+       BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr;
+       if (!bmgr)
+               return 0;
+
+       Biome *b = (Biome *)bmgr->getRaw(biome_id);
+       lua_pushstring(L, b->name.c_str());
+
+       return 1;
+}
+
+
 // get_heat(pos)
 // returns the heat at the position
 int ModApiMapgen::l_get_heat(lua_State *L)
@@ -1731,6 +1748,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_biome_name);
        API_FCT(get_heat);
        API_FCT(get_humidity);
        API_FCT(get_biome_data);
index aebbcbac6c13e064dcaea048d55b1bbdee325bc4..1339791f389e75286d0ceb9d41e0c91816f6171f 100644 (file)
@@ -28,6 +28,10 @@ class ModApiMapgen : public ModApiBase
        // returns the biome id as used in biomemap and returned by 'get_biome_data()'
        static int l_get_biome_id(lua_State *L);
 
+       // get_biome_name(biome_id)
+       // returns the biome name string
+       static int l_get_biome_name(lua_State *L);
+
        // get_heat(pos)
        // returns the heat at the position
        static int l_get_heat(lua_State *L);