summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2020-04-05 21:20:52 +0200
committerGitHub <noreply@github.com>2020-04-05 21:20:52 +0200
commit19ad96561c255fcc1e54ea3717a7d6afd50f5c92 (patch)
treeb8497aaae1885ef1497b0733458d469422966860 /src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
parentAdd potatoes to washed away list also (diff)
downloadcuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar.gz
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar.bz2
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar.lz
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar.xz
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.tar.zst
cuberite-19ad96561c255fcc1e54ea3717a7d6afd50f5c92.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
index ddd682288..6be03c947 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator/IncrementalRedstoneSimulator.cpp
@@ -157,8 +157,7 @@ void cIncrementalRedstoneSimulator::Simulate(float a_dt)
if (CurrentHandler == nullptr) // Block at CurrentPosition doesn't have a corresponding redstone handler
{
// Clean up cached PowerData for CurrentPosition
- static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData()->ErasePowerData(CurrentLocation);
-
+ GetChunkData()->ErasePowerData(CurrentLocation);
continue;
}
@@ -193,3 +192,63 @@ void cIncrementalRedstoneSimulator::Simulate(float a_dt)
}
}
}
+
+
+
+
+
+void cIncrementalRedstoneSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
+{
+ // Can't inspect block, so queue update anyway
+ if (a_Chunk == nullptr)
+ {
+ m_Data.WakeUp(a_Block);
+ return;
+ }
+
+ const auto RelPos = cChunkDef::AbsoluteToRelative(a_Block, a_Chunk->GetPos());
+ const auto CurBlock = a_Chunk->GetBlock(RelPos);
+
+ // Always update redstone devices
+ if (IsRedstone(CurBlock))
+ {
+ m_Data.WakeUp(a_Block);
+ return;
+ }
+
+ // Never update blocks without a handler
+ if (GetComponentHandler(CurBlock) == nullptr)
+ {
+ GetChunkData()->ErasePowerData(a_Block);
+ return;
+ }
+
+ // Only update others if there is a redstone device nearby
+ for (int x = -1; x < 2; ++x)
+ {
+ for (int y = -1; y < 2; ++y)
+ {
+ if (!cChunkDef::IsValidHeight(RelPos.y + y))
+ {
+ continue;
+ }
+
+ for (int z = -1; z < 2; ++z)
+ {
+ auto CheckPos = RelPos + Vector3i{x, y, z};
+ BLOCKTYPE Block;
+ NIBBLETYPE Meta;
+
+ // If we can't read the block, assume it is a mechanism
+ if (
+ !a_Chunk->UnboundedRelGetBlock(CheckPos, Block, Meta) ||
+ IsRedstone(Block)
+ )
+ {
+ m_Data.WakeUp(a_Block);
+ return;
+ }
+ }
+ }
+ }
+}