summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h
index bf9c639b1..b66ce47fd 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h
@@ -11,9 +11,7 @@
class cRedstoneToggleHandler final : public cRedstoneHandler
{
-public:
-
- inline static Vector3i GetPositionAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
+ inline static Vector3i GetOffsetAttachedTo(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
{
switch (a_BlockType)
{
@@ -22,13 +20,13 @@ public:
switch (a_Meta & 0x7)
{
case 0x0:
- case 0x7: return { a_Position + Vector3i(0, 1, 0) };
- case 0x1: return { a_Position + Vector3i(-1, 0, 0) };
- case 0x2: return { a_Position + Vector3i(1, 0, 0) };
- case 0x3: return { a_Position + Vector3i(0, 0, -1) };
- case 0x4: return { a_Position + Vector3i(0, 0, 1) };
+ case 0x7: return { 0, 1, 0 };
+ case 0x1: return { -1, 0, 0 };
+ case 0x2: return { 1, 0, 0 };
+ case 0x3: return { 0, 0, -1 };
+ case 0x4: return { 0, 0, 1 };
case 0x5:
- case 0x6: return { a_Position + Vector3i(0, -1, 0) };
+ case 0x6: return { 0, -1, 0 };
default:
{
ASSERT(!"Unhandled lever metadata!");
@@ -41,12 +39,12 @@ public:
{
switch (a_Meta & 0x7)
{
- case 0x0: return { a_Position + Vector3i(0, 1, 0) };
- case 0x1: return { a_Position + Vector3i(-1, 0, 0) };
- case 0x2: return { a_Position + Vector3i(1, 0, 0) };
- case 0x3: return { a_Position + Vector3i(0, 0, -1) };
- case 0x4: return { a_Position + Vector3i(0, 0, 1) };
- case 0x5: return { a_Position + Vector3i(0, -1, 0) };
+ case 0x0: return { 0, 1, 0 };
+ case 0x1: return { -1, 0, 0 };
+ case 0x2: return { 1, 0, 0 };
+ case 0x3: return { 0, 0, -1 };
+ case 0x4: return { 0, 0, 1 };
+ case 0x5: return { 0, -1, 0 };
default:
{
ASSERT(!"Unhandled button metadata!");
@@ -62,14 +60,19 @@ public:
}
}
- virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override
+ virtual unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked) const override
{
UNUSED(a_QueryBlockType);
- if ((GetPositionAttachedTo(a_Position, a_BlockType, a_Meta) == a_QueryPosition) || cIncrementalRedstoneSimulator::IsMechanism(a_QueryBlockType))
+
+ const auto Meta = a_Chunk.GetMeta(a_Position);
+ const auto QueryOffset = a_QueryPosition - a_Position;
+
+ if (IsLinked && (QueryOffset != GetOffsetAttachedTo(a_Position, a_BlockType, Meta)))
{
- return GetPowerLevel(a_BlockType, a_Meta);
+ return 0;
}
- return 0;
+
+ return GetPowerLevel(a_BlockType, Meta);
}
static unsigned char GetPowerLevel(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
@@ -92,7 +95,7 @@ public:
// LOGD("Evaluating templatio<> the lever/button (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
}
- virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
+ virtual void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
{
UNUSED(a_Chunk);
UNUSED(a_Position);