summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHax52 <jay.bourgeois7@gmail.com>2015-06-23 04:00:15 +0200
committerhax52 <jay.bourgeois7@gmail.com>2015-06-24 20:52:56 +0200
commit9f1d1c058fa5fe415a264be710d774dc37e12f5e (patch)
tree45298832af28e55e24239e3821ca72730440ecd8
parentMerge pull request #2274 from cuberite/ItemsRemovalFix (diff)
downloadcuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar.gz
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar.bz2
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar.lz
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar.xz
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.tar.zst
cuberite-9f1d1c058fa5fe415a264be710d774dc37e12f5e.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/ManualBindings_World.cpp2
-rw-r--r--src/Blocks/BlockButton.h26
-rw-r--r--src/Blocks/BlockPiston.cpp6
-rw-r--r--src/World.cpp12
-rw-r--r--src/World.h22
5 files changed, 58 insertions, 10 deletions
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
index ddbebce78..d9590de33 100644
--- a/src/Bindings/ManualBindings_World.cpp
+++ b/src/Bindings/ManualBindings_World.cpp
@@ -490,7 +490,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
auto task = std::make_shared<cLuaScheduledWorldTask>(*Plugin, FnRef);
Plugin->AddResettable(task);
- World->ScheduleTask(DelayTicks, task);
+ World->ScheduleTask(DelayTicks, static_cast<cWorld::cTaskPtr>(task));
return 0;
}
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 154cd610e..3558729bb 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -19,15 +19,35 @@ public:
virtual void OnUse(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) override
{
+ NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+
+ double x(a_BlockX);
+ double y(a_BlockY);
+ double z(a_BlockZ);
+
+ // If button is already on do nothing
+ if (Meta & 0x08)
+ {
+ return;
+ }
+
// Set p the ON bit to on
- NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08);
+ Meta |= 0x08;
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
a_WorldInterface.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ);
- a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", (double)a_BlockX, (double)a_BlockY, (double)a_BlockZ, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f);
+ a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", x, y, z, 0.5f, 0.6f);
// Queue a button reset (unpress)
- a_ChunkInterface.QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType, a_WorldInterface);
+ int delay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? 20 : 30;
+
+ a_ChunkInterface.QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), delay, m_BlockType, a_WorldInterface);
+
+ a_Player->GetWorld()->ScheduleTask(delay, [x, y, z](cWorld & a_World)
+ {
+ a_World.BroadcastSoundEffect("random.click", x, y, z, 0.5f, 0.5f);
+ });
+
}
diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp
index d9f4913d8..75f8621a7 100644
--- a/src/Blocks/BlockPiston.cpp
+++ b/src/Blocks/BlockPiston.cpp
@@ -179,7 +179,7 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ,
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, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks));
+ a_World->ScheduleTask(PISTON_TICK_DELAY, static_cast<cWorld::cTaskPtr>(std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)));
}
@@ -229,7 +229,7 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ
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, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks));
+ a_World->ScheduleTask(PISTON_TICK_DELAY + 1, static_cast<cWorld::cTaskPtr>(std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)));
return;
}
}
@@ -239,7 +239,7 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ
std::vector<Vector3i> ScheduledBlocks;
ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
- a_World->ScheduleTask(PISTON_TICK_DELAY + 1, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks));
+ a_World->ScheduleTask(PISTON_TICK_DELAY + 1, static_cast<cWorld::cTaskPtr>(std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)));
}
diff --git a/src/World.cpp b/src/World.cpp
index cf2c35816..f4fd696ee 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -3051,7 +3051,11 @@ void cWorld::QueueTask(cTaskPtr a_Task)
}
-
+void cWorld::ScheduleTask(int a_DelayTicks, std::function<void (cWorld&)> a_Func)
+{
+ cTaskLambda task(a_Func);
+ ScheduleTask(a_DelayTicks, static_cast<cTaskPtr>(std::make_shared<cTaskLambda>(task)));
+}
void cWorld::ScheduleTask(int a_DelayTicks, cTaskPtr a_Task)
@@ -3554,8 +3558,10 @@ void cWorld::cTaskSendBlockToAllPlayers::Run(cWorld & a_World)
a_World.ForEachPlayer(PlayerCallback);
}
-
-
+void cWorld::cTaskLambda::Run(cWorld & a_World)
+{
+ m_func(a_World);
+}
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/World.h b/src/World.h
index 064b50165..2ea89f338 100644
--- a/src/World.h
+++ b/src/World.h
@@ -103,8 +103,12 @@ public:
class cTask
{
public:
+ cTask(const cTask & other) = default;
virtual ~cTask() {}
virtual void Run(cWorld & a_World) = 0;
+
+ protected:
+ cTask() {}
} ;
typedef SharedPtr<cTask> cTaskPtr;
@@ -142,6 +146,21 @@ public:
std::vector<Vector3i> m_SendQueue;
};
+ class cTaskLambda :
+ public cTask
+ {
+
+ public:
+ cTaskLambda(std::function<void(cWorld&)> a_Func) :
+ m_func(a_Func)
+ { }
+
+ protected:
+ virtual void Run(cWorld & a_World) override;
+
+ std::function<void(cWorld&)> m_func;
+ };
+
static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
{
@@ -705,6 +724,9 @@ public:
/** Queues a task onto the tick thread. The task object will be deleted once the task is finished */
void QueueTask(cTaskPtr a_Task); // Exported in ManualBindings.cpp
+ /** Queues a lambda task onto the tick thread, with the specified delay. */
+ void ScheduleTask(int a_DelayTicks, std::function<void(cWorld&)> a_Func);
+
/** Queues a task onto the tick thread, with the specified delay. */
void ScheduleTask(int a_DelayTicks, cTaskPtr a_Task);