summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockSponge.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Blocks/BlockSponge.h')
-rw-r--r--src/Blocks/BlockSponge.h79
1 files changed, 20 insertions, 59 deletions
diff --git a/src/Blocks/BlockSponge.h b/src/Blocks/BlockSponge.h
index 88981567a..2ef078ea1 100644
--- a/src/Blocks/BlockSponge.h
+++ b/src/Blocks/BlockSponge.h
@@ -19,44 +19,25 @@ 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 around the sponge to see if they are water.
If a dry sponge is touching water, soak up up to 65 blocks of water,
- with a taxicab distance of 7, and turn the sponge into a wet sponge.
- Returns TRUE if the block was changed. */
- bool GetSoaked(Vector3i a_Rel, cChunk & a_Chunk)
+ with a taxicab distance of 7, and turn the sponge into a wet sponge. */
+ void CheckSoaked(Vector3i a_Rel, cChunk & a_Chunk)
{
- static const std::array<Vector3i, 6> WaterCheck
- {
- {
- { 1, 0, 0},
- {-1, 0, 0},
- { 0, 0, 1},
- { 0, 0, -1},
- { 0, 1, 0},
- { 0, -1, 0},
- }
- };
struct sSeed
{
sSeed(Vector3i pos, int d)
@@ -68,27 +49,25 @@ public:
int m_Depth;
};
-
// Check if this is a dry sponge next to a water block.
NIBBLETYPE TargetMeta = a_Chunk.GetMeta(a_Rel.x, a_Rel.y, a_Rel.z);
if (TargetMeta != E_META_SPONGE_DRY)
{
- return false;
+ return;
}
- bool ShouldSoak = std::any_of(WaterCheck.cbegin(), WaterCheck.cend(), [a_Rel, & a_Chunk](Vector3i a_Offset)
- {
- return IsWet(a_Rel + a_Offset, a_Chunk);
- }
- );
+ const auto & WaterCheck = cSimulator::AdjacentOffsets;
+ const bool ShouldSoak = std::any_of(WaterCheck.cbegin(), WaterCheck.cend(), [a_Rel, &a_Chunk](Vector3i a_Offset)
+ {
+ return IsWet(a_Rel + a_Offset, a_Chunk);
+ });
// Early return if the sponge isn't touching any water.
- if (! ShouldSoak)
+ if (!ShouldSoak)
{
- return false;
+ return;
}
-
// Use a queue to hold blocks that we want to check, so our search is breadth-first.
std::queue<sSeed> Seeds;
int count = 0;
@@ -100,7 +79,6 @@ public:
Seeds.emplace(a_Rel + WaterCheck[i], maxDepth - 1);
}
-
// Keep checking blocks that are touching water blocks, or until 65 have been soaked up.
while (!Seeds.empty() && count < 65)
{
@@ -122,24 +100,16 @@ public:
}
Seeds.pop();
}
+
a_Chunk.SetBlock(a_Rel, E_BLOCK_SPONGE, E_META_SPONGE_WET);
- return true;
}
-
-
-
-
static void DryUp(Vector3i a_Rel, cChunk & a_Chunk)
{
// TODO: support evaporating waterlogged blocks.
a_Chunk.UnboundedRelSetBlock(a_Rel.x, a_Rel.y, a_Rel.z, E_BLOCK_AIR, 0);
}
-
-
-
-
static bool IsWet(Vector3i a_Rel, cChunk & a_Chunk)
{
// TODO: support detecting waterlogged blocks.
@@ -147,18 +117,9 @@ public:
return(a_Chunk.UnboundedRelGetBlockType(a_Rel.x, a_Rel.y, a_Rel.z, Type) && IsBlockWater(Type));
}
-
-
-
-
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);
return 18;
}
-
-
-
-
-
};