summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BlockID.h4
-rw-r--r--src/Blocks/BlockHandler.cpp2
-rw-r--r--src/Blocks/BlockSponge.h97
-rw-r--r--src/Blocks/CMakeLists.txt1
4 files changed, 104 insertions, 0 deletions
diff --git a/src/BlockID.h b/src/BlockID.h
index 41ccf90b5..96afe0db9 100644
--- a/src/BlockID.h
+++ b/src/BlockID.h
@@ -682,6 +682,10 @@ enum
E_META_SNOW_LAYER_SEVEN = 6,
E_META_SNOW_LAYER_EIGHT = 7,
+ // E_BLOCK_SPONGE metas:
+ E_META_SPONGE_NORMAL = 0,
+ E_META_SPONGE_WET = 1,
+
// E_BLOCK_STAINED_CLAY metas:
E_META_STAINED_CLAY_WHITE = 0,
E_META_STAINED_CLAY_ORANGE = 1,
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 2de4a3e4c..91317b1c5 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -72,6 +72,7 @@
#include "BlockSignPost.h"
#include "BlockSlab.h"
#include "BlockSnow.h"
+#include "BlockSponge.h"
#include "BlockStairs.h"
#include "BlockStems.h"
#include "BlockStone.h"
@@ -294,6 +295,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_SEA_LANTERN: return new cBlockSeaLanternHandler (a_BlockType);
case E_BLOCK_SIGN_POST: return new cBlockSignPostHandler (a_BlockType);
case E_BLOCK_SNOW: return new cBlockSnowHandler (a_BlockType);
+ case E_BLOCK_SPONGE: return new cBlockSpongeHandler (a_BlockType);
case E_BLOCK_SPRUCE_DOOR: return new cBlockDoorHandler (a_BlockType);
case E_BLOCK_SPRUCE_FENCE_GATE: return new cBlockFenceGateHandler (a_BlockType);
case E_BLOCK_SPRUCE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType);
diff --git a/src/Blocks/BlockSponge.h b/src/Blocks/BlockSponge.h
new file mode 100644
index 000000000..a9a897f33
--- /dev/null
+++ b/src/Blocks/BlockSponge.h
@@ -0,0 +1,97 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "ChunkInterface.h"
+
+
+
+
+
+class cBlockSpongeHandler : public cBlockHandler
+{
+public:
+ cBlockSpongeHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+
+ virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ {
+ if (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) == E_META_SPONGE_NORMAL)
+ {
+ AbsorbWater(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
+ }
+ }
+
+
+ virtual void OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, const sSetBlock & a_BlockChange) override
+ {
+ if (a_BlockChange.m_BlockMeta == E_META_SPONGE_NORMAL)
+ {
+ int BlockX = a_BlockChange.m_ChunkX * cChunkDef::Width + a_BlockChange.m_RelX;
+ int BlockZ = a_BlockChange.m_ChunkZ * cChunkDef::Width + a_BlockChange.m_RelZ;
+
+ AbsorbWater(a_ChunkInterface, BlockX, a_BlockChange.m_RelY, BlockZ);
+ }
+ }
+
+
+ void AbsorbWater(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
+ {
+ std::list<Vector3i> Blocks;
+ std::list<Vector3i> WaterBlocks;
+ Blocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
+
+ int CurrentRadius = 0;
+ while (!Blocks.empty() && (CurrentRadius < 6) && (WaterBlocks.size() <= 64))
+ {
+ Vector3i BlockLoc = Blocks.front();
+ Blocks.pop_front();
+
+ bool ChangedBlock = false;
+ for (size_t i = 0; i <= 5; ++i)
+ {
+ eBlockFace Face = static_cast<eBlockFace>(i);
+
+ int BlockX = BlockLoc.x, BlockY = BlockLoc.y, BlockZ = BlockLoc.z;
+ AddFaceDirection(BlockX, BlockY, BlockZ, Face);
+
+ if (IsBlockWater(a_ChunkInterface.GetBlock(BlockX, BlockY, BlockZ)))
+ {
+ Blocks.push_back(Vector3i(BlockX, BlockY, BlockZ));
+ WaterBlocks.push_back(Vector3i(BlockX, BlockY, BlockZ));
+ a_ChunkInterface.FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_AIR, 0);
+
+ ChangedBlock = true;
+ }
+ }
+
+ if (ChangedBlock)
+ {
+ CurrentRadius++;
+ }
+ }
+
+ if (WaterBlocks.size() > 0)
+ {
+ // Change the sponge to a wet sponge.
+ a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, E_META_SPONGE_WET);
+
+ // Remove the water
+ for (auto Block : WaterBlocks)
+ {
+ a_ChunkInterface.SetBlock(Block.x, Block.y, Block.z, E_BLOCK_AIR, 0);
+ }
+
+ // ChunkInterface doesn't have a BroadcastSoundParticleEffect() method.
+ // a_World->BroadcastSoundParticleEffect(2001, (int) a_BlockX * 8.f), (int) (a_BlockY * 8.f), (int) (a_BlockZ * 8.f), E_BLOCK_STATIONARY_WATER);
+ }
+ }
+
+} ;
+
+
+
+
diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt
index ed3e321d4..3ce15ed26 100644
--- a/src/Blocks/CMakeLists.txt
+++ b/src/Blocks/CMakeLists.txt
@@ -76,6 +76,7 @@ SET (HDRS
BlockSignPost.h
BlockSlab.h
BlockSnow.h
+ BlockSponge.h
BlockStairs.h
BlockStems.h
BlockStone.h