From 225c2fa9f6bc2ebffcc9160090482e6833a220ce Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Jul 2020 01:18:59 +0100 Subject: Always use relative coordinates in AddBlock + Pass block, use relatives * Fixes everything immediately converting abs back to rel and getting block, when these data were already available --- src/Simulator/SandSimulator.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/Simulator/SandSimulator.cpp') diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index ef02339bc..95f514cc9 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -99,29 +99,23 @@ bool cSandSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType) void cSandSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) { - if ((a_Chunk == nullptr) || !a_Chunk->IsValid()) - { - return; - } - int RelX = a_Block.x - a_Chunk->GetPosX() * cChunkDef::Width; - int RelZ = a_Block.z - a_Chunk->GetPosZ() * cChunkDef::Width; - if (!IsAllowedBlock(a_Chunk->GetBlock(RelX, a_Block.y, RelZ))) + if (!IsAllowedBlock(a_Block)) { return; } // Check for duplicates: - cSandSimulatorChunkData & ChunkData = a_Chunk->GetSandSimulatorData(); + cSandSimulatorChunkData & ChunkData = a_Chunk.GetSandSimulatorData(); for (cSandSimulatorChunkData::iterator itr = ChunkData.begin(); itr != ChunkData.end(); ++itr) { - if ((itr->x == RelX) && (itr->y == a_Block.y) && (itr->z == RelZ)) + if ((itr->x == a_Position.x) && (itr->y == a_Position.y) && (itr->z == a_Position.z)) { return; } } m_TotalBlocks += 1; - ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ)); + ChunkData.push_back(cCoordWithInt(a_Position.x, a_Position.y, a_Position.z)); } -- cgit v1.2.3