diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-08 19:22:16 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-08-08 19:22:16 +0200 |
commit | 40eba5244ddd7045a9c3539c5f46c9921301ed90 (patch) | |
tree | 9edf40e2e5033ad19ce8a0739668500e30de653e /src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h | |
parent | const-ify some Chunk functions (diff) | |
download | cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.gz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.bz2 cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.lz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.xz cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.tar.zst cuberite-40eba5244ddd7045a9c3539c5f46c9921301ed90.zip |
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/RedstoneToggleHandler.h | 43 |
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); |