summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockCrops.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks/BlockCrops.h')
-rw-r--r--src/Blocks/BlockCrops.h25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h
index 0d6296a33..0dc0ebbb8 100644
--- a/src/Blocks/BlockCrops.h
+++ b/src/Blocks/BlockCrops.h
@@ -90,27 +90,24 @@ 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
+ virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) override
{
- NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
-
- // 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 < RipeMeta) && (Action == paGrowth))
- {
- a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++Meta);
- }
- else if (Action == paDeath)
+ auto oldMeta = a_Chunk.GetMeta(a_RelPos);
+ if (oldMeta >= RipeMeta)
{
- a_Chunk.GetWorld()->DigBlock(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width);
+ // Already ripe
+ return 0;
}
+ auto newMeta = std::min<int>(oldMeta + a_NumStages, RipeMeta);
+ ASSERT(newMeta > oldMeta);
+ a_Chunk.GetWorld()->SetBlock(a_Chunk.RelativeToAbsolute(a_RelPos), m_BlockType, static_cast<NIBBLETYPE>(newMeta));
+ return newMeta - oldMeta;
}
+
+
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND));