summaryrefslogtreecommitdiffstats
path: root/src/Blocks
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-12-17 20:06:57 +0100
committerHowaner <franzi.moos@googlemail.com>2014-12-17 20:06:57 +0100
commit30961e0f522a17679b501e3f72f5d1ad5ac9147f (patch)
tree30349237255201c568afe630d0ce8bc426712f90 /src/Blocks
parentMerge pull request #1674 from gushromp/master (diff)
downloadcuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar.gz
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar.bz2
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar.lz
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar.xz
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.tar.zst
cuberite-30961e0f522a17679b501e3f72f5d1ad5ac9147f.zip
Diffstat (limited to 'src/Blocks')
-rw-r--r--src/Blocks/BlockHandler.cpp2
-rw-r--r--src/Blocks/BlockSponge.h101
-rw-r--r--src/Blocks/CMakeLists.txt1
3 files changed, 104 insertions, 0 deletions
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index d532aa1dc..e50b19ba3 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..2e920e856
--- /dev/null
+++ b/src/Blocks/BlockSponge.h
@@ -0,0 +1,101 @@
+
+#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,
+ int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
+ int a_CursorX, int a_CursorY, int a_CursorZ,
+ BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
+ )
+ {
+ if (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) == E_META_SPONGE_NORMAL)
+ {
+ AbsorbWater(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
+ }
+ }
+
+
+ bool 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);
+ return true;
+ }
+ return false;
+ }
+
+} ;
+
+
+
+
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