summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockPiston.cpp
diff options
context:
space:
mode:
authorhle0 <91701075+hle0@users.noreply.github.com>2024-11-08 00:05:47 +0100
committerGitHub <noreply@github.com>2024-11-08 00:05:47 +0100
commit33b9c5dc6dae42fb6fc33283ded888a8001e5394 (patch)
tree136bb3e02c25e49feb00a06857e4145a54b6c339 /src/Blocks/BlockPiston.cpp
parentRemove simple template-id from constructors for Vector3 template. (#5586) (diff)
downloadcuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar.gz
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar.bz2
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar.lz
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar.xz
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.tar.zst
cuberite-33b9c5dc6dae42fb6fc33283ded888a8001e5394.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockPiston.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index 124757b44..568e2eaa5 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -48,8 +48,12 @@ void cBlockPistonHandler::ExtendPiston(Vector3i a_BlockPos, cWorld & a_World)
BLOCKTYPE pistonBlock;
NIBBLETYPE pistonMeta;
- a_World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta);
- a_World.BroadcastBlockAction(a_BlockPos, PistonExtendAction, pistonMeta, pistonBlock);
+ if (a_World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta))
+ {
+ a_World.BroadcastBlockAction(
+ a_BlockPos, PistonExtendAction, pistonMeta, pistonBlock
+ );
+ }
}
// Client expects the server to "play" the animation before setting the final blocks
@@ -60,9 +64,12 @@ void cBlockPistonHandler::ExtendPiston(Vector3i a_BlockPos, cWorld & a_World)
{
BLOCKTYPE pistonBlock;
NIBBLETYPE pistonMeta;
- World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta);
- if ((pistonBlock != E_BLOCK_PISTON) && !IsSticky(pistonBlock))
+
+ if (
+ !World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta) ||
+ ((pistonBlock != E_BLOCK_PISTON) && !IsSticky(pistonBlock))
+ )
{
// Ensure we operate on a piston to avoid spurious behaviour
// Note that the scheduled task may result in the block type of a_BlockPos changing
@@ -104,17 +111,23 @@ void cBlockPistonHandler::RetractPiston(Vector3i a_BlockPos, cWorld & a_World)
{
BLOCKTYPE pistonBlock;
NIBBLETYPE pistonMeta;
- a_World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta);
- a_World.BroadcastBlockAction(a_BlockPos, PistonRetractAction, pistonMeta, pistonBlock);
+ if (a_World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta))
+ {
+ a_World.BroadcastBlockAction(
+ a_BlockPos, PistonRetractAction, pistonMeta, pistonBlock
+ );
+ }
}
a_World.ScheduleTask(1_tick, [a_BlockPos](cWorld & World)
{
BLOCKTYPE pistonBlock;
NIBBLETYPE pistonMeta;
- World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta);
- if ((pistonBlock != E_BLOCK_PISTON) && !IsSticky(pistonBlock))
+ if (
+ !World.GetBlockTypeMeta(a_BlockPos, pistonBlock, pistonMeta) ||
+ ((pistonBlock != E_BLOCK_PISTON) && !IsSticky(pistonBlock))
+ )
{
// Ensure we operate on a piston to avoid spurious behaviour
// Note that the scheduled task may result in the block type of a_BlockPos changing
@@ -189,19 +202,20 @@ void cBlockPistonHandler::PushBlocks(
NIBBLETYPE moveMeta;
for (auto & moveBlockPos : sortedBlocks)
{
- a_World.GetBlockTypeMeta(moveBlockPos, moveBlock, moveMeta);
-
- if (cBlockInfo::IsPistonBreakable(moveBlock))
- {
- // Block is breakable, drop it:
- a_World.DropBlockAsPickups(moveBlockPos, nullptr, nullptr);
- }
- else
+ if (a_World.GetBlockTypeMeta(moveBlockPos, moveBlock, moveMeta))
{
- // Not breakable, just move it
- a_World.SetBlock(moveBlockPos, E_BLOCK_AIR, 0);
- moveBlockPos += a_PushDir;
- a_World.SetBlock(moveBlockPos, moveBlock, moveMeta);
+ if (cBlockInfo::IsPistonBreakable(moveBlock))
+ {
+ // Block is breakable, drop it:
+ a_World.DropBlockAsPickups(moveBlockPos, nullptr, nullptr);
+ }
+ else
+ {
+ // Not breakable, just move it
+ a_World.SetBlock(moveBlockPos, E_BLOCK_AIR, 0);
+ moveBlockPos += a_PushDir;
+ a_World.SetBlock(moveBlockPos, moveBlock, moveMeta);
+ }
}
}
}
@@ -232,7 +246,10 @@ bool cBlockPistonHandler::CanPushBlock(
BLOCKTYPE currBlock;
NIBBLETYPE currMeta;
- a_World.GetBlockTypeMeta(a_BlockPos, currBlock, currMeta);
+ if (!a_World.GetBlockTypeMeta(a_BlockPos, currBlock, currMeta))
+ {
+ return !a_RequirePushable;
+ }
if (currBlock == E_BLOCK_AIR)
{