diff options
Diffstat (limited to '')
-rw-r--r-- | src/BlockID.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockHandler.cpp | 2 | ||||
-rw-r--r-- | src/Blocks/BlockSponge.h | 101 | ||||
-rw-r--r-- | src/Blocks/CMakeLists.txt | 1 |
4 files changed, 108 insertions, 0 deletions
diff --git a/src/BlockID.h b/src/BlockID.h index 8f2cee02e..d08d0ed12 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 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 |