summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockPiston.cpp23
-rw-r--r--src/World.cpp21
-rw-r--r--src/World.h6
3 files changed, 29 insertions, 21 deletions
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index f758013dc..1f8e0d9e0 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -27,6 +27,7 @@
}
#define PISTON_TICK_DELAY 1
+#define PISTON_MAX_PUSH_DISTANCE 12
@@ -78,7 +79,7 @@ bool cBlockPistonHandler::GetPlacementBlockTypeMeta(
int cBlockPistonHandler::FirstPassthroughBlock(int pistonX, int pistonY, int pistonZ, NIBBLETYPE pistonmeta, cWorld * a_World)
{
// Examine each of the 12 blocks ahead of the piston:
- for (int ret = 0; ret < 12; ret++)
+ for (int ret = 0; ret < PISTON_MAX_PUSH_DISTANCE; ret++)
{
BLOCKTYPE currBlock;
NIBBLETYPE currMeta;
@@ -144,12 +145,15 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ,
// Push blocks, from the furthest to the nearest:
int oldx = a_BlockX, oldy = a_BlockY, oldz = a_BlockZ;
NIBBLETYPE currBlockMeta;
+ std::vector<Vector3i> ScheduledBlocks;
+ ScheduledBlocks.reserve(PISTON_MAX_PUSH_DISTANCE);
+
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, false);
- a_World->ScheduleTask(PISTON_TICK_DELAY, new cWorld::cTaskSendBlockToAllPlayers(oldx, oldy, oldz));
+ ScheduledBlocks.push_back(Vector3i(oldx, oldy, oldz));
oldx = a_BlockX;
oldy = a_BlockY;
oldz = a_BlockZ;
@@ -158,12 +162,13 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ,
int extx = a_BlockX;
int exty = a_BlockY;
int extz = a_BlockZ;
+ ScheduledBlocks.push_back(Vector3i(extx, exty, extz));
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), false);
- a_World->ScheduleTask(PISTON_TICK_DELAY, new cWorld::cTaskSendBlockToAllPlayers(extx, exty, extz));
+ a_World->ScheduleTask(PISTON_TICK_DELAY, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks));
}
@@ -209,15 +214,21 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ
// Pull the block
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, tempBlock, tempMeta, false);
a_World->SetBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0, false);
- a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(a_BlockX, a_BlockY, a_BlockZ));
- a_World->ScheduleTask(PISTON_TICK_DELAY, new cWorld::cTaskSendBlockToAllPlayers(tempx, tempy, tempz));
+
+ std::vector<Vector3i> ScheduledBlocks;
+ ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
+ ScheduledBlocks.push_back(Vector3i(tempx, tempy, tempz));
+ a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks));
return;
}
}
// Retract without pulling
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0, false);
- a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(a_BlockX, a_BlockY, a_BlockZ));
+
+ std::vector<Vector3i> ScheduledBlocks;
+ ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
+ a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks));
}
diff --git a/src/World.cpp b/src/World.cpp
index 29046bba9..88e9c32e6 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3130,10 +3130,8 @@ void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cWorld::cTaskSendBlockTo
-cWorld::cTaskSendBlockToAllPlayers::cTaskSendBlockToAllPlayers(int a_BlockX, int a_BlockY, int a_BlockZ) :
- m_BlockX(a_BlockX),
- m_BlockY(a_BlockY),
- m_BlockZ(a_BlockZ)
+cWorld::cTaskSendBlockToAllPlayers::cTaskSendBlockToAllPlayers(std::vector<Vector3i> & a_SendQueue) :
+ m_SendQueue(a_SendQueue)
{
}
@@ -3143,26 +3141,27 @@ void cWorld::cTaskSendBlockToAllPlayers::Run(cWorld & a_World)
public cPlayerListCallback
{
public:
- cPlayerCallback(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld & a_World) :
- m_BlockX(a_BlockX),
- m_BlockY(a_BlockY),
- m_BlockZ(a_BlockZ),
+ cPlayerCallback(std::vector<Vector3i> & a_SendQueue, cWorld & a_World) :
+ m_SendQueue(a_SendQueue),
m_World(a_World)
{
}
virtual bool Item(cPlayer * a_Player)
{
- m_World.SendBlockTo(m_BlockX, m_BlockY, m_BlockZ, a_Player);
+ for (std::vector<Vector3i>::const_iterator itr = m_SendQueue.begin(); itr != m_SendQueue.end(); ++itr)
+ {
+ m_World.SendBlockTo(itr->x, itr->y, itr->z, a_Player);
+ }
return false;
}
private:
- int m_BlockX, m_BlockY, m_BlockZ;
+ std::vector<Vector3i> m_SendQueue;
cWorld & m_World;
- } PlayerCallback(m_BlockX, m_BlockY, m_BlockZ, a_World);
+ } PlayerCallback(m_SendQueue, a_World);
a_World.ForEachPlayer(PlayerCallback);
}
diff --git a/src/World.h b/src/World.h
index 5ef63a540..98b241a2b 100644
--- a/src/World.h
+++ b/src/World.h
@@ -121,15 +121,13 @@ public:
public cTask
{
public:
- cTaskSendBlockToAllPlayers(int a_BlockX, int a_BlockY, int a_BlockZ);
+ cTaskSendBlockToAllPlayers(std::vector<Vector3i> & a_SendQueue);
protected:
// cTask overrides:
virtual void Run(cWorld & a_World) override;
- int m_BlockX;
- int m_BlockY;
- int m_BlockZ;
+ std::vector<Vector3i> m_SendQueue;
};