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/ChunkDef.h | 58 ++++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 48 deletions(-) (limited to 'src/ChunkDef.h') diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 673ae347a..12036cdbe 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -207,36 +207,22 @@ public: } - inline static int MakeIndex(int x, int y, int z) + inline static size_t MakeIndex(int x, int y, int z) { - if ( - (x < Width) && (x > -1) && - (y < Height) && (y > -1) && - (z < Width) && (z > -1) - ) - { - return MakeIndexNoCheck(x, y, z); - } - FLOGERROR("cChunkDef::MakeIndex(): coords out of range: {0}; returning fake index 0", Vector3i{x, y, z}); - ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!"); - return 0; - } - + ASSERT(IsValidRelPos({ x, y, z })); - inline static int MakeIndexNoCheck(int x, int y, int z) - { #if AXIS_ORDER == AXIS_ORDER_XZY // For some reason, NOT using the Horner schema is faster. Weird. - return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 uses XZY + return static_cast(x + (z * Width) + (y * Width * Width)); // 1.2 uses XZY #elif AXIS_ORDER == AXIS_ORDER_YZX - return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 uses YZX + return static_cast(y + (z * Width) + (x * Height * Width)); // 1.1 uses YZX #endif } - inline static int MakeIndexNoCheck(Vector3i a_RelPos) + inline static size_t MakeIndex(Vector3i a_RelPos) { - return MakeIndexNoCheck(a_RelPos.x, a_RelPos.y, a_RelPos.z); + return MakeIndex(a_RelPos.x, a_RelPos.y, a_RelPos.z); } @@ -263,7 +249,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type; + a_BlockTypes[MakeIndex(a_X, a_Y, a_Z)] = a_Type; } @@ -277,7 +263,7 @@ public: inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, Vector3i a_RelPos) { ASSERT(IsValidRelPos(a_RelPos)); - return a_BlockTypes[MakeIndexNoCheck(a_RelPos)]; + return a_BlockTypes[MakeIndex(a_RelPos)]; } @@ -286,7 +272,7 @@ public: ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Y >= 0) && (a_Y < Height)); ASSERT((a_Z >= 0) && (a_Z < Width)); - return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)]; + return a_BlockTypes[MakeIndex(a_X, a_Y, a_Z)]; } @@ -333,8 +319,7 @@ public: { if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) { - int Index = MakeIndexNoCheck(x, y, z); - return ExpandNibble(a_Buffer, static_cast(Index)); + return ExpandNibble(a_Buffer, MakeIndex(x, y, z)); } ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!"); return 0; @@ -436,7 +421,6 @@ struct sSetBlock } }; -typedef std::list sSetBlockList; typedef std::vector sSetBlockVector; typedef std::list cChunkCoordsList; @@ -461,27 +445,6 @@ public: -class cChunkCoordsWithBool -{ -public: - int m_ChunkX; - int m_ChunkZ; - bool m_ForceGenerate; - - cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_ForceGenerate(a_ForceGenerate){} - - bool operator == (const cChunkCoordsWithBool & a_Other) const - { - return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ) && (m_ForceGenerate == a_Other.m_ForceGenerate)); - } -}; - -typedef std::list cChunkCoordsWithBoolList; - - - - - /** Interface class used as a callback for operations that involve chunk coords */ class cChunkCoordCallback { @@ -518,7 +481,6 @@ public: } ; typedef cCoordWithData cCoordWithInt; -typedef cCoordWithData cCoordWithBlock; typedef std::list cCoordWithIntList; typedef std::vector cCoordWithIntVector; -- cgit v1.2.3