summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator
diff options
context:
space:
mode:
authorQUSpilPrgm <QUSpilPrgm@users.noreply.github.com>2016-06-04 14:16:35 +0200
committerQUSpilPrgm <QUSpilPrgm@users.noreply.github.com>2016-06-15 10:33:49 +0200
commit33cd7f4e75819d50f22ae61027373ebb331305b5 (patch)
treeb61d763a27e1986116c1a2f3b779bcf0bb1bd27b /src/Simulator/IncrementalRedstoneSimulator
parentMerge pull request #3227 from cuberite/NormalizeVectorApi (diff)
downloadcuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar.gz
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar.bz2
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar.lz
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar.xz
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.tar.zst
cuberite-33cd7f4e75819d50f22ae61027373ebb331305b5.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h27
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp6
2 files changed, 28 insertions, 5 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
index b67b8d4fb..3c9952582 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
@@ -18,6 +18,22 @@ public:
{
}
+ inline static bool IsActivated(NIBBLETYPE a_Meta)
+ {
+ return (a_Meta & E_META_DROPSPENSER_ACTIVATED) != 0;
+ }
+ inline static NIBBLETYPE SetActivationState(NIBBLETYPE a_Meta, bool IsOn)
+ {
+ if (IsOn)
+ {
+ return a_Meta | E_META_DROPSPENSER_ACTIVATED; // set the bit
+ }
+ else
+ {
+ return a_Meta & ~E_META_DROPSPENSER_ACTIVATED; // clear the bit
+ }
+ }
+
virtual unsigned char GetPowerDeliveredToPosition(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const Vector3i & a_QueryPosition, BLOCKTYPE a_QueryBlockType) override
{
UNUSED(a_Position);
@@ -39,8 +55,9 @@ public:
virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override
{
// LOGD("Evaluating spencer the dropspenser (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
-
- if (a_PoweringData.PowerLevel > 0)
+ bool IsPoweredNow = (a_PoweringData.PowerLevel > 0);
+ bool WasPoweredPreviously = IsActivated(a_Meta);
+ if (IsPoweredNow && !WasPoweredPreviously)
{
class cSetPowerToDropSpenser :
public cDropSpenserCallback
@@ -56,6 +73,12 @@ public:
m_World.DoWithDropSpenserAt(a_Position.x, a_Position.y, a_Position.z, DrSpSP);
}
+ // Update the internal dropspenser state if necessary
+ if (IsPoweredNow != WasPoweredPreviously)
+ {
+ m_World.SetBlockMeta(a_Position, SetActivationState(a_Meta, IsPoweredNow));
+ }
+
return {};
}
diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
index 9f8c0f39d..c7be24dc4 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
@@ -196,12 +196,12 @@ void cIncrementalRedstoneSimulator::Simulate(float a_dt)
cRedstoneHandler::PoweringData Power;
for (const auto & Location : CurrentHandler->GetValidSourcePositions(CurrentLocation, CurrentBlock, CurrentMeta))
{
- BLOCKTYPE PotentialBlock;
- NIBBLETYPE PotentialMeta;
- if ((Location.y < 0) || (Location.y > cChunkDef::Height))
+ if (!cChunk::IsValidHeight(Location.y))
{
continue;
}
+ BLOCKTYPE PotentialBlock;
+ NIBBLETYPE PotentialMeta;
m_World.GetBlockTypeMeta(Location.x, Location.y, Location.z, PotentialBlock, PotentialMeta);
auto PotentialSourceHandler = cIncrementalRedstoneSimulator::CreateComponent(m_World, PotentialBlock, &m_Data);