aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-12-03 10:40:46 -0500
committerGitHub <noreply@github.com>2022-12-03 10:40:46 -0500
commitb3ffc4b327622bec63793476191b95bc174bf33c (patch)
treef528352d914b5aacb8b4d8b31f2e702efe18d0dc /src/script/lua_api
parente84d259ec7fcc00466bd947070cb4ed77cd83c52 (diff)
downloadminetest-b3ffc4b327622bec63793476191b95bc174bf33c.tar.xz
Add `minetest.get_mapgen_edges` (#12999)
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mapgen.cpp36
-rw-r--r--src/script/lua_api/l_mapgen.h3
2 files changed, 39 insertions, 0 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 1e4197df3..2e17d0d67 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -810,6 +810,41 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L)
return 0;
}
+// get_mapgen_edges([mapgen_limit[, chunksize]])
+int ModApiMapgen::l_get_mapgen_edges(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ MapSettingsManager *settingsmgr = getServer(L)->getEmergeManager()->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.
+
+ s16 mapgen_limit;
+ if (lua_isnumber(L, 1)) {
+ mapgen_limit = lua_tointeger(L, 1);
+ } else {
+ std::string mapgen_limit_str;
+ settingsmgr->getMapSetting("mapgen_limit", &mapgen_limit_str);
+ mapgen_limit = stoi(mapgen_limit_str, 0, MAX_MAP_GENERATION_LIMIT);
+ }
+
+ s16 chunksize;
+ if (lua_isnumber(L, 2)) {
+ chunksize = lua_tointeger(L, 2);
+ } else {
+ std::string chunksize_str;
+ settingsmgr->getMapSetting("chunksize", &chunksize_str);
+ chunksize = stoi(chunksize_str, -32768, 32767);
+ }
+
+ std::pair<s16, s16> edges = get_mapgen_edges(mapgen_limit, chunksize);
+ push_v3s16(L, v3s16(1, 1, 1) * edges.first);
+ push_v3s16(L, v3s16(1, 1, 1) * edges.second);
+ return 2;
+}
+
// get_mapgen_setting(name)
int ModApiMapgen::l_get_mapgen_setting(lua_State *L)
{
@@ -1782,6 +1817,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_setting);
API_FCT(set_mapgen_setting);
API_FCT(get_mapgen_setting_noiseparams);
diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h
index 0bdc56fc5..1428a91c8 100644
--- a/src/script/lua_api/l_mapgen.h
+++ b/src/script/lua_api/l_mapgen.h
@@ -61,6 +61,9 @@ private:
// set mapgen parameters
static int l_set_mapgen_params(lua_State *L);
+ // get_mapgen_edges([mapgen_limit[, chunksize]])
+ static int l_get_mapgen_edges(lua_State *L);
+
// get_mapgen_setting(name)
static int l_get_mapgen_setting(lua_State *L);