summaryrefslogtreecommitdiffstats
path: root/src/Generating/FinishGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Generating/FinishGen.cpp')
-rw-r--r--src/Generating/FinishGen.cpp73
1 files changed, 59 insertions, 14 deletions
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index 4c40270e8..f53addb68 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -91,15 +91,55 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a
{
bool IsFireBlock = a_Block == E_BLOCK_FIRE;
- for (int x = a_RelX - 4; x < a_RelX + 4; x++)
+ int MinX = a_RelX - 4;
+ if (MinX < 0) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MinX = 0;
+ }
+
+ int MaxX = a_RelX + 4;
+ if (MaxX > cChunkDef::Width) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MaxX = cChunkDef::Width;
+ }
+
+ int MinZ = a_RelZ - 4;
+ if (MinZ < 0) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MinZ = 0;
+ }
+
+ int MaxZ = a_RelZ + 4;
+ if (MaxZ > cChunkDef::Width) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MaxZ = cChunkDef::Width;
+ }
+
+ int MinY = a_RelY - 2;
+ if (MinY < 0) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MinY = 0;
+ }
+
+ int MaxY = a_RelY + 2;
+ if (MaxY > cChunkDef::Height) // Check if the coordinate is outside the chunk. If it it then adjust it.
+ {
+ MaxY = cChunkDef::Height;
+ }
+
+ for (int x = MinX; x < MaxX; x++)
{
int xx = a_ChunkDesc.GetChunkX() * cChunkDef::Width + x;
- for (int z = a_RelZ - 4; z < a_RelZ + 4; z++)
+ for (int z = MinZ; z < MaxZ; z++)
{
int zz = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z;
- for (int y = a_RelY - 2; y < a_RelY + 2; y++)
+ for (int y = MinY; y < MaxY; y++)
{
- if ((y < 1) || (y > cChunkDef::Height))
+ if (
+ ((x < 0) || (x >= cChunkDef::Width)) ||
+ ((y < 0) || (y >= cChunkDef::Height)) ||
+ ((z < 0) || (z >= cChunkDef::Width))
+ )
{
continue;
}
@@ -110,7 +150,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a
}
BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z);
- if (!cBlockInfo::IsSolid(BlockBelow)) // Only place on solid blocks
+ if (!cBlockInfo::FullyOccupiesVoxel(BlockBelow)) // Only place on solid blocks
{
continue;
}
@@ -423,14 +463,14 @@ void cFinishGenIce::GenFinish(cChunkDesc & a_ChunkDesc)
////////////////////////////////////////////////////////////////////////////////
-// cFinishGenLilypads:
+// cFinishGenSingleTopBlock:
-int cFinishGenSingleBiomeSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap)
+int cFinishGenSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap)
{
int res = 0;
for (size_t i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
{
- if (a_BiomeMap[i] == m_Biome)
+ if (IsAllowedBiome(a_BiomeMap[i]))
{
res++;
}
@@ -442,7 +482,7 @@ int cFinishGenSingleBiomeSingleTopBlock::GetNumToGen(const cChunkDef::BiomeMap &
-void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
+void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
{
// Add Lilypads on top of water surface in Swampland
@@ -455,11 +495,13 @@ void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
int z = (m_Noise.IntNoise3DInt(ChunkX - ChunkZ, i, ChunkZ) / 11) % cChunkDef::Width;
// Place the block at {x, z} if possible:
- if (a_ChunkDesc.GetBiome(x, z) != m_Biome)
+ EMCSBiome Biome = a_ChunkDesc.GetBiome(x, z);
+ if (!IsAllowedBiome(Biome))
{
// Incorrect biome
continue;
}
+
int Height = a_ChunkDesc.GetHeight(x, z);
if (Height >= cChunkDef::Height)
{
@@ -471,13 +513,16 @@ void cFinishGenSingleBiomeSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc)
// Not an empty block
continue;
}
+
BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, Height, z);
- if ((BlockBelow == m_AllowedBelow1) || (BlockBelow == m_AllowedBelow2))
+ if (!IsAllowedBlockBelow(BlockBelow))
{
- a_ChunkDesc.SetBlockType(x, Height + 1, z, m_BlockType);
- a_ChunkDesc.SetHeight(x, z, Height + 1);
+ continue;
}
- } // for i
+
+ a_ChunkDesc.SetBlockType(x, Height + 1, z, m_BlockType);
+ a_ChunkDesc.SetHeight(x, z, Height + 1);
+ }
}