From 6bdd130aab51b630918ed664c4389cf33bcb2e06 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jul 2020 19:30:38 +0100 Subject: OnBroken/OnPlaced are for entity actions * Call OnPlaced/OnBroken in PlaceBlock/DigBlock - Remove unused Placing/Breaking handlers * Have the blockhandler's Check handle neighbour updating, instead of QueueTickBlockNeighbors --- src/Blocks/BlockConcretePowder.h | 67 ++++++++++++---------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) (limited to 'src/Blocks/BlockConcretePowder.h') diff --git a/src/Blocks/BlockConcretePowder.h b/src/Blocks/BlockConcretePowder.h index d3133a571..7cd99149e 100644 --- a/src/Blocks/BlockConcretePowder.h +++ b/src/Blocks/BlockConcretePowder.h @@ -19,66 +19,41 @@ public: { } - - - - - virtual void Check( - cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, - Vector3i a_RelPos, - cChunk & a_Chunk + virtual void OnPlaced( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, + Vector3i a_BlockPos, + BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) override { - if (GetSoaked(a_RelPos, a_Chunk)) - { - return; - } - Super::Check(a_ChunkInterface, a_PluginInterface, a_RelPos, a_Chunk); + OnNeighborChanged(a_ChunkInterface, a_BlockPos, BLOCK_FACE_NONE); } + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) override + { + a_ChunkInterface.DoWithChunkAt(a_BlockPos, [&](cChunk & a_Chunk) { CheckSoaked(a_Chunk.AbsoluteToRelative(a_BlockPos), a_Chunk); return true; }); + } - - - - /** Check blocks above and around to see if they are water. If one is, converts this into concrete block. - Returns true if the block was changed. */ - bool GetSoaked(Vector3i a_Rel, cChunk & a_Chunk) + /** Check blocks above and around to see if they are water. If one is, converts this into concrete block. */ + void CheckSoaked(Vector3i a_Rel, cChunk & a_Chunk) { - static const std::array WaterCheck + const auto & WaterCheck = cSimulator::AdjacentOffsets; + const bool ShouldSoak = std::any_of(WaterCheck.cbegin(), WaterCheck.cend(), [a_Rel, & a_Chunk](Vector3i a_Offset) { - { - { 1, 0, 0}, - {-1, 0, 0}, - { 0, 0, 1}, - { 0, 0, -1}, - { 0, 1, 0}, - } - }; - - bool ShouldSoak = std::any_of(WaterCheck.cbegin(), WaterCheck.cend(), [a_Rel, & a_Chunk](Vector3i a_Offset) - { - BLOCKTYPE NeighborType; - return ( - a_Chunk.UnboundedRelGetBlockType(a_Rel.x + a_Offset.x, a_Rel.y + a_Offset.y, a_Rel.z + a_Offset.z, NeighborType) - && IsBlockWater(NeighborType) - ); - } - ); + BLOCKTYPE NeighborType; + return ( + a_Chunk.UnboundedRelGetBlockType(a_Rel.x + a_Offset.x, a_Rel.y + a_Offset.y, a_Rel.z + a_Offset.z, NeighborType) + && IsBlockWater(NeighborType) + ); + }); if (ShouldSoak) { NIBBLETYPE BlockMeta; BlockMeta = a_Chunk.GetMeta(a_Rel.x, a_Rel.y, a_Rel.z); a_Chunk.SetBlock(a_Rel, E_BLOCK_CONCRETE, BlockMeta); - return true; } - return false; } - - - - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override { switch (a_Meta) @@ -107,7 +82,3 @@ public: } } }; - - - - -- cgit v1.2.3