From 426a60320061f0d59b763b826c5dd5802fec68e8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 13 Dec 2014 13:12:35 +0100 Subject: Fixed grass spread --- src/Blocks/BlockDirt.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index aae6719e2..69768396b 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -55,29 +55,32 @@ public: // Grass spreads to adjacent dirt blocks: cFastRandom rand; - for (int i = 0; i < 2; i++) // Pick two blocks to grow to + for (int i = 0; i < 3; i++) // Pick three blocks to grow to { - int OfsX = rand.NextInt(3, a_RelX) - 1; // [-1 .. 1] - int OfsY = rand.NextInt(5, a_RelY) - 3; // [-3 .. 1] - int OfsZ = rand.NextInt(3, a_RelZ) - 1; // [-1 .. 1] - - BLOCKTYPE DestBlock; - NIBBLETYPE DestMeta; - if ((a_RelY + OfsY < 0) || (a_RelY + OfsY >= cChunkDef::Height - 1)) + int OfsX = rand.GenerateRandomInteger(-1, 1); + int OfsY = rand.GenerateRandomInteger(-3, 1); + int OfsZ = rand.GenerateRandomInteger(-1, 1); + int BlockX = a_RelX + OfsX; + int BlockY = a_RelY + OfsY; + int BlockZ = a_RelZ + OfsZ; + + if ((BlockY < 0) || (BlockY >= cChunkDef::Height)) { // Y Coord out of range continue; } - int BlockX = a_RelX + OfsX; - int BlockY = a_RelY + OfsY; - int BlockZ = a_RelZ + OfsZ; + cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(BlockX, BlockZ); if (Chunk == nullptr) { // Unloaded chunk continue; } + + BLOCKTYPE DestBlock; + NIBBLETYPE DestMeta; Chunk->GetBlockTypeMeta(BlockX, BlockY, BlockZ, DestBlock, DestMeta); + if ((DestBlock != E_BLOCK_DIRT) || (DestMeta != E_META_DIRT_NORMAL)) { // Not a regular dirt block -- cgit v1.2.3