diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-07-29 20:30:38 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-04 19:15:18 +0200 |
commit | 6bdd130aab51b630918ed664c4389cf33bcb2e06 (patch) | |
tree | eed35c8716f9ea18afe8fd909c09e8595928a671 /src/Blocks/BlockConcretePowder.h | |
parent | Do not GetBlock individually in simulators (diff) | |
download | cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar.gz cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar.bz2 cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar.lz cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar.xz cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.tar.zst cuberite-6bdd130aab51b630918ed664c4389cf33bcb2e06.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockConcretePowder.h | 67 |
1 files changed, 19 insertions, 48 deletions
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<Vector3i, 5> 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: } } }; - - - - |