diff --git a/doc/lua_api.md b/doc/lua_api.md index 438769085..8f11507ad 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -6666,6 +6666,8 @@ Environment access of the *active* mapgen setting `"mapgen_limit"`. * `chunksize` is an optional number. If it is absent, its value is that of the *active* mapgen setting `"chunksize"`. +* `core.get_mapgen_chunksize()` + * Returns the currently active chunksize of the mapgen, as a vector. * `core.get_mapgen_setting(name)` * Gets the *active* mapgen setting (or nil if none exists) in string format with the following order of precedence: diff --git a/games/devtest/mods/unittests/inside_mapgen_env.lua b/games/devtest/mods/unittests/inside_mapgen_env.lua index f6f8513ce..f92465cc5 100644 --- a/games/devtest/mods/unittests/inside_mapgen_env.lua +++ b/games/devtest/mods/unittests/inside_mapgen_env.lua @@ -29,6 +29,6 @@ if core.ipc_cas("unittests:mg_once", nil, true) then end core.register_on_generated(function(vm, pos1, pos2, blockseed) - local n = tonumber(core.get_mapgen_setting("chunksize")) * 16 - 1 - assert(pos2:subtract(pos1) == vector.new(n, n, n)) + local cs = core.get_mapgen_chunksize() + assert(pos2:subtract(pos1) == cs:multiply(core.MAP_BLOCKSIZE):subtract(1)) end) diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 49c28172b..16fa1760e 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -865,7 +865,7 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L) } else { std::string chunksize_str; settingsmgr->getMapSetting("chunksize", &chunksize_str); - chunksize = stoi(chunksize_str, -32768, 32767); + chunksize = stoi(chunksize_str, 1, 10); } std::pair edges = get_mapgen_edges(mapgen_limit, chunksize); @@ -874,6 +874,25 @@ int ModApiMapgen::l_get_mapgen_edges(lua_State *L) return 2; } +// get_mapgen_chunksize() +int ModApiMapgen::l_get_mapgen_chunksize(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + const MapSettingsManager *settingsmgr = getEmergeManager(L)->map_settings_mgr; + + // MapSettingsManager::makeMapgenParams cannot be used here because it would + // make mapgen settings immutable from then on. Mapgen settings should stay + // mutable until after mod loading ends. + + std::string chunksize_str; + settingsmgr->getMapSetting("chunksize", &chunksize_str); + s16 chunksize = stoi(chunksize_str, 1, 10); + + push_v3s16(L, {chunksize, chunksize, chunksize}); + return 1; +} + // get_mapgen_setting(name) int ModApiMapgen::l_get_mapgen_setting(lua_State *L) { @@ -2025,6 +2044,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top) API_FCT(get_mapgen_params); API_FCT(set_mapgen_params); API_FCT(get_mapgen_edges); + API_FCT(get_mapgen_chunksize); API_FCT(get_mapgen_setting); API_FCT(set_mapgen_setting); API_FCT(get_mapgen_setting_noiseparams); @@ -2067,6 +2087,7 @@ void ModApiMapgen::InitializeEmerge(lua_State *L, int top) API_FCT(get_seed); API_FCT(get_mapgen_params); API_FCT(get_mapgen_edges); + API_FCT(get_mapgen_chunksize); API_FCT(get_mapgen_setting); API_FCT(get_mapgen_setting_noiseparams); API_FCT(get_noiseparams); diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 860daa7e8..67c48a0b0 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -56,6 +56,9 @@ private: // get_mapgen_edges([mapgen_limit[, chunksize]]) static int l_get_mapgen_edges(lua_State *L); + // get_mapgen_chunksize() + static int l_get_mapgen_chunksize(lua_State *L); + // get_seed([add]) static int l_get_seed(lua_State *L);