From cc83c4641d50818bf4fd830653438515ed5264d3 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Wed, 19 Aug 2015 10:45:53 -0600 Subject: * Logic for handling plant growth has been centralized into cBlockPlant, and all growable plants now inherit from it. * Blocks now have an effect upon plant growth, just like in vanilla. --- src/Blocks/BlockCrops.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/Blocks/BlockCrops.h') diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index c54625561..9014f7046 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -1,7 +1,7 @@ #pragma once -#include "BlockHandler.h" +#include "BlockPlant.h" #include "../FastRandom.h" @@ -10,11 +10,12 @@ /** Common class that takes care of carrots, potatoes and wheat */ class cBlockCropsHandler : - public cBlockHandler + public cBlockPlant { + typedef cBlockPlant Super; public: cBlockCropsHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : Super(a_BlockType, true) { } @@ -82,12 +83,17 @@ public: { Light = SkyLight; } - - if ((Meta < 7) && (Light > 8)) + + // Check to see if the plant can grow + auto Action = CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ); + + // If there is still room to grow and the plant can grow, then grow. + // Otherwise if the plant needs to die, then dig it up + if ((Meta < 7) && (Action == paGrowth)) { a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++Meta); } - else if (Light < 9) + else if (Action == paDeath) { a_Chunk.GetWorld()->DigBlock(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width); } -- cgit v1.2.3