Buttons no longer click on when already on. Buttons now play sound when clicking off.
This commit is contained in:
parent
d83c9f194f
commit
9f1d1c058f
|
@ -490,7 +490,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
|
||||||
|
|
||||||
auto task = std::make_shared<cLuaScheduledWorldTask>(*Plugin, FnRef);
|
auto task = std::make_shared<cLuaScheduledWorldTask>(*Plugin, FnRef);
|
||||||
Plugin->AddResettable(task);
|
Plugin->AddResettable(task);
|
||||||
World->ScheduleTask(DelayTicks, task);
|
World->ScheduleTask(DelayTicks, static_cast<cWorld::cTaskPtr>(task));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
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
|
// 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_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
|
||||||
a_WorldInterface.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ);
|
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)
|
// 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);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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(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->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;
|
std::vector<Vector3i> ScheduledBlocks;
|
||||||
ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
|
ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
|
||||||
ScheduledBlocks.push_back(Vector3i(tempx, tempy, tempz));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ
|
||||||
|
|
||||||
std::vector<Vector3i> ScheduledBlocks;
|
std::vector<Vector3i> ScheduledBlocks;
|
||||||
ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void cWorld::ScheduleTask(int a_DelayTicks, cTaskPtr a_Task)
|
||||||
|
@ -3554,8 +3558,10 @@ void cWorld::cTaskSendBlockToAllPlayers::Run(cWorld & a_World)
|
||||||
a_World.ForEachPlayer(PlayerCallback);
|
a_World.ForEachPlayer(PlayerCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cWorld::cTaskLambda::Run(cWorld & a_World)
|
||||||
|
{
|
||||||
|
m_func(a_World);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
22
src/World.h
22
src/World.h
|
@ -103,8 +103,12 @@ public:
|
||||||
class cTask
|
class cTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
cTask(const cTask & other) = default;
|
||||||
virtual ~cTask() {}
|
virtual ~cTask() {}
|
||||||
virtual void Run(cWorld & a_World) = 0;
|
virtual void Run(cWorld & a_World) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
cTask() {}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
typedef SharedPtr<cTask> cTaskPtr;
|
typedef SharedPtr<cTask> cTaskPtr;
|
||||||
|
@ -142,6 +146,21 @@ public:
|
||||||
std::vector<Vector3i> m_SendQueue;
|
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
|
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 */
|
/** 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
|
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. */
|
/** Queues a task onto the tick thread, with the specified delay. */
|
||||||
void ScheduleTask(int a_DelayTicks, cTaskPtr a_Task);
|
void ScheduleTask(int a_DelayTicks, cTaskPtr a_Task);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user