summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2016-07-29 00:39:13 +0200
committerGitHub <noreply@github.com>2016-07-29 00:39:13 +0200
commit47831ee933a5fb80808be9e98523d635f4dbc548 (patch)
treeea3f89419865fd4383865c39480ece19b793a4f6 /src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
parentTab completion across worlds (#3270) (diff)
parentConsolidated comparator code (diff)
downloadcuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar.gz
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar.bz2
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar.lz
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar.xz
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.tar.zst
cuberite-47831ee933a5fb80808be9e98523d635f4dbc548.zip
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
index 1ee68e521..f82ebdf94 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
@@ -39,14 +39,37 @@ public:
virtual cVector3iArray Update(const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) override
{
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
+ auto Data = static_cast<cIncrementalRedstoneSimulator *>(m_World.GetRedstoneSimulator())->GetChunkData();
+ auto DelayInfo = Data->GetMechanismDelayInfo(a_Position);
- if (a_PoweringData.PowerLevel > 0)
+ // Delay is used here to prevent an infinite loop (#3168)
+ if (DelayInfo == nullptr)
{
- cBlockPistonHandler::ExtendPiston(a_Position, &m_World);
+ bool ShouldBeExtended = (a_PoweringData.PowerLevel != 0);
+ if (ShouldBeExtended != cBlockPistonHandler::IsExtended(a_Meta))
+ {
+ Data->m_MechanismDelays[a_Position] = std::make_pair(1, ShouldBeExtended);
+ }
}
else
{
- cBlockPistonHandler::RetractPiston(a_Position, &m_World);
+ int DelayTicks;
+ bool ShouldBeExtended;
+ std::tie(DelayTicks, ShouldBeExtended) = *DelayInfo;
+
+ if (DelayTicks == 0)
+ {
+ if (ShouldBeExtended)
+ {
+ cBlockPistonHandler::ExtendPiston(a_Position, &m_World);
+ }
+ else
+ {
+ cBlockPistonHandler::RetractPiston(a_Position, &m_World);
+ }
+
+ Data->m_MechanismDelays.erase(a_Position);
+ }
}
return {};