Skip to content

Commit

Permalink
randomize rotatable plants in world generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Feb 21, 2025
1 parent 721286c commit 0649419
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/voxels/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/voxels/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/world/generator/WorldGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit 0649419

Please sign in to comment.