summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockCocoaPod.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks/BlockCocoaPod.h')
-rw-r--r--src/Blocks/BlockCocoaPod.h53
1 files changed, 41 insertions, 12 deletions
diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h
index 2d5243995..f9b7fbd36 100644
--- a/src/Blocks/BlockCocoaPod.h
+++ b/src/Blocks/BlockCocoaPod.h
@@ -10,12 +10,18 @@
class cBlockCocoaPodHandler :
public cBlockHandler
{
+ using super = cBlockHandler;
+
public:
- cBlockCocoaPodHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+ cBlockCocoaPodHandler(BLOCKTYPE a_BlockType):
+ super(a_BlockType)
{
}
+
+
+
+
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
eBlockFace BlockFace = MetaToBlockFace(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
@@ -28,19 +34,15 @@ public:
return ((BlockType == E_BLOCK_LOG) && ((BlockMeta & 0x3) == E_META_LOG_JUNGLE));
}
+
+
+
+
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
if (GetRandomProvider().RandBool(0.20))
{
- NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
- NIBBLETYPE TypeMeta = Meta & 0x03;
- int GrowState = Meta >> 2;
-
- if (GrowState < 2)
- {
- ++GrowState;
- a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, static_cast<NIBBLETYPE>(GrowState << 2 | TypeMeta));
- }
+ Grow(a_Chunk, {a_RelX, a_RelY, a_RelZ});
}
}
@@ -59,9 +61,28 @@ public:
+ virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) override
+ {
+ auto meta = a_Chunk.GetMeta(a_RelPos);
+ auto typeMeta = meta & 0x03;
+ auto growState = meta >> 2;
+
+ if (growState >= 3)
+ {
+ return 0;
+ }
+ auto newState = std::min(growState + a_NumStages, 3);
+ a_Chunk.SetMeta(a_RelPos, static_cast<NIBBLETYPE>(newState << 2 | typeMeta));
+ return newState - growState;
+ }
+
+
+
+
+
static eBlockFace MetaToBlockFace(NIBBLETYPE a_Meta)
{
- switch (a_Meta & 0x3)
+ switch (a_Meta & 0x03)
{
case 0: return BLOCK_FACE_ZM;
case 1: return BLOCK_FACE_XP;
@@ -75,6 +96,10 @@ public:
}
}
+
+
+
+
static NIBBLETYPE BlockFaceToMeta(eBlockFace a_BlockFace)
{
switch (a_BlockFace)
@@ -94,6 +119,10 @@ public:
UNREACHABLE("Unsupported block face");
}
+
+
+
+
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);