Skip to content

Commit

Permalink
[TerrainGenerator] Fixed #134.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 2, 2020
1 parent 957ef30 commit c159626
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions source/server/world/TerrainGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,14 @@ void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
chunk.setBlockRaw(x, y, z, biome.getLiquidBlockID());
}
// Otherwise we are in the air
else {
// Try to place a tree
bool placedTree = tryPlaceTree(chunk, x, y, z, biome, rand);

// Otherwise try to place flora.
bool placedFlora = false;
if (!placedTree)
tryPlaceFlora(chunk, x, y, z, biome, rand);

// Or a portal
bool placedPortal = false;
if (!placedTree && !placedFlora)
tryPlacePortal(chunk, x, y, z, biome, rand);

// Otherwise set sunlight.
if (!placedTree && !placedFlora && !placedPortal && z == CHUNK_HEIGHT - 1) {
chunk.lightmap().addSunlight(x, y, z, 15);
}
else if (chunk.getBlock(x, y, z) == 0 && z == CHUNK_HEIGHT - 1) {
// Add sunlight at the top of the chunk if possible
chunk.lightmap().addSunlight(x, y, z, 15);
}
}
else {
if (z + chunk.z() * CHUNK_HEIGHT >= h - 1 && z + chunk.z() * CHUNK_HEIGHT > SEALEVEL - 1)
bool isGeneratingTopBlock = z + chunk.z() * CHUNK_HEIGHT >= h - 1 && z + chunk.z() * CHUNK_HEIGHT > SEALEVEL - 1;
if (isGeneratingTopBlock)
chunk.setBlockRaw(x, y, z, biome.getTopBlockID());
else if (z + chunk.z() * CHUNK_HEIGHT <= SEALEVEL - 1 && h < SEALEVEL && z + chunk.z() * CHUNK_HEIGHT > h - 3)
chunk.setBlockRaw(x, y, z, biome.getBeachBlockID());
Expand All @@ -103,6 +89,21 @@ void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {

// Caves
generateCaves(chunk, x, y, z, h);

// Generate trees, flora and portals
if (isGeneratingTopBlock && chunk.getBlock(x, y, z)) {
// Try to place a tree
bool placedTree = tryPlaceTree(chunk, x, y, z + 1, biome, rand);

// Otherwise try to place flora.
bool placedFlora = false;
if (!placedTree)
placedFlora = tryPlaceFlora(chunk, x, y, z + 1, biome, rand);

// Or a portal
if (!placedTree && !placedFlora)
tryPlacePortal(chunk, x, y, z + 1, biome, rand);
}
}

if (topChunk && topChunk->isInitialized()) {
Expand Down

0 comments on commit c159626

Please sign in to comment.