1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
sfan5 2025-06-27 10:54:06 +00:00 committed by GitHub
commit 3c6bcd197b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 3 deletions

View file

@ -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:

View file

@ -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)

View file

@ -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<s16, s16> 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);

View file

@ -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);