summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockCocoaPod.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-10-11 11:02:53 +0200
committerMattes D <github@xoft.cz>2019-10-28 10:45:43 +0100
commit61904af626b036b6e4e045ca219b2a361aa45a6e (patch)
tree60b99ab37c9ec87ca96d403b3254a4da023cf6ac /src/Blocks/BlockCocoaPod.h
parentUpdate README.md (#4423) (diff)
downloadcuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.gz
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.bz2
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.lz
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.xz
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.tar.zst
cuberite-61904af626b036b6e4e045ca219b2a361aa45a6e.zip
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);