summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockSugarcane.h
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2015-08-19 19:05:30 +0200
committerSamuel Barney <samjbarney@gmail.com>2015-08-19 19:05:30 +0200
commitb5ed23d2a6696586b70b11a1bed51f4565079e5d (patch)
treed4c4ebe5a88eaeba8ce9d53122c9eb92e297870c /src/Blocks/BlockSugarcane.h
parentMerge pull request #2439 from cuberite/AppveyorYml (diff)
parent* Logic for handling plant growth has been centralized into cBlockPlant, and all growable plants now inherit from it. (diff)
downloadcuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar.gz
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar.bz2
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar.lz
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar.xz
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.tar.zst
cuberite-b5ed23d2a6696586b70b11a1bed51f4565079e5d.zip
Diffstat (limited to 'src/Blocks/BlockSugarcane.h')
-rw-r--r--src/Blocks/BlockSugarcane.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h
index 632dc8baa..2b4c9e583 100644
--- a/src/Blocks/BlockSugarcane.h
+++ b/src/Blocks/BlockSugarcane.h
@@ -1,18 +1,19 @@
#pragma once
-#include "BlockHandler.h"
+#include "BlockPlant.h"
class cBlockSugarcaneHandler :
- public cBlockHandler
+ public cBlockPlant
{
+ typedef cBlockPlant Super;
public:
cBlockSugarcaneHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ : Super(a_BlockType, false)
{
}
@@ -73,7 +74,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()->GrowSugarcane(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()->GrowSugarcane(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1);
+ }
}
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
@@ -81,6 +85,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;
+ }
} ;