diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-08 14:16:39 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-08 14:16:39 +0200 |
commit | fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b (patch) | |
tree | c382dcd205dfc8b2dd61005332709029181715f7 /source/FinishGen.cpp | |
parent | Configurable classic composition generator (diff) | |
download | cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar.gz cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar.bz2 cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar.lz cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar.xz cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.tar.zst cuberite-fbabf9ee8c7f0940e6f7d01e0362849bf4f6396b.zip |
Diffstat (limited to 'source/FinishGen.cpp')
-rw-r--r-- | source/FinishGen.cpp | 89 |
1 files changed, 84 insertions, 5 deletions
diff --git a/source/FinishGen.cpp b/source/FinishGen.cpp index f4eb5ab10..9761d4373 100644 --- a/source/FinishGen.cpp +++ b/source/FinishGen.cpp @@ -17,9 +17,70 @@ +static inline bool IsWater(BLOCKTYPE a_BlockType)
+{
+ return (a_BlockType == E_BLOCK_STATIONARY_WATER) || (a_BlockType == E_BLOCK_WATER);
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cFinishGenSprinkleFoliage:
+bool cFinishGenSprinkleFoliage::TryAddSugarcane(
+ int a_ChunkX, int a_ChunkZ,
+ int a_RelX, int a_RelY, int a_RelZ,
+ cChunkDef::BlockTypes & a_BlockTypes,
+ cChunkDef::BlockNibbles & a_BlockMeta
+)
+{
+ // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges:
+ if (
+ (a_RelX < 1) || (a_RelX >= cChunkDef::Width - 1) ||
+ (a_RelY < 1) || (a_RelY >= cChunkDef::Height - 2) ||
+ (a_RelZ < 1) || (a_RelZ >= cChunkDef::Width - 1)
+ )
+ {
+ return false;
+ }
+
+ // Only allow dirt, grass or sand below sugarcane:
+ switch (cChunkDef::GetBlock(a_BlockTypes, a_RelX, a_RelY, a_RelZ))
+ {
+ case E_BLOCK_DIRT:
+ case E_BLOCK_GRASS:
+ case E_BLOCK_SAND:
+ {
+ break;
+ }
+ default:
+ {
+ return false;
+ }
+ }
+
+ // Water is required next to the block below the sugarcane:
+ if (
+ !IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX - 1, a_RelY, a_RelZ)) &&
+ !IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX + 1, a_RelY, a_RelZ)) &&
+ !IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX , a_RelY, a_RelZ - 1)) &&
+ !IsWater(cChunkDef::GetBlock(a_BlockTypes, a_RelX , a_RelY, a_RelZ + 1))
+ )
+ {
+ return false;
+ }
+
+ // All conditions met, place a sugarcane here:
+ cChunkDef::SetBlock(a_BlockTypes, a_RelX, a_RelY + 1, a_RelZ, E_BLOCK_SUGARCANE);
+ return true;
+}
+
+
+
+
+
void cFinishGenSprinkleFoliage::GenFinish(
int a_ChunkX, int a_ChunkZ,
cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
@@ -88,18 +149,36 @@ void cFinishGenSprinkleFoliage::GenFinish( cChunkDef::SetBlock (a_BlockTypes, x, ++Top, z, E_BLOCK_TALL_GRASS);
cChunkDef::SetNibble(a_BlockMeta, x, Top, z, E_META_TALL_GRASS_GRASS);
}
+ else if (TryAddSugarcane(a_ChunkX, a_ChunkZ, x, Top, z, a_BlockTypes, a_BlockMeta))
+ {
+ ++Top;
+ }
+ else if ((val1 > 0.5) && (val2 < -0.5))
+ {
+ cChunkDef::SetBlock (a_BlockTypes, x, ++Top, z, E_BLOCK_PUMPKIN);
+ cChunkDef::SetNibble(a_BlockMeta, x, Top, z, (int)(val3 * 8) % 4);
+ }
break;
} // case E_BLOCK_GRASS
case E_BLOCK_SAND:
{
- if (val1 + val2 > 0.f)
+ int y = Top + 1;
+ if (
+ (x > 0) && (x < cChunkDef::Width - 1) &&
+ (z > 0) && (z < cChunkDef::Width - 1) &&
+ (val1 + val2 > 0.5f) &&
+ (cChunkDef::GetBlock(a_BlockTypes, x + 1, y, z) == E_BLOCK_AIR) &&
+ (cChunkDef::GetBlock(a_BlockTypes, x - 1, y, z) == E_BLOCK_AIR) &&
+ (cChunkDef::GetBlock(a_BlockTypes, x, y, z + 1) == E_BLOCK_AIR) &&
+ (cChunkDef::GetBlock(a_BlockTypes, x, y, z - 1) == E_BLOCK_AIR)
+ )
{
cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_CACTUS);
- if (val1 > val2)
- {
- cChunkDef::SetBlock(a_BlockTypes, x, ++Top, z, E_BLOCK_CACTUS);
- }
+ }
+ else if (TryAddSugarcane(a_ChunkX, a_ChunkZ, x, Top, z, a_BlockTypes, a_BlockMeta))
+ {
+ ++Top;
}
break;
}
|