From 16fac768c82639c2c5be452d10ab9991eba0ec18 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 29 Sep 2024 23:39:42 +0300 Subject: [PATCH] add chunk_height parameter to place_structures --- res/content/base/generators/demo.files/script.lua | 6 +++--- src/logic/scripting/scripting_world_generation.cpp | 5 +++-- src/world/generator/GeneratorDef.hpp | 3 ++- src/world/generator/WorldGenerator.cpp | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/res/content/base/generators/demo.files/script.lua b/res/content/base/generators/demo.files/script.lua index 73c4698d..98ccc785 100644 --- a/res/content/base/generators/demo.files/script.lua +++ b/res/content/base/generators/demo.files/script.lua @@ -1,10 +1,10 @@ -function place_structures(x, z, w, d, seed, hmap) +function place_structures(x, z, w, d, seed, hmap, chunk_height) local placements = {} for i=1,10 do local sx = math.random() * w local sz = math.random() * d - local sy = math.random() * 128 - if sy < hmap:at(sx, sz) * 256 - 6 then + local sy = math.random() * (chunk_height * 0.5) + if sy < hmap:at(sx, sz) * chunk_height - 6 then table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4}) end end diff --git a/src/logic/scripting/scripting_world_generation.cpp b/src/logic/scripting/scripting_world_generation.cpp index ff7175a0..4ee87116 100644 --- a/src/logic/scripting/scripting_world_generation.cpp +++ b/src/logic/scripting/scripting_world_generation.cpp @@ -76,7 +76,7 @@ public: std::vector placeStructures( const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, - const std::shared_ptr& heightmap + const std::shared_ptr& heightmap, uint chunkHeight ) override { std::vector placements; @@ -88,7 +88,8 @@ public: lua::pushivec_stack(L, size); lua::pushinteger(L, seed); lua::newuserdata(L, heightmap); - if (lua::call_nothrow(L, 6, 1)) { + lua::pushinteger(L, chunkHeight); + if (lua::call_nothrow(L, 7, 1)) { int len = lua::objlen(L, -1); for (int i = 1; i <= len; i++) { lua::rawgeti(L, i); diff --git a/src/world/generator/GeneratorDef.hpp b/src/world/generator/GeneratorDef.hpp index 02d9bc69..630f7400 100644 --- a/src/world/generator/GeneratorDef.hpp +++ b/src/world/generator/GeneratorDef.hpp @@ -155,10 +155,11 @@ public: /// @param size size of the area (blocks) /// @param seed world seed /// @param heightmap area heightmap + /// @param chunkHeight chunk height to use as heights multiplier /// @return structure placements virtual std::vector placeStructures( const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed, - const std::shared_ptr& heightmap) = 0; + const std::shared_ptr& heightmap, uint chunkHeight) = 0; }; /// @brief Structure voxel fragments and metadata diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index b70fae35..2043b7a7 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -177,7 +177,7 @@ void WorldGenerator::generateStructures( util::concat(prototype.structures, def.script->placeStructures( {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed, - heightmap + heightmap, CHUNK_H )); for (const auto& placement : prototype.structures) { const auto& offset = placement.position;