From d2156aab7cf25383c8f893e6222c89dcf5c17aa4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 Aug 2020 08:35:10 +0100 Subject: [PATCH] WakeUpSimulators correct Y computation + Add Y validity check to SimulatorManager --- src/Chunk.cpp | 13 +++++++------ src/Simulator/SimulatorManager.cpp | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 17c41acec..e24aa7733 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1187,14 +1187,14 @@ void cChunk::CreateBlockEntities(void) auto BlockType = Section->m_BlockTypes[BlockIdx]; if (cBlockEntity::IsBlockEntityBlockType(BlockType)) { - auto relPos = IndexToCoordinate(BlockIdx); - relPos.y += static_cast(SectionIdx * cChunkData::SectionHeight); - auto absPos = RelativeToAbsolute(relPos); + auto RelPos = IndexToCoordinate(BlockIdx); + RelPos.y += static_cast(SectionIdx * cChunkData::SectionHeight); + const auto AbsPos = RelativeToAbsolute(RelPos); - if (!HasBlockEntityAt(absPos)) + if (!HasBlockEntityAt(AbsPos)) { AddBlockEntityClean(cBlockEntity::CreateByBlockType( - BlockType, GetMeta(relPos), absPos, m_World + BlockType, GetMeta(RelPos), AbsPos, m_World )); } } @@ -1223,7 +1223,8 @@ void cChunk::WakeUpSimulators(void) for (size_t BlockIdx = 0; BlockIdx != cChunkData::SectionBlockCount; ++BlockIdx) { const auto BlockType = Section->m_BlockTypes[BlockIdx]; - const auto Position = IndexToCoordinate(BlockIdx); + auto Position = IndexToCoordinate(BlockIdx); + Position.y += static_cast(SectionIdx * cChunkData::SectionHeight); RedstoneSimulator->AddBlock(*this, Position, BlockType); WaterSimulator->AddBlock(*this, Position, BlockType); diff --git a/src/Simulator/SimulatorManager.cpp b/src/Simulator/SimulatorManager.cpp index 07b4a7214..81044d705 100644 --- a/src/Simulator/SimulatorManager.cpp +++ b/src/Simulator/SimulatorManager.cpp @@ -71,8 +71,12 @@ void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position) for (const auto Offset : cSimulator::AdjacentOffsets) { auto Relative = a_Position + Offset; - auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative); + if (!cChunkDef::IsValidHeight(Relative.y)) + { + continue; + } + auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative); if ((Chunk == nullptr) || !Chunk->IsValid()) { continue;