From fe983a1a45b23c67cf6c758a4f0ffe6a8ba764d6 Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Wed, 20 Apr 2022 00:10:35 +0200 Subject: Valid Height is now checked by vector. --- src/World.cpp | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index d0cca09db..77230e5b8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -850,42 +850,37 @@ bool cWorld::CanSpawnAt(int a_X, int & a_Y, int a_Z) -bool cWorld::CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ) +bool cWorld::CheckPlayerSpawnPoint(Vector3i a_Pos) { // Check height bounds - if (!cChunkDef::IsValidHeight(a_PosY)) + if (!cChunkDef::IsValidHeight(a_Pos)) { return false; } // Check that surrounding blocks are neither solid or liquid - static const Vector3i SurroundingCoords[] = - { - Vector3i(0, 0, 1), - Vector3i(1, 0, 1), - Vector3i(1, 0, 0), - Vector3i(1, 0, -1), - Vector3i(0, 0, -1), - Vector3i(-1, 0, -1), - Vector3i(-1, 0, 0), - Vector3i(-1, 0, 1), - }; - - static const int SurroundingCoordsCount = ARRAYCOUNT(SurroundingCoords); - - for (int CoordIndex = 0; CoordIndex < SurroundingCoordsCount; ++CoordIndex) - { - const int XPos = a_PosX + SurroundingCoords[CoordIndex].x; - const int ZPos = a_PosZ + SurroundingCoords[CoordIndex].z; - - const BLOCKTYPE BlockType = GetBlock({ XPos, a_PosY, ZPos }); + constexpr std::array SurroundingCoords = + {{ + {0, 0, 1}, + {1, 0, 1}, + {1, 0, 0}, + {1, 0, -1}, + {0, 0, -1}, + {-1, 0, -1}, + {-1, 0, 0}, + {-1, 0, 1}, + }}; + + for (const auto & Offset : SurroundingCoords) + { + const BLOCKTYPE BlockType = GetBlock(a_Pos + Offset); if (cBlockInfo::IsSolid(BlockType) || IsBlockLiquid(BlockType)) { - return false; + return true; } } - return true; + return false; } -- cgit v1.2.3