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/BlockCactus.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/Blocks/BlockCactus.h') diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index cb6cecc7b..29e86d085 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -1,18 +1,19 @@ #pragma once -#include "BlockHandler.h" +#include "BlockPlant.h" class cBlockCactusHandler : - public cBlockHandler + public cBlockPlant { + typedef cBlockPlant Super; public: cBlockCactusHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : Super(a_BlockType, false) { } @@ -64,7 +65,10 @@ public: virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override { - a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1); + if (CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ) == paGrowth) + { + a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1); + } } virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override @@ -72,6 +76,19 @@ public: UNUSED(a_Meta); return 7; } + +protected: + + virtual PlantAction CanGrow(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + { + auto Action = paStay; + if (((a_RelY + 1) < cChunkDef::Height) && (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR)) + { + Action = Super::CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ); + } + + return Action; + } } ; -- cgit v1.2.3