mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: grass (#11)
* feat: add grass texture and update grass_block texture * feat: add block data * feat: add blocks_tool * feat: add sync info and change function in blocks_tools * feat: add check and new function * refactor: make block texture loading data-driven * feat: add rendering for grass * feat: passable grass * feat: random grass place * fix: memory leak in TextureManager::load_cross_plane_texture
This commit is contained in:
@@ -15,5 +15,28 @@ void BiomeBuilder::build_bottom() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BiomeBuilder::place_grass() {
|
||||
ChunkGenerator& chunk_generator = get_chunk_generator();
|
||||
Chunk& chunk = chunk_generator.chunk();
|
||||
auto& blocks = chunk.blocks();
|
||||
const auto& heightmap = chunk.get_heightmap();
|
||||
auto& random = chunk_generator.random();
|
||||
for (int x = 0; x < SIZE_X; ++x) {
|
||||
for (int z = 0; z < SIZE_Z; ++z) {
|
||||
int y = heightmap[x][z];
|
||||
BlockType top_id = blocks[Chunk::index(x, y, z)];
|
||||
if (top_id != 1) {
|
||||
continue;
|
||||
}
|
||||
if (blocks[Chunk::index(x, y + 1, z)] != 0) {
|
||||
continue;
|
||||
}
|
||||
if (random.random_bool(0.2)) {
|
||||
if (y + 1 < SIZE_Y) {
|
||||
blocks[Chunk::index(x, y + 1, z)] = 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user