From 0649419485ddfed485e409c1bed401ac6635aa04 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 21 Feb 2025 19:35:37 +0300 Subject: [PATCH] randomize rotatable plants in world generation --- src/voxels/Block.cpp | 9 ++++++--- src/voxels/Block.hpp | 1 + src/world/generator/WorldGenerator.cpp | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index 3aee8606..7f08b3a7 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -101,7 +101,8 @@ const BlockRotProfile BlockRotProfile::NONE { {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // West {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // Up {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // Down - } + }, + 0 }; const BlockRotProfile BlockRotProfile::PIPE { @@ -113,7 +114,8 @@ const BlockRotProfile BlockRotProfile::PIPE { {{0, 0, -1}, {1, 0, 0}, {0, -1, 0}}, // West {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // Up {{1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, // Down - } + }, + 6 }; const BlockRotProfile BlockRotProfile::PANE { @@ -123,7 +125,8 @@ const BlockRotProfile BlockRotProfile::PANE { {{0, 0, -1}, {0, 1, 0}, {1, 0, 0}}, // East {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, // South {{0, 0, 1}, {0, 1, 0}, {-1, 0, 0}}, // West - } + }, + 4 }; Block::Block(const std::string& name) diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index b127a48b..a7b3aeb1 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -65,6 +65,7 @@ struct BlockRotProfile { static const int MAX_COUNT = 8; std::string name; CoordSystem variants[MAX_COUNT]; + int variantsCount; /// @brief No rotation static const BlockRotProfile NONE; diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index a86565ec..77c8cbeb 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -389,7 +389,12 @@ void WorldGenerator::generatePlants( } auto& groundVoxel = voxels[vox_index(x, height, z)]; if (indices.get(groundVoxel.id)->rt.solid) { + const auto& def = indices.require(plant); voxel = {plant, {}}; + if (def.rotatable && def.rotations.variantsCount) { + voxel.state.rotation = + plantsRand.rand() % def.rotations.variantsCount; + } } } }