Toggleables: update simulators when changed
This commit is contained in:
parent
7d93742498
commit
860eedd3d7
|
@ -48,7 +48,7 @@ public:
|
||||||
const auto SoundToPlay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? "block.stone_button.click_on" : "block.wood_button.click_on";
|
const auto SoundToPlay = (m_BlockType == E_BLOCK_STONE_BUTTON) ? "block.stone_button.click_on" : "block.wood_button.click_on";
|
||||||
|
|
||||||
a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta, false);
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta, false);
|
||||||
a_WorldInterface.WakeUpSimulators(a_BlockPos);
|
WakeUpSimulators(a_WorldInterface, a_BlockPos);
|
||||||
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect(SoundToPlay, a_BlockPos, 0.5f, 0.6f, a_Player.GetClientHandle());
|
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect(SoundToPlay, a_BlockPos, 0.5f, 0.6f, a_Player.GetClientHandle());
|
||||||
|
|
||||||
// Queue a button reset (unpress)
|
// Queue a button reset (unpress)
|
||||||
|
@ -186,7 +186,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
a_World.SetBlockMeta(Pos, Meta | 0x08, false);
|
a_World.SetBlockMeta(Pos, Meta | 0x08, false);
|
||||||
a_World.WakeUpSimulators(Pos);
|
WakeUpSimulators(a_World, Pos);
|
||||||
|
|
||||||
// sound name is ok to be wood, because only wood gets triggered by arrow
|
// sound name is ok to be wood, because only wood gets triggered by arrow
|
||||||
a_World.GetBroadcastManager().BroadcastSoundEffect("block.wood_button.click_on", Pos, 0.5f, 0.6f);
|
a_World.GetBroadcastManager().BroadcastSoundEffect("block.wood_button.click_on", Pos, 0.5f, 0.6f);
|
||||||
|
@ -195,6 +195,27 @@ public:
|
||||||
QueueButtonRelease(a_World, Pos, Type);
|
QueueButtonRelease(a_World, Pos, Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Notify, mainly the redstone simulator, that this toggle component has updated. */
|
||||||
|
template <class WorldType>
|
||||||
|
static void WakeUpSimulators(WorldType & a_World, const Vector3i a_Position)
|
||||||
|
{
|
||||||
|
// Contains our direct adjacents
|
||||||
|
static const Vector3i Offsets[] =
|
||||||
|
{
|
||||||
|
{ 1, 0, 0 },
|
||||||
|
{ -1, 0, 0 },
|
||||||
|
{ 0, 1, 0 },
|
||||||
|
{ 0, -1, 0 },
|
||||||
|
{ 0, 0, 1 },
|
||||||
|
{ 0, 0, -1 }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto & Offset : Offsets)
|
||||||
|
{
|
||||||
|
a_World.WakeUpSimulators(a_Position + Offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Schedules a recurring event at appropriate intervals to release a button at a given position.
|
/** Schedules a recurring event at appropriate intervals to release a button at a given position.
|
||||||
|
@ -229,7 +250,7 @@ private:
|
||||||
const auto SoundToPlayOnRelease = (Type == E_BLOCK_STONE_BUTTON) ? "block.stone_button.click_off" : "block.wood_button.click_off";
|
const auto SoundToPlayOnRelease = (Type == E_BLOCK_STONE_BUTTON) ? "block.stone_button.click_off" : "block.wood_button.click_off";
|
||||||
|
|
||||||
a_World.SetBlockMeta(a_Position, Meta & 0x07, false);
|
a_World.SetBlockMeta(a_Position, Meta & 0x07, false);
|
||||||
a_World.WakeUpSimulators(a_Position);
|
WakeUpSimulators(a_World, a_Position);
|
||||||
a_World.BroadcastSoundEffect(SoundToPlayOnRelease, a_Position, 0.5f, 0.5f);
|
a_World.BroadcastSoundEffect(SoundToPlayOnRelease, a_Position, 0.5f, 0.5f);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "BlockHandler.h"
|
#include "BlockHandler.h"
|
||||||
#include "../Chunk.h"
|
#include "../Chunk.h"
|
||||||
#include "Mixins.h"
|
#include "Mixins.h"
|
||||||
|
#include "BlockButton.h"
|
||||||
#include "BlockSlab.h"
|
#include "BlockSlab.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockPos) ^ 0x08);
|
NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockPos) ^ 0x08);
|
||||||
|
|
||||||
a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta);
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta);
|
||||||
a_WorldInterface.WakeUpSimulators(a_BlockPos);
|
cBlockButtonHandler::WakeUpSimulators(a_WorldInterface, a_BlockPos);
|
||||||
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.lever.click", a_BlockPos, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f);
|
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.lever.click", a_BlockPos, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user