From 02f40e5b0dfbbb3a7f0f08a7eecb4a14c06702ee Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 22 Jul 2024 16:31:46 +0200 Subject: [PATCH] Fix blockseed for on_generated in mapgen env --- src/emerge.cpp | 2 +- src/emerge.h | 1 + src/mapgen/mapgen.h | 2 ++ src/script/cpp_api/s_mapgen.cpp | 4 ++-- src/script/cpp_api/s_mapgen.h | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/emerge.cpp b/src/emerge.cpp index b53f298b3..425e294b8 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -692,7 +692,7 @@ void *EmergeThread::run() "EmergeThread: Lua on_generated", SPT_AVG); try { - m_script->on_generated(&bmdata); + m_script->on_generated(&bmdata, m_mapgen->blockseed); } catch (const LuaError &e) { m_server->setAsyncFatalError(e); error = true; diff --git a/src/emerge.h b/src/emerge.h index 4718637ad..d7f018feb 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -50,6 +50,7 @@ class ModApiMapgen; // Structure containing inputs/outputs for chunk generation struct BlockMakeData { MMVManip *vmanip = nullptr; + // Global map seed u64 seed = 0; v3s16 blockpos_min; v3s16 blockpos_max; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index d2d21a9fc..7a3808da3 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -167,6 +167,7 @@ private: */ class Mapgen { public: + // Seed used for noises (truncated from the map seed) s32 seed = 0; int water_level = 0; int mapgen_limit = 0; @@ -180,6 +181,7 @@ public: EmergeParams *m_emerge = nullptr; const NodeDefManager *ndef = nullptr; + // Chunk-specific seed used to place ores and decorations u32 blockseed; s16 *heightmap = nullptr; biome_t *biomemap = nullptr; diff --git a/src/script/cpp_api/s_mapgen.cpp b/src/script/cpp_api/s_mapgen.cpp index c363ce2c2..f50e95159 100644 --- a/src/script/cpp_api/s_mapgen.cpp +++ b/src/script/cpp_api/s_mapgen.cpp @@ -45,7 +45,7 @@ void ScriptApiMapgen::on_shutdown() runCallbacks(0, RUN_CALLBACKS_MODE_FIRST); } -void ScriptApiMapgen::on_generated(BlockMakeData *bmdata) +void ScriptApiMapgen::on_generated(BlockMakeData *bmdata, u32 seed) { SCRIPTAPI_PRECHECKHEADER @@ -66,7 +66,7 @@ void ScriptApiMapgen::on_generated(BlockMakeData *bmdata) lua_pushvalue(L, vmanip); push_v3s16(L, minp); push_v3s16(L, maxp); - lua_pushnumber(L, bmdata->seed); + lua_pushnumber(L, seed); runCallbacks(4, RUN_CALLBACKS_MODE_FIRST); lua_pop(L, 1); // return val diff --git a/src/script/cpp_api/s_mapgen.h b/src/script/cpp_api/s_mapgen.h index e881ca04a..08786f99e 100644 --- a/src/script/cpp_api/s_mapgen.h +++ b/src/script/cpp_api/s_mapgen.h @@ -35,6 +35,6 @@ public: void on_mods_loaded(); void on_shutdown(); - // Called after generating a piece of map before writing it to the map - void on_generated(BlockMakeData *bmdata); + // Called after generating a piece of map, before writing it to the map + void on_generated(BlockMakeData *bmdata, u32 seed); };