summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockPiston.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-10-16 10:06:34 +0200
committerGitHub <noreply@github.com>2019-10-16 10:06:34 +0200
commit221cc4ec5cb6301743e947eaabed3fecedba796f (patch)
tree4e44c8bb7523e5d1d04468fc906ae24674c10abc /src/Blocks/BlockPiston.cpp
parentFixed crash in hopper while pulling items from blockentity above itself (#4412) (diff)
downloadcuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.gz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.bz2
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.lz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.xz
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.tar.zst
cuberite-221cc4ec5cb6301743e947eaabed3fecedba796f.zip
Diffstat (limited to 'src/Blocks/BlockPiston.cpp')
-rw-r--r--src/Blocks/BlockPiston.cpp75
1 files changed, 23 insertions, 52 deletions
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index c3a90c8a5..6ebbd784d 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -16,8 +16,8 @@
-cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType)
- : cBlockHandler(a_BlockType)
+cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType):
+ super(a_BlockType)
{
}
@@ -25,20 +25,19 @@ cBlockPistonHandler::cBlockPistonHandler(BLOCKTYPE a_BlockType)
-void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
+void cBlockPistonHandler::OnBroken(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ Vector3i a_BlockPos,
+ BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
+)
{
- Vector3i blockPos(a_BlockX, a_BlockY, a_BlockZ);
-
- NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos);
// If the piston is extended, destroy the extension as well
- if (IsExtended(OldMeta))
+ if (IsExtended(a_OldBlockMeta))
{
- // Get the position of the extension
- blockPos += MetadataToOffset(OldMeta);
-
- if (a_ChunkInterface.GetBlock(blockPos) == E_BLOCK_PISTON_EXTENSION)
+ auto extPos = a_BlockPos + MetadataToOffset(a_OldBlockMeta);
+ if (a_ChunkInterface.GetBlock(extPos) == E_BLOCK_PISTON_EXTENSION)
{
- a_ChunkInterface.SetBlock(blockPos.x, blockPos.y, blockPos.z, E_BLOCK_AIR, 0);
+ a_ChunkInterface.DropBlockAsPickups(extPos);
}
}
}
@@ -47,16 +46,6 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorld
-void cBlockPistonHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta)
-{
- // Returning Piston Item without Direction-Metavalue
- a_Pickups.push_back(cItem(m_BlockType, 1));
-}
-
-
-
-
-
bool cBlockPistonHandler::GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@@ -106,7 +95,7 @@ void cBlockPistonHandler::PushBlocks(
std::vector<Vector3i> sortedBlocks(a_BlocksToPush.begin(), a_BlocksToPush.end());
std::sort(sortedBlocks.begin(), sortedBlocks.end(), [a_PushDir](const Vector3i & a, const Vector3i & b)
{
- return a.Dot(a_PushDir) > b.Dot(a_PushDir);
+ return (a.Dot(a_PushDir) > b.Dot(a_PushDir));
});
// Move every block
@@ -118,17 +107,8 @@ void cBlockPistonHandler::PushBlocks(
if (cBlockInfo::IsPistonBreakable(moveBlock))
{
- // Block is breakable, drop it
- cBlockHandler * Handler = BlockHandler(moveBlock);
- if (Handler->DoesDropOnUnsuitable())
- {
- cChunkInterface ChunkInterface(a_World.GetChunkMap());
- cBlockInServerPluginInterface PluginInterface(a_World);
- Handler->DropBlock(ChunkInterface, a_World, PluginInterface, nullptr,
- moveBlockPos.x, moveBlockPos.y, moveBlockPos.z
- );
- }
- a_World.SetBlock(moveBlockPos.x, moveBlockPos.y, moveBlockPos.z, E_BLOCK_AIR, 0);
+ // Block is breakable, drop it:
+ a_World.DropBlockAsPickups(moveBlockPos, nullptr, nullptr);
}
else
{
@@ -357,26 +337,17 @@ cBlockPistonHeadHandler::cBlockPistonHeadHandler(void) :
-void cBlockPistonHeadHandler::OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
+void cBlockPistonHeadHandler::OnBroken(
+ cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
+ Vector3i a_BlockPos,
+ BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
+)
{
- Vector3i blockPos(a_BlockX, a_BlockY, a_BlockZ);
-
- // Get the base of the piston
- NIBBLETYPE OldMeta = a_ChunkInterface.GetBlockMeta(blockPos);
- blockPos -= cBlockPistonHandler::MetadataToOffset(OldMeta);
-
- BLOCKTYPE Block = a_ChunkInterface.GetBlock(blockPos);
- if ((Block == E_BLOCK_STICKY_PISTON) || (Block == E_BLOCK_PISTON))
+ // Drop the base of the piston:
+ auto basePos = a_BlockPos - cBlockPistonHandler::MetadataToOffset(a_OldBlockMeta);
+ if (cChunkDef::IsValidHeight(basePos.y))
{
- a_ChunkInterface.DigBlock(a_WorldInterface, blockPos.x, blockPos.y, blockPos.z);
- if (a_Player.IsGameModeCreative())
- {
- return; // No pickups if creative
- }
-
- cItems Pickups;
- Pickups.push_back(cItem(Block, 1));
- a_WorldInterface.SpawnItemPickups(Pickups, blockPos.x + 0.5, blockPos.y + 0.5, blockPos.z + 0.5);
+ a_ChunkInterface.DropBlockAsPickups(basePos);
}
}