summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbibo38 <bibo38@github.com>2015-11-04 21:45:51 +0100
committerbibo38 <bibo38@github.com>2015-11-07 17:23:02 +0100
commit8f066a16ec0eda3e0558cbf6decf3e0c7c82302a (patch)
tree62c51da40455c7cad56048257e2c8e553c1e00b1
parentAdded the CanPushBlock method for the piston push check. (diff)
downloadcuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar.gz
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar.bz2
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar.lz
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar.xz
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.tar.zst
cuberite-8f066a16ec0eda3e0558cbf6decf3e0c7c82302a.zip
-rw-r--r--src/Blocks/BlockPiston.cpp77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index 83a1b83c4..8e56fe06b 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -7,6 +7,8 @@
#include "BlockInServerPluginInterface.h"
#include "ChunkInterface.h"
+#include <vector>
+
@@ -136,56 +138,59 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ,
return;
}
- int dist = 1; // TODO
- AddPistonDir(a_BlockX, a_BlockY, a_BlockZ, pistonMeta, 1);
+ int moveX = a_BlockX;
+ int moveY = a_BlockY;
+ int moveZ = a_BlockZ;
+
+ AddPistonDir(moveX, moveY, moveZ, pistonMeta, 1);
std::unordered_set<Vector3i, VectorHasher<int>> blocksPushed;
- if (!CanPushBlock(a_BlockX, a_BlockY, a_BlockZ, a_World, true, blocksPushed, pistonMeta))
+ if (!CanPushBlock(moveX, moveY, moveZ, a_World, true, blocksPushed, pistonMeta))
{
// Can't push anything, bail out
return;
}
+
+ Vector3i pistonMoveVec;
+ AddPistonDir(pistonMoveVec.x, pistonMoveVec.y, pistonMoveVec.z, pistonMeta, 1);
+ std::vector<Vector3i> sortedBlocks(blocksPushed.begin(), blocksPushed.end());
+ std::sort(sortedBlocks.begin(), sortedBlocks.end(), [pistonMoveVec](const Vector3i & a, const Vector3i & b)
+ {
+ return a.Dot(pistonMoveVec) > b.Dot(pistonMoveVec);
+ });
a_World->BroadcastBlockAction(a_BlockX, a_BlockY, a_BlockZ, 0, pistonMeta, pistonBlock);
a_World->BroadcastSoundEffect("tile.piston.out", static_cast<double>(a_BlockX), static_cast<double>(a_BlockY), static_cast<double>(a_BlockZ), 0.5f, 0.7f);
- // Drop the breakable block in the line, if appropriate:
- AddPistonDir(a_BlockX, a_BlockY, a_BlockZ, pistonMeta, dist + 1); // "a_Block" now at the breakable / empty block
- BLOCKTYPE currBlock;
- NIBBLETYPE currMeta;
- a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, currBlock, currMeta);
- if (currBlock != E_BLOCK_AIR)
+ BLOCKTYPE moveBlock;
+ NIBBLETYPE moveMeta;
+ for (const Vector3i & moveBlockVec : sortedBlocks)
{
- cBlockHandler * Handler = BlockHandler(currBlock);
- if (Handler->DoesDropOnUnsuitable())
+ moveX = moveBlockVec.x;
+ moveY = moveBlockVec.y;
+ moveZ = moveBlockVec.z;
+ a_World->GetBlockTypeMeta(moveX, moveY, moveZ, moveBlock, moveMeta);
+ a_World->SetBlock(moveX, moveY, moveZ, E_BLOCK_AIR, 0);
+
+ AddPistonDir(moveX, moveY, moveZ, pistonMeta, 1);
+
+ if (cBlockInfo::IsPistonBreakable(moveBlock))
+ {
+ cBlockHandler * Handler = BlockHandler(moveBlock);
+ if (Handler->DoesDropOnUnsuitable())
+ {
+ cChunkInterface ChunkInterface(a_World->GetChunkMap());
+ cBlockInServerPluginInterface PluginInterface(*a_World);
+ Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, nullptr, moveX, moveY, moveZ);
+ }
+ } else
{
- cChunkInterface ChunkInterface(a_World->GetChunkMap());
- cBlockInServerPluginInterface PluginInterface(*a_World);
- Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, nullptr, a_BlockX, a_BlockY, a_BlockZ);
+ a_World->SetBlock(moveX, moveY, moveZ, moveBlock, moveMeta);
}
}
-
- // Push blocks, from the furthest to the nearest:
- int oldx = a_BlockX, oldy = a_BlockY, oldz = a_BlockZ;
- NIBBLETYPE currBlockMeta;
-
- for (int i = dist + 1; i > 1; i--)
- {
- AddPistonDir(a_BlockX, a_BlockY, a_BlockZ, pistonMeta, -1);
- a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, currBlock, currBlockMeta);
- a_World->SetBlock(oldx, oldy, oldz, currBlock, currBlockMeta);
- oldx = a_BlockX;
- oldy = a_BlockY;
- oldz = a_BlockZ;
- }
-
- int extx = a_BlockX;
- int exty = a_BlockY;
- int extz = a_BlockZ;
- AddPistonDir(a_BlockX, a_BlockY, a_BlockZ, pistonMeta, -1);
- // "a_Block" now at piston body, "ext" at future extension
-
+
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, pistonBlock, pistonMeta | 0x8);
- a_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0));
+ AddPistonDir(a_BlockX, a_BlockY, a_BlockZ, pistonMeta, 1);
+ a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0));
}