From 9b97d63f8f939dbc431cc2dcd9eddf959f86603a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 30 Apr 2021 14:23:46 +0100 Subject: Chest, weather, crash, and miscellaneous fixes (#5215) * Alpha-sort cChestEntity * Chests: use SendUpdateBlockEntity * Pathfinder: fix out of range Y * 1.13: correct weather packet ID * Chests: fix neighbour scanner + Add OnAddToWorld and overload to scan neighbours there, instead of in the constructor/OnUse. This fixes hoppers accessing newly loaded double chests and seeing a null m_Neighbour, thus thinking its a single chest. * Fix typo in cross coords computation. * Simplify hopper logic. * Block entities: ASSERT that type is correct If you match the block type first before calling DoWithBlockEntity, the corresponding block entity must either be empty or correspond to the block type. * Chunk: fix some forgotten PendingSendBE cleanup + Add cleanup in SetAllData, WriteBlockArea - Remove RemoveBlockEntity (used once), HasBlockEntity (not used) * Replace MakeIndex with MakeIndexNoCheck * Remove extraneous MarkDirty in hopper & chests --- src/Simulator/DelayedFluidSimulator.cpp | 14 +++++++------- src/Simulator/DelayedFluidSimulator.h | 4 ++-- .../IncrementalRedstoneSimulator/CommandBlockHandler.h | 5 +---- .../IncrementalRedstoneSimulator/DropSpenserHandler.h | 5 +---- src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h | 5 +---- .../IncrementalRedstoneSimulator/NoteBlockHandler.h | 5 +---- .../IncrementalRedstoneSimulator/TrappedChestHandler.h | 5 +---- 7 files changed, 14 insertions(+), 29 deletions(-) (limited to 'src/Simulator') diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp index b231f5fef..59f76a7f8 100644 --- a/src/Simulator/DelayedFluidSimulator.cpp +++ b/src/Simulator/DelayedFluidSimulator.cpp @@ -22,11 +22,11 @@ bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_R ASSERT(a_RelZ >= 0); ASSERT(a_RelZ < static_cast(ARRAYCOUNT(m_Blocks))); - cCoordWithIntVector & Blocks = m_Blocks[a_RelZ]; - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - for (cCoordWithIntVector::const_iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr) + auto & Blocks = m_Blocks[a_RelZ]; + const auto Index = cChunkDef::MakeIndex(a_RelX, a_RelY, a_RelZ); + for (const auto & Block : Blocks) { - if (itr->Data == Index) + if (Block.Data == Index) { // Already present return false; @@ -101,14 +101,14 @@ void cDelayedFluidSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a // Simulate all the blocks in the scheduled slot: for (size_t i = 0; i < ARRAYCOUNT(Slot.m_Blocks); i++) { - cCoordWithIntVector & Blocks = Slot.m_Blocks[i]; + auto & Blocks = Slot.m_Blocks[i]; if (Blocks.empty()) { continue; } - for (cCoordWithIntVector::iterator itr = Blocks.begin(), end = Blocks.end(); itr != end; ++itr) + for (const auto & Block : Blocks) { - SimulateBlock(a_Chunk, itr->x, itr->y, itr->z); + SimulateBlock(a_Chunk, Block.x, Block.y, Block.z); } m_TotalBlocks -= static_cast(Blocks.size()); Blocks.clear(); diff --git a/src/Simulator/DelayedFluidSimulator.h b/src/Simulator/DelayedFluidSimulator.h index 1a9f42a65..826489849 100644 --- a/src/Simulator/DelayedFluidSimulator.h +++ b/src/Simulator/DelayedFluidSimulator.h @@ -29,9 +29,9 @@ public: bool Add(int a_RelX, int a_RelY, int a_RelZ); /** Array of block containers, each item stores blocks for one Z coord - Int param is the block index (for faster duplicate comparison in Add()) + size_t param is the block index (for faster duplicate comparison in Add()) */ - cCoordWithIntVector m_Blocks[16]; + std::vector> m_Blocks[16]; } ; cDelayedFluidSimulatorChunkData(int a_TickDelay); diff --git a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h index 0a5ffe136..50ea6dcb6 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h @@ -33,10 +33,7 @@ namespace CommandBlockHandler a_Chunk.DoWithBlockEntityAt(a_Position, [](cBlockEntity & a_BlockEntity) { - if (a_BlockEntity.GetBlockType() != E_BLOCK_COMMAND_BLOCK) - { - return false; - } + ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_COMMAND_BLOCK); static_cast(a_BlockEntity).Activate(); return false; diff --git a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h index 4dd87e972..5f92c3868 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h @@ -48,10 +48,7 @@ namespace DropSpenserHandler { a_Chunk.DoWithBlockEntityAt(a_Position, [](cBlockEntity & a_BlockEntity) { - if ((a_BlockEntity.GetBlockType() != E_BLOCK_DISPENSER) && (a_BlockEntity.GetBlockType() != E_BLOCK_DROPPER)) - { - return false; - } + ASSERT((a_BlockEntity.GetBlockType() == E_BLOCK_DISPENSER) || (a_BlockEntity.GetBlockType() == E_BLOCK_DROPPER)); static_cast(a_BlockEntity).Activate(); return false; diff --git a/src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h b/src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h index ca820441c..95ef6ae62 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h @@ -43,10 +43,7 @@ namespace HopperHandler a_Chunk.DoWithBlockEntityAt(a_Position, [ShouldBeLocked](cBlockEntity & a_BlockEntity) { - if (a_BlockEntity.GetBlockType() != E_BLOCK_HOPPER) - { - return false; - } + ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_HOPPER); static_cast(a_BlockEntity).SetLocked(ShouldBeLocked); return false; diff --git a/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h b/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h index 8bd639357..fd96d8721 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h @@ -33,10 +33,7 @@ namespace NoteBlockHandler a_Chunk.DoWithBlockEntityAt(a_Position, [](cBlockEntity & a_BlockEntity) { - if (a_BlockEntity.GetBlockType() != E_BLOCK_NOTE_BLOCK) - { - return false; - } + ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_NOTE_BLOCK); static_cast(a_BlockEntity).MakeSound(); return false; diff --git a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h index 145c5dc83..d68e48997 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h @@ -24,10 +24,7 @@ namespace TrappedChestHandler int NumberOfPlayers = 0; a_Chunk.DoWithBlockEntityAt(a_Position, [&NumberOfPlayers](cBlockEntity & a_BlockEntity) { - if (a_BlockEntity.GetBlockType() != E_BLOCK_TRAPPED_CHEST) - { - return false; - } + ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_TRAPPED_CHEST); NumberOfPlayers = static_cast(a_BlockEntity).GetNumberOfPlayers(); return false; -- cgit v1.2.3