From 52d5760be17235a1811e9a26ce849c4a33afad72 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 30 Mar 2020 18:23:25 +0100 Subject: Add helper functions to get combined light from cChunk These are now used for plant growth --- src/Blocks/BlockGrass.h | 6 ++---- src/Blocks/BlockPlant.h | 17 +++++------------ 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src/Blocks') diff --git a/src/Blocks/BlockGrass.h b/src/Blocks/BlockGrass.h index 0e54cb092..341a44b07 100644 --- a/src/Blocks/BlockGrass.h +++ b/src/Blocks/BlockGrass.h @@ -60,9 +60,8 @@ public: return; } - NIBBLETYPE light = std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ))); // Source block is not bright enough to spread - if (light < 9) + if (a_Chunk.GetLightAltered(Vector3i(a_RelX, a_RelY + 1, a_RelZ)) < 9) { return; } @@ -99,8 +98,7 @@ public: } auto abovePos = pos.addedY(1); BLOCKTYPE above = chunk->GetBlock(abovePos); - NIBBLETYPE light = std::max(chunk->GetBlockLight(abovePos), chunk->GetTimeAlteredLight(chunk->GetSkyLight(abovePos))); - if ((light > 4) && + if ((a_Chunk.GetLightAltered(abovePos) > 4) && cBlockInfo::IsTransparent(above) && (!IsBlockLava(above)) && (!IsBlockWaterOrIce(above)) diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h index 0e249bbde..d71614cdb 100644 --- a/src/Blocks/BlockPlant.h +++ b/src/Blocks/BlockPlant.h @@ -77,26 +77,19 @@ protected: { return paGrowth; } - NIBBLETYPE Blocklight = a_Chunk.GetBlockLight(a_RelPos); - NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelPos); - NIBBLETYPE Light = a_Chunk.GetTimeAlteredLight(SkyLight); - - // If the amount of light provided by blocks is greater than the sky light, use it instead - if (Blocklight > Light) - { - Light = Blocklight; - } // Based on light levels, decide between growth, stay and death: - if (Light > 8) + // Grow if the combined adjusted light above is bright enough. + if (a_Chunk.GetLightAltered(a_RelPos + Vector3i(0, 1, 0)) > 8) { return paGrowth; } - else if ((Blocklight < 9) && (SkyLight < 9)) + // Die if the combined non-adjusted light inside is dark enough. + if (a_Chunk.GetLight(a_RelPos) < 8) { return paDeath; } - + // Otherwise stay the same. return paStay; } -- cgit v1.2.3