diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-04-06 20:09:33 +0200 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-04-06 20:09:33 +0200 |
commit | f5cb81eb1bb10d7a3a6704269644a6aedd04375a (patch) | |
tree | 657c49569552369fc3e2a8b5706a3c636ca73df9 /src/Simulator/IncrementalRedstoneSimulator.cpp | |
parent | Fixed Endiannes conversion routines for floats and doubles. (diff) | |
download | cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar.gz cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar.bz2 cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar.lz cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar.xz cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.tar.zst cuberite-f5cb81eb1bb10d7a3a6704269644a6aedd04375a.zip |
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator.cpp')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 92659fab7..b59f95cfd 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -688,12 +688,13 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_B bool IsOn = ((a_MyState == E_BLOCK_REDSTONE_REPEATER_ON) ? true : false); // Cache if repeater is on bool IsSelfPowered = IsRepeaterPowered(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); // Cache if repeater is pwoered + bool IsLocked = IsRepeaterLocked(a_BlockX, a_BlockY, a_BlockZ, a_Meta & 0x3); - if (IsSelfPowered && !IsOn) // Queue a power change if I am receiving power but not on + if (IsSelfPowered && !IsOn && !IsLocked) // Queue a power change if I am receiving power but not on { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, true); } - else if (!IsSelfPowered && IsOn) // Queue a power change if I am not receiving power but on + else if (!IsSelfPowered && IsOn && !IsLocked) // Queue a power change if I am not receiving power but on { QueueRepeaterPowerChange(a_BlockX, a_BlockY, a_BlockZ, a_Meta, false); } @@ -1220,6 +1221,66 @@ bool cIncrementalRedstoneSimulator::IsRepeaterPowered(int a_BlockX, int a_BlockY + +bool cIncrementalRedstoneSimulator::IsRepeaterLocked(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) +{ + // Repeaters can be locked by either of their sides + + for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks->begin(); itr != m_PoweredBlocks->end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + // If N/S check E/W + case 0x0: + case 0x2: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + // If E/W check N/S + case 0x1: + case 0x3: + { + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_SourcePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + } + } + + for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) + { + if (!itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { continue; } + + switch (a_Meta) + { + // If N/S check E/W + case 0x0: + case 0x2: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX + 1, a_BlockY, a_BlockZ))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX - 1, a_BlockY, a_BlockZ))) { return true; } + break; + } + // If E/W check N/S + case 0x1: + case 0x3: + { + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ + 1))) { return true; } + if (itr->a_MiddlePos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ - 1))) { return true; } + break; + } + } + } + return false; // Couldn't find power source behind repeater +} + + + + bool cIncrementalRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta) { // Pistons cannot be powered through their front face; this function verifies that a source meets this requirement |