diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1644cba0f5..4f058dc444 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,7 +53,7 @@ Here are the conventions: - `dimNether`, `dimOverworld` and `dimEnd` for world dimension. - `gmSurvival`, `gmCreative`, `gmAdventure` for game modes. - `wSunny`, `wRain`, `wThunderstorm` for weather. - - `cChunkDef::Width`, `cChunkDef::Height` for chunk dimensions (C++). + - `cChunkDef::Width`, `cChunkDef::LowerLimit`, `cChunkDef::UpperLimit` for chunk dimensions. - etc. - Instead of checking for a specific value, use an `IsXXX` function, if available: - `cPlayer:IsGameModeCreative()` instead of` (cPlayer:GetGameMode() == gmCreative)` (the player can also inherit the gamemode from the world, which the value-d condition doesn't catch). diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 89e9955a96..7d52a92b0a 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -535,6 +535,36 @@ return }, }, }, + cChunkDef = + { + Desc = [[ + This class contains constants and functions that are useful for dealing with chunks. The constants + are mostly used for specifying chunk coordinate ranges. + ]], + Constants = + { + Width = + { + Notes = "The width of a chunk, in number of blocks.", + }, + LowerLimit = + { + Notes = "The lower limit of the chunk coordinate vertical range.", + }, + UpperLimit = + { + Notes = "The upper limit of the chunk coordinate vertical range.", + }, + VerticalBlockCount = + { + Notes = "The number of blocks in the vertical direction in a chunk.", + }, + NumBlocks = + { + Notes = "The total number of blocks in a chunk.", + }, + }, + }, cChunkDesc = { Desc = [[ diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 40ab0467b4..999d3686d7 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -4516,6 +4516,7 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, nullptr); // Create the new classes: + tolua_usertype(tolua_S, "cChunkDef"); tolua_usertype(tolua_S, "cCryptoHash"); tolua_usertype(tolua_S, "cLineBlockTracer"); tolua_usertype(tolua_S, "cStringCompression"); @@ -4546,6 +4547,14 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "Intersect", tolua_cBoundingBox_Intersect); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cChunkDef"); + tolua_constant(tolua_S, "Width", cChunkDef::Width); + tolua_constant(tolua_S, "LowerLimit", cChunkDef::LowerLimit); + tolua_constant(tolua_S, "UpperLimit", cChunkDef::UpperLimit); + tolua_constant(tolua_S, "VerticalBlockCount", cChunkDef::VerticalBlockCount); + tolua_constant(tolua_S, "NumBlocks", cChunkDef::NumBlocks); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cChunkDesc"); tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cChunkDesc_GetBlockTypeMeta); tolua_endmodule(tolua_S); diff --git a/src/Bindings/ManualBindings_BlockArea.cpp b/src/Bindings/ManualBindings_BlockArea.cpp index c363e082f2..315a3106c0 100644 --- a/src/Bindings/ManualBindings_BlockArea.cpp +++ b/src/Bindings/ManualBindings_BlockArea.cpp @@ -786,17 +786,17 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState) // ... Or should we silently clone-crop-write the cBlockArea so that the API call does what would be naturally expected? // ... Or should we change the cBlockArea::Write() to allow out-of-range Y coords and do the cropping there? // ... NOTE: We already support auto-crop in cBlockArea::Merge() itself - if (coords.y < 0) + if (coords.y < cChunkDef::LowerLimit) { - LOGWARNING("cBlockArea:Write(): MinBlockY less than zero, adjusting to zero"); + LOGWARNING("cBlockArea:Write(): MinBlockY less than lower limit, adjusting to lower limit"); L.LogStackTrace(); - coords.y = 0; + coords.y = cChunkDef::LowerLimit; } - else if (coords.y > cChunkDef::Height - self->GetSizeY()) + else if (coords.y > cChunkDef::UpperLimit - self->GetSizeY()) { LOGWARNING("cBlockArea:Write(): MinBlockY + m_SizeY more than chunk height, adjusting to chunk height"); L.LogStackTrace(); - coords.y = cChunkDef::Height - self->GetSizeY(); + coords.y = cChunkDef::UpperLimit - self->GetSizeY(); } // Do the actual write: diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 65ada4682a..d6010607a9 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -343,7 +343,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes) ASSERT(IsValidDataTypeCombination(a_DataTypes)); // Warn if the height is too much, but proceed with the creation: - if (a_SizeY > cChunkDef::Height) + if (a_SizeY > cChunkDef::UpperLimit) { LOGWARNING("Creating a cBlockArea with height larger than world height (%d). Continuing, but the area may misbehave.", a_SizeY); } diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index bff1b2e180..651484b611 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -139,7 +139,7 @@ bool cBeaconEntity::SetSecondaryEffect(cEntityEffect::eType a_Effect) bool cBeaconEntity::IsBeaconBlocked(void) { - for (int Y = m_Pos.y; Y < cChunkDef::Height; ++Y) + for (int Y = m_Pos.y; Y < cChunkDef::UpperLimit; ++Y) { BLOCKTYPE Block = m_World->GetBlock({m_Pos.x, Y, m_Pos.z}); if (!cBlockInfo::IsTransparent(Block)) @@ -234,7 +234,7 @@ void cBeaconEntity::GiveEffects(void) bool HasSecondaryEffect = (m_BeaconLevel >= 4) && (m_PrimaryEffect != m_SecondaryEffect) && (m_SecondaryEffect > 0); - auto Area = cBoundingBox(m_Pos, Radius, Radius + static_cast(cChunkDef::Height), -Radius); + auto Area = cBoundingBox(m_Pos, Radius, Radius + static_cast(cChunkDef::UpperLimit), -Radius); GetWorld()->ForEachEntityInBox(Area, [&](cEntity & a_Entity) { if (!a_Entity.IsPlayer()) diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 11146bf46d..4fa12eb4fe 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -95,7 +95,7 @@ void cChestEntity::DestroyWindow() bool cChestEntity::IsBlocked() { return ( - (GetPosY() < cChunkDef::Height - 1) && + cChunkDef::IsValidHeight(GetPosY(), 1) && ( !cBlockInfo::IsTransparent(GetWorld()->GetBlock(GetPos().addedY(1))) || !cOcelot::IsCatSittingOnBlock(GetWorld(), Vector3d(GetPos())) diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index 07cc8aa181..3eb7cf9d4f 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -51,7 +51,7 @@ void cEnderChestEntity::OnRemoveFromWorld() bool cEnderChestEntity::UsedBy(cPlayer * a_Player) { if ( - (GetPosY() < cChunkDef::Height - 1) && + cChunkDef::IsValidHeight(GetPosY(), 1) && ( !cBlockInfo::IsTransparent(GetWorld()->GetBlock(GetPos().addedY(1))) || !cOcelot::IsCatSittingOnBlock(GetWorld(), Vector3d(GetPos())) diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index d7faca174f..6312aca706 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -150,7 +150,7 @@ void cHopperEntity::OpenNewWindow(void) bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, const cTickTimeLong a_CurrentTick) { - if (m_Pos.y >= cChunkDef::Height) + if (m_Pos.y >= cChunkDef::UpperLimit) { // This hopper is at the top of the world, no more blocks above return false; diff --git a/src/BlockTracer.h b/src/BlockTracer.h index 62ae1636e8..d2ea6f7f4a 100644 --- a/src/BlockTracer.h +++ b/src/BlockTracer.h @@ -52,7 +52,7 @@ class cBlockTracer abstract return false; } - /** Called when the path goes out of world, either below (a_BlockPos.y < 0) or above (a_BlockPos.y >= cChunkDef::Height) + /** Called when the path goes out of world, either below (a_BlockPos.y < cChunkDef::LowerLimit) or above (a_BlockPos.y >= cChunkDef::UpperLimit) The coords specify the exact point at which the path exited the world. If this callback returns true, the tracing is aborted. Note that some paths can go out of the world and come back again (parabola), @@ -64,7 +64,7 @@ class cBlockTracer abstract return false; } - /** Called when the path goes into the world, from either below (a_BlockPos.y < 0) or above (a_BlockPos.y >= cChunkDef::Height) + /** Called when the path goes into the world, from either below (a_BlockPos.y < cChunkDef::LowerLimit) or above (a_BlockPos.y >= cChunkDef::UpperLimit) The coords specify the exact point at which the path entered the world. If this callback returns true, the tracing is aborted. Note that some paths can go out of the world and come back again (parabola), diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 1b2c0d735f..381d5495fc 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -104,7 +104,7 @@ class cBlockBigFlowerHandler final : // Both parts can only that they're rooted in grass. const auto RootPosition = a_Position.addedY(IsMetaTopPart(a_Meta) ? -2 : -1); - return (RootPosition.y >= 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(RootPosition)); + return (RootPosition.y >= cChunkDef::LowerLimit) && IsBlockTypeOfDirt(a_Chunk.GetBlock(RootPosition)); } diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 23c4d34210..9346c68346 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -77,7 +77,7 @@ class cBlockCactusHandler final : // Check the total height of the cacti blocks here: int top = a_RelPos.y + 1; while ( - (top < cChunkDef::Height) && + (cChunkDef::IsValidHeight(top)) && (a_Chunk.GetBlock({a_RelPos.x, top, a_RelPos.z}) == E_BLOCK_CACTUS) ) { @@ -85,7 +85,7 @@ class cBlockCactusHandler final : } int bottom = a_RelPos.y - 1; while ( - (bottom > 0) && + (cChunkDef::IsValidHeight(bottom, 0, 1)) && (a_Chunk.GetBlock({a_RelPos.x, bottom, a_RelPos.z}) == E_BLOCK_CACTUS) ) { @@ -143,7 +143,7 @@ class cBlockCactusHandler final : virtual PlantAction CanGrow(cChunk & a_Chunk, Vector3i a_RelPos) const override { // Only allow growing if there's an air block above: - if (((a_RelPos.y + 1) < cChunkDef::Height) && (a_Chunk.GetBlock(a_RelPos.addedY(1)) == E_BLOCK_AIR)) + if (cChunkDef::IsValidHeight(a_RelPos.addedY(1)) && (a_Chunk.GetBlock(a_RelPos.addedY(1)) == E_BLOCK_AIR)) { return Super::CanGrow(a_Chunk, a_RelPos); } diff --git a/src/Blocks/BlockCarpet.h b/src/Blocks/BlockCarpet.h index 841e94b113..b42ec5f3d4 100644 --- a/src/Blocks/BlockCarpet.h +++ b/src/Blocks/BlockCarpet.h @@ -27,7 +27,7 @@ class cBlockCarpetHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - return (a_Position.y > 0) && (a_Chunk.GetBlock(a_Position.addedY(-1)) != E_BLOCK_AIR); + return (a_Position.y > cChunkDef::LowerLimit) && (a_Chunk.GetBlock(a_Position.addedY(-1)) != E_BLOCK_AIR); } diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 90a5badc9c..4ba2e6e1d9 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -118,7 +118,7 @@ class cBlockCropsHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - return (a_Position.y > 0) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_FARMLAND); + return (a_Position.y > cChunkDef::LowerLimit) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_FARMLAND); } diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index d97bd9696b..ca6883d203 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -21,7 +21,7 @@ void cBlockDoorHandler::OnBroken( if ((a_OldBlockMeta & 0x08) != 0) { const auto Lower = a_BlockPos.addedY(-1); - if ((Lower.y >= 0) && IsDoorBlockType(a_ChunkInterface.GetBlock(Lower))) + if ((Lower.y >= cChunkDef::LowerLimit) && IsDoorBlockType(a_ChunkInterface.GetBlock(Lower))) { // Was upper part of door, remove lower: a_ChunkInterface.SetBlock(Lower, E_BLOCK_AIR, 0); @@ -30,7 +30,7 @@ void cBlockDoorHandler::OnBroken( else { const auto Upper = a_BlockPos.addedY(1); - if ((Upper.y < cChunkDef::Height) && IsDoorBlockType(a_ChunkInterface.GetBlock(Upper))) + if (cChunkDef::IsValidHeight(Upper) && IsDoorBlockType(a_ChunkInterface.GetBlock(Upper))) { // Was lower part, remove upper: a_ChunkInterface.SetBlock(Upper, E_BLOCK_AIR, 0); diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 1b5c33d46e..4bf3c43885 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -113,7 +113,7 @@ class cBlockDoorHandler final : else { // The block is the top part of the door, set the meta to the corresponding top part - if (a_BlockPos.y > 0) + if (a_BlockPos.y > cChunkDef::LowerLimit) { a_ChunkInterface.SetBlockMeta(a_BlockPos.addedY(-1), NewMeta); } @@ -198,7 +198,7 @@ class cBlockDoorHandler final : const auto BasePosition = a_Position.addedY(((a_Meta & 0x8) == 0x8) ? -2 : -1); a_Chunk.GetBlockTypeMeta(BasePosition, BlockType, BlockMeta); - return (BasePosition.y >= 0) && CanBeOn(BlockType, BlockMeta); + return (BasePosition.y >= cChunkDef::LowerLimit) && CanBeOn(BlockType, BlockMeta); } @@ -216,7 +216,7 @@ class cBlockDoorHandler final : if ((Meta & 0x08) != 0) { // The coords are pointing at the top part of the door - if (a_BlockPos.y > 0) + if (a_BlockPos.y > cChunkDef::LowerLimit) { NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta(a_BlockPos.addedY(-1)); return static_cast((DownMeta & 0x07) | 0x08 | (Meta << 4)); @@ -227,7 +227,7 @@ class cBlockDoorHandler final : else { // The coords are pointing at the bottom part of the door - if (a_BlockPos.y < cChunkDef::Height - 1) + if (cChunkDef::IsValidHeight(a_BlockPos.y, 1)) { NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta(a_BlockPos.addedY(1)); return static_cast(Meta | (UpMeta << 4)); diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index 9a458a1d63..29feab8bd5 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -159,7 +159,7 @@ class cBlockFarmlandHandler final : } // Don't care about anything if we're at the top of the world: - if (a_BlockPos.y >= cChunkDef::Height) + if (a_BlockPos.y >= cChunkDef::UpperLimit) { return; } diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index a0f5e9a693..2bf1d9c44a 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -74,7 +74,7 @@ class cBlockFireHandler final : return 0; } - for (int newY = Y + 1; newY < cChunkDef::Height; newY++) + for (int newY = Y + 1; newY < cChunkDef::UpperLimit; newY++) { BLOCKTYPE Block = a_ChunkInterface.GetBlock({X, newY, Z}); if ((Block == E_BLOCK_AIR) || (Block == E_BLOCK_FIRE)) diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h index 023ba4a372..6199f6d7de 100644 --- a/src/Blocks/BlockFlower.h +++ b/src/Blocks/BlockFlower.h @@ -30,7 +30,7 @@ class cBlockFlowerHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - return (a_Position.y > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_Position.addedY(-1))); + return (a_Position.y > cChunkDef::LowerLimit) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_Position.addedY(-1))); } diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index c5e46926b0..50a9a945f5 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -82,7 +82,7 @@ class cBlockLeavesHandler final : } return false; }; - for (int y = std::max(a_BlockPos.y - i, 0); y <= std::min(a_BlockPos.y + i, cChunkDef::Height - 1); y++) + for (int y = std::max(a_BlockPos.y - i, cChunkDef::LowerLimit); y <= std::min(a_BlockPos.y + i, cChunkDef::UpperLimit - 1); y++) { for (int z = a_BlockPos.z - i; z <= a_BlockPos.z + i; z++) { diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index 43081d511f..21de9dea07 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -60,7 +60,7 @@ class cBlockNetherWartHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { // Needs to be placed on top of a Soulsand block: - return (a_Position.y > 0) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_SOULSAND); + return (a_Position.y > cChunkDef::LowerLimit) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_SOULSAND); } diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index 05daa9337e..01362e54c4 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -51,7 +51,7 @@ class cBlockPortalHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - if ((a_Position.y <= 0) || (a_Position.y >= cChunkDef::Height - 1)) + if ((a_Position.y <= cChunkDef::LowerLimit) || (a_Position.y >= cChunkDef::UpperLimit - 1)) { return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1. } diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index d32b9b449b..2c9e7ce70a 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -31,7 +31,7 @@ class cBlockSaplingHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - return (a_Position.y > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_Position.addedY(-1))); + return (a_Position.y > cChunkDef::LowerLimit) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_Position.addedY(-1))); } @@ -137,7 +137,7 @@ class cBlockSaplingHandler final : ASSERT(CheckHeight != 0); // Don't grow a tree if we don't have enough space left above it in the chunk - if ((a_RelY + CheckHeight) > cChunkDef::Height) + if (!cChunkDef::IsValidHeight(a_RelY + CheckHeight)) { return false; } diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index f6686b25a7..d144187eee 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -58,7 +58,7 @@ class cBlockStemsHandler final : virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { - return (a_Position.y > 0) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_FARMLAND); + return (a_Position.y > cChunkDef::LowerLimit) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_FARMLAND); } diff --git a/src/Blocks/BlockSugarCane.h b/src/Blocks/BlockSugarCane.h index cffe667e5f..fefe7b2eb8 100644 --- a/src/Blocks/BlockSugarCane.h +++ b/src/Blocks/BlockSugarCane.h @@ -92,7 +92,7 @@ class cBlockSugarCaneHandler final : // Check the total height of the sugarcane blocks here: int top = a_RelPos.y + 1; while ( - (top < cChunkDef::Height) && + (cChunkDef::IsValidHeight(top)) && (a_Chunk.GetBlock({a_RelPos.x, top, a_RelPos.z}) == E_BLOCK_SUGARCANE) ) { @@ -127,7 +127,7 @@ class cBlockSugarCaneHandler final : virtual PlantAction CanGrow(cChunk & a_Chunk, Vector3i a_RelPos) const override { // Only allow growing if there's an air block above: - if (((a_RelPos.y + 1) < cChunkDef::Height) && (a_Chunk.GetBlock(a_RelPos.addedY(1)) == E_BLOCK_AIR)) + if (cChunkDef::IsValidHeight(a_RelPos.addedY(1)) && (a_Chunk.GetBlock(a_RelPos.addedY(1)) == E_BLOCK_AIR)) { return Super::CanGrow(a_Chunk, a_RelPos); } diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index ea638c8781..f60b525939 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -70,7 +70,7 @@ class cBlockTallGrassHandler final : /** Growing a tall grass produces a big flower (2-block high fern or double-tall grass). */ virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) const override { - if (a_RelPos.y > (cChunkDef::Height - 2)) + if (a_RelPos.y > (cChunkDef::UpperLimit - 2)) { return 0; } diff --git a/src/Blocks/BlockVines.h b/src/Blocks/BlockVines.h index a23ba1489b..a5a157605c 100644 --- a/src/Blocks/BlockVines.h +++ b/src/Blocks/BlockVines.h @@ -119,7 +119,7 @@ class cBlockVinesHandler final : } // Check if vine above us, add its meta to MaxMeta: - if ((a_Position.y < cChunkDef::Height - 1) && (a_Chunk.GetBlock(a_Position.addedY(1)) == E_BLOCK_VINES)) + if (cChunkDef::IsValidHeight(a_Position.y, 1) && (a_Chunk.GetBlock(a_Position.addedY(1)) == E_BLOCK_VINES)) { MaxMeta |= a_Chunk.GetMeta(a_Position.addedY(1)); } @@ -127,7 +127,7 @@ class cBlockVinesHandler final : NIBBLETYPE Common = a_CurrentMeta & MaxMeta; // Neighbors that we have and are legal. if (Common != a_CurrentMeta) { - bool HasTop = (a_Position.y < (cChunkDef::Height - 1)) && IsBlockAttachable(a_Chunk.GetBlock(a_Position.addedY(1))); + bool HasTop = (a_Position.y < (cChunkDef::UpperLimit - 1)) && IsBlockAttachable(a_Chunk.GetBlock(a_Position.addedY(1))); if ((Common == 0) && !HasTop) // Meta equals 0 also means top. Make a last-ditch attempt to save the vine. { return VINE_LOST_SUPPORT; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a693e08e67..18e2f1f7fb 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -435,7 +435,7 @@ void cChunk::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock int BlockEndZ = std::min(a_MinBlockZ + a_Area.GetSizeZ(), (m_PosZ + 1) * cChunkDef::Width); int SizeX = BlockEndX - BlockStartX; // Size of the union int SizeZ = BlockEndZ - BlockStartZ; - int SizeY = std::min(a_Area.GetSizeY(), cChunkDef::Height - a_MinBlockY); + int SizeY = std::min(a_Area.GetSizeY(), cChunkDef::UpperLimit - a_MinBlockY); int OffX = BlockStartX - m_PosX * cChunkDef::Width; // Offset within the chunk where the union starts int OffZ = BlockStartZ - m_PosZ * cChunkDef::Width; int BaseX = BlockStartX - a_MinBlockX; // Offset within the area where the union starts @@ -600,7 +600,7 @@ void cChunk::GetRandomBlockCoords(int & a_X, int & a_Y, int & a_Z) // MG TODO : check if this kind of optimization (only one random call) is still needed // MG TODO : if so propagate it - GetThreeRandomNumbers(a_X, a_Y, a_Z, cChunkDef::Width, cChunkDef::Height - 2, cChunkDef::Width); + GetThreeRandomNumbers(a_X, a_Y, a_Z, cChunkDef::Width, cChunkDef::UpperLimit - 2, cChunkDef::Width); a_Y++; } @@ -636,8 +636,7 @@ void cChunk::SpawnMobs(cMobSpawner & a_MobSpawner) TryY += CenterY; TryZ += CenterZ; - ASSERT(TryY > 0); - ASSERT(TryY < cChunkDef::Height - 1); + ASSERT(cChunkDef::IsValidHeight(TryY, 1)); int WorldX, WorldY, WorldZ; PositionToWorldPosition(TryX, TryY, TryZ, WorldX, WorldY, WorldZ); @@ -935,7 +934,7 @@ void cChunk::ApplyWeatherToTop() FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1); } } - else if (cBlockInfo::IsSnowable(TopBlock) && (Height < cChunkDef::Height - 1)) + else if (cChunkDef::IsValidHeight(TopBlock, 1) && cBlockInfo::IsSnowable(TopBlock)) { SetBlock({X, Height + 1, Z}, E_BLOCK_SNOW, 0); } @@ -1210,7 +1209,7 @@ bool cChunk::IsWeatherWetAt(const Vector3i a_Position) const return false; } - if (a_Position.y >= cChunkDef::Height) + if (a_Position.y >= cChunkDef::UpperLimit) { return true; } @@ -1354,7 +1353,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT } else { - for (int y = a_RelY - 1; y > 0; --y) + for (int y = a_RelY - 1; y > cChunkDef::LowerLimit; --y) { if (GetBlock(a_RelX, y, a_RelZ) != E_BLOCK_AIR) { diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 11ef96e815..9b9e43a1a1 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -99,17 +99,19 @@ class cChunkCoords /** Constants used throughout the code, useful typedefs and utility functions */ -class cChunkDef -{ -public: +class cChunkDef // tolua_export +{ // tolua_export +public: // tolua_export - // Chunk dimensions: + // Chunk dimensions, exported in ManualBindings.cpp static const int Width = 16; - static const int Height = 256; - static const int NumBlocks = Width * Height * Width; + static constexpr int LowerLimit = 0; // Lower Limit for chunk coordinates (for future use, when negative height is supported). MUST BE NEGATIVE OR ZERO! + static const int UpperLimit = 256; + static constexpr int VerticalBlockCount = UpperLimit - LowerLimit; + static const int NumBlocks = Width * VerticalBlockCount * Width; static const int SectionHeight = 16; - static const size_t NumSections = (cChunkDef::Height / SectionHeight); + static const size_t NumSections = (VerticalBlockCount / SectionHeight); /** The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the highest non-air block in the column */ typedef HEIGHTTYPE HeightMap[Width * Width]; @@ -164,21 +166,34 @@ class cChunkDef } - /** Validates a height-coordinate. Returns false if height-coordinate is out of height bounds */ - inline static bool IsValidHeight(Vector3i a_BlockPosition) + /** Validates a height-coordinate. Returns false if height-coordinate is out of height bounds. + Might be enclosed by a_SpaceBelow and a_SpaceAbove. [LowerLimit + a_SpaceBelow, UpperLimit - a_SpaceAbove) is valid. */ + inline static bool IsValidHeight(Vector3i a_BlockPosition, int a_SpaceAbove = 0, int a_SpaceBelow = 0) + { + ASSERT(a_SpaceBelow >= 0); + ASSERT(a_SpaceAbove >= 0); + return ((a_BlockPosition.y >= LowerLimit + a_SpaceBelow) && (a_BlockPosition.y < UpperLimit - a_SpaceAbove)); + } + + /** DEPRECATED!!! Validates a height-coordinate. Returns false if height-coordinate is out of height bounds. + Might be enclosed by a_SpaceBelow and a_SpaceAbove. [LowerLimit + a_SpaceBelow, UpperLimit - a_SpaceAbove) is valid. + @deprecated */ + inline static bool IsValidHeight(int a_Height, int a_SpaceAbove = 0, int a_SpaceBelow = 0) { - return ((a_BlockPosition.y >= 0) && (a_BlockPosition.y < Height)); + ASSERT(a_SpaceBelow >= 0); + ASSERT(a_SpaceAbove >= 0); + return ((a_Height >= LowerLimit + a_SpaceBelow) && (a_Height < UpperLimit - a_SpaceAbove)); } - /** Validates a width-coordinate. Returns false if width-coordiante is out of width bounds */ + /** Validates a width-coordinate. Returns false if width-coordinate is out of width bounds */ inline static bool IsValidWidth(int a_Width) { return ((a_Width >= 0) && (a_Width < Width)); } - /** Validates a chunk relative coordinate. Returns false if the coordiante is out of bounds for a chunk. */ + /** Validates a chunk relative coordinate. Returns false if the coordinate is out of bounds for a chunk. */ inline static bool IsValidRelPos(Vector3i a_RelPos) { return ( @@ -215,7 +230,7 @@ class cChunkDef // For some reason, NOT using the Horner schema is faster. Weird. return static_cast(x + (z * Width) + (y * Width * Width)); // 1.2 uses XZY #elif AXIS_ORDER == AXIS_ORDER_YZX - return static_cast(y + (z * Width) + (x * Height * Width)); // 1.1 uses YZX + return static_cast(y + (z * Width) + (x * UpperLimit * Width)); // 1.1 uses YZX #endif } @@ -236,9 +251,9 @@ class cChunkDef ); #elif AXIS_ORDER == AXIS_ORDER_YZX return Vector3i( // 1.1 - static_cast(index / (cChunkDef::Height * cChunkDef::Width)), // X - static_cast(index % cChunkDef::Height), // Y - static_cast((index / cChunkDef::Height) % cChunkDef::Width) // Z + static_cast(index / (cChunkDef::UpperLimit * cChunkDef::Width)), // X + static_cast(index % cChunkDef::UpperLimit), // Y + static_cast((index / cChunkDef::UpperLimit) % cChunkDef::Width) // Z ); #endif } @@ -247,7 +262,7 @@ class cChunkDef inline static void SetBlock(BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type) { ASSERT((a_X >= 0) && (a_X < Width)); - ASSERT((a_Y >= 0) && (a_Y < Height)); + ASSERT((a_Y >= LowerLimit) && (a_Y < UpperLimit)); ASSERT((a_Z >= 0) && (a_Z < Width)); a_BlockTypes[MakeIndex(a_X, a_Y, a_Z)] = a_Type; } @@ -255,7 +270,7 @@ class cChunkDef inline static void SetBlock(BLOCKTYPE * a_BlockTypes, int a_Index, BLOCKTYPE a_Type) { - ASSERT((a_Index >= 0) && (a_Index <= NumBlocks)); + ASSERT((a_Index >= LowerLimit) && (a_Index <= NumBlocks)); a_BlockTypes[a_Index] = a_Type; } @@ -270,7 +285,7 @@ class cChunkDef inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); - ASSERT((a_Y >= 0) && (a_Y < Height)); + ASSERT((a_Y >= LowerLimit) && (a_Y < UpperLimit)); ASSERT((a_Z >= 0) && (a_Z < Width)); return a_BlockTypes[MakeIndex(a_X, a_Y, a_Z)]; } @@ -317,7 +332,11 @@ class cChunkDef static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z) { - if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1)) + if ( + (x < Width) && (x >= 0) && + (y < UpperLimit) && (y >= LowerLimit) && + (z < Width) && (z >= 0) + ) { return ExpandNibble(a_Buffer, MakeIndex(x, y, z)); } @@ -341,7 +360,7 @@ class cChunkDef { return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f; } -} ; +} ; // tolua_export diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7fc678de00..1043aea745 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -61,7 +61,7 @@ int cClientHandle::s_ClientCount = 0; float cClientHandle::FASTBREAK_PERCENTAGE; -Vector3i cClientHandle::s_IllegalPosition = {0, cChunkDef::Height + 1, 0}; +Vector3i cClientHandle::s_IllegalPosition = {0, cChunkDef::UpperLimit + 1, 0}; diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 9ad0dd5f9e..1f85280b97 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -180,7 +180,7 @@ void cBoat::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed - if ((POSY_TOINT < 0) || (POSY_TOINT >= cChunkDef::Height)) + if ((POSY_TOINT < cChunkDef::LowerLimit) || (POSY_TOINT >= cChunkDef::UpperLimit)) { return; } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c46f9e6446..591947b16d 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -917,7 +917,7 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } // Non-players are destroyed as soon as they fall out of the world: - if ((GetPosY() < 0) && (!IsPlayer())) + if ((GetPosY() < cChunkDef::LowerLimit) && (!IsPlayer())) { Destroy(); return; @@ -1011,7 +1011,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); - if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) + if ((BlockY >= cChunkDef::UpperLimit) || (BlockY < cChunkDef::LowerLimit)) { // Outside of the world AddSpeedY(m_Gravity * DtSec.count()); @@ -1022,7 +1022,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ); - BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; + BLOCKTYPE BlockBelow = (BlockY > cChunkDef::LowerLimit) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground @@ -1365,8 +1365,8 @@ void cEntity::DetectCacti(void) int MaxX = FloorC(GetPosX() + m_Width / 2); int MinZ = FloorC(GetPosZ() - m_Width / 2); int MaxZ = FloorC(GetPosZ() + m_Width / 2); - int MinY = Clamp(POSY_TOINT, 0, cChunkDef::Height - 1); - int MaxY = Clamp(FloorC(GetPosY() + m_Height), 0, cChunkDef::Height - 1); + int MinY = Clamp(POSY_TOINT, 0, cChunkDef::UpperLimit - 1); + int MaxY = Clamp(FloorC(GetPosY() + m_Height), 0, cChunkDef::UpperLimit - 1); for (int x = MinX; x <= MaxX; x++) { @@ -1394,8 +1394,8 @@ void cEntity::DetectMagma(void) int MaxX = FloorC(GetPosX() + m_Width / 2); int MinZ = FloorC(GetPosZ() - m_Width / 2); int MaxZ = FloorC(GetPosZ() + m_Width / 2); - int MinY = Clamp(POSY_TOINT - 1, 0, cChunkDef::Height - 1); - int MaxY = Clamp(FloorC(GetPosY() + m_Height), 0, cChunkDef::Height - 1); + int MinY = Clamp(POSY_TOINT - 1, cChunkDef::LowerLimit, cChunkDef::UpperLimit - 1); + int MaxY = Clamp(FloorC(GetPosY() + m_Height), cChunkDef::LowerLimit, cChunkDef::UpperLimit - 1); for (int x = MinX; x <= MaxX; x++) { @@ -1476,7 +1476,7 @@ bool cEntity::DetectPortal() cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() LOGD("Jumping %s -> %s", DimensionToString(dimNether).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str()); - new cNetherPortalScanner(*this, *TargetWorld, TargetPos, cChunkDef::Height); + new cNetherPortalScanner(*this, *TargetWorld, TargetPos, cChunkDef::UpperLimit); return true; } // Nether portal in the overworld @@ -1496,7 +1496,7 @@ bool cEntity::DetectPortal() cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str()); - new cNetherPortalScanner(*this, *TargetWorld, TargetPos, (cChunkDef::Height / 2)); + new cNetherPortalScanner(*this, *TargetWorld, TargetPos, (cChunkDef::UpperLimit / 2)); return true; } } @@ -1708,7 +1708,7 @@ void cEntity::SetSwimState(cChunk & a_Chunk) int RelY = FloorC(GetPosY() + 0.1); int HeadRelY = CeilC(GetPosY() + GetHeight()) - 1; ASSERT(RelY <= HeadRelY); - if ((RelY < 0) || (HeadRelY >= cChunkDef::Height)) + if (!cChunkDef::IsValidHeight(HeadRelY)) { return; } @@ -1717,8 +1717,8 @@ void cEntity::SetSwimState(cChunk & a_Chunk) int MaxRelX = FloorC(GetPosX() + m_Width / 2) - a_Chunk.GetPosX() * cChunkDef::Width; int MinRelZ = FloorC(GetPosZ() - m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; int MaxRelZ = FloorC(GetPosZ() + m_Width / 2) - a_Chunk.GetPosZ() * cChunkDef::Width; - int MinY = Clamp(POSY_TOINT, 0, cChunkDef::Height - 1); - int MaxY = Clamp(FloorC(GetPosY() + m_Height), 0, cChunkDef::Height - 1); + int MinY = Clamp(POSY_TOINT, cChunkDef::LowerLimit, cChunkDef::UpperLimit - 1); + int MaxY = Clamp(FloorC(GetPosY() + m_Height), cChunkDef::LowerLimit, cChunkDef::UpperLimit - 1); for (int x = MinRelX; x <= MaxRelX; x++) { diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index aa6baae820..920fd97f13 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -51,7 +51,7 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) return; } - if (BlockY >= cChunkDef::Height) + if (BlockY >= cChunkDef::UpperLimit) { // Above the world, just wait for it to fall back down return; @@ -79,7 +79,7 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) ); */ - if (BlockY < cChunkDef::Height - 1) + if (cChunkDef::IsValidHeight(BlockY, 1)) { cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta); } diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp index 03db96d916..2b34d60d34 100644 --- a/src/Entities/FireworkEntity.cpp +++ b/src/Entities/FireworkEntity.cpp @@ -27,7 +27,7 @@ void cFireworkEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_C int RelZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width; int PosY = POSY_TOINT; - if ((PosY < 0) || (PosY >= cChunkDef::Height)) + if ((PosY < cChunkDef::LowerLimit) || (PosY >= cChunkDef::UpperLimit)) { AddSpeedY(1); AddPosition(GetSpeed() * (static_cast(a_Dt.count()) / 1000)); diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index 1fd4673bd0..93d62ba1cc 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -157,7 +157,7 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // Check water at the top of floater otherwise it floats into the air above the water if ( const auto Above = Rel.addedY(FloorC(GetPosY() + GetHeight())); - (Above.y < cChunkDef::Height) && IsBlockWater(m_World->GetBlock(Above)) + cChunkDef::IsValidHeight(Above) && IsBlockWater(m_World->GetBlock(Above)) ) { SetSpeedY(0.7); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index d8dbc10c19..2e0c33a305 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -159,7 +159,7 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) ASSERT(IsTicking()); int PosY = POSY_TOINT; - if ((PosY <= 0) || (PosY >= cChunkDef::Height)) + if ((PosY <= cChunkDef::LowerLimit) || (PosY >= cChunkDef::UpperLimit)) { // Outside the world, just process normal falling physics Super::HandlePhysics(a_Dt, a_Chunk); diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 05d1cd1851..faeb086f4e 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -143,7 +143,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) int BlockX = POSX_TOINT; int BlockZ = POSZ_TOINT; - if ((BlockY >= 0) && (BlockY < cChunkDef::Height)) // Don't do anything except for falling when outside the world + if (cChunkDef::IsValidHeight(BlockY)) // Don't do anything except for falling when outside the world { // Position might have changed due to physics. So we have to make sure we have the correct chunk. GET_AND_VERIFY_CURRENT_CHUNK(CurrentChunk, BlockX, BlockZ); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 9f4fcb971b..3c7e2c4e8f 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2378,7 +2378,7 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const std::initializer_listGetBlock({ x - 1, y, z }), m_World->GetBlock({ x + 1, y, z }), (y == 0) ? static_cast(E_BLOCK_AIR) : m_World->GetBlock({ x, y - 1, z }), - (y == cChunkDef::Height - 1) ? static_cast(E_BLOCK_AIR) : m_World->GetBlock({ x, y + 1, z }), + (y == cChunkDef::UpperLimit - 1) ? static_cast(E_BLOCK_AIR) : m_World->GetBlock({ x, y + 1, z }), m_World->GetBlock({ x, y, z - 1 }), m_World->GetBlock({ x, y, z + 1 }) ); @@ -2760,11 +2760,8 @@ void cPlayer::TickFreezeCode() if (RelSuccess) { int NewY = Rel.y; - if (NewY < 0) - { - NewY = 0; - } - while (NewY < cChunkDef::Height - 2) + NewY = std::max(0, NewY); + while (cChunkDef::IsValidHeight(NewY, 2)) { // If we find a position with enough space for the player if ( diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index fcad9032c4..c9a0e05e22 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -495,7 +495,7 @@ void cCaveTunnel::ProcessChunk( int DifY = itr->m_BlockY; int DifZ = itr->m_BlockZ - BlockStartZ; // substitution for faster calc int Bottom = std::max(itr->m_BlockY - 3 * itr->m_Radius / 7, 1); - int Top = std::min(itr->m_BlockY + 3 * itr->m_Radius / 7, static_cast(cChunkDef::Height)); + int Top = std::min(itr->m_BlockY + 3 * itr->m_Radius / 7, static_cast(cChunkDef::UpperLimit)); int SqRad = itr->m_Radius * itr->m_Radius; for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) { @@ -538,7 +538,7 @@ void cCaveTunnel::ProcessChunk( int DifZ = itr->m_BlockZ - BlockStartZ; // substitution for faster calc if ( (DifX >= 0) && (DifX < cChunkDef::Width) && - (itr->m_BlockY > 0) && (itr->m_BlockY < cChunkDef::Height) && + (itr->m_BlockY > cChunkDef::LowerLimit) && (itr->m_BlockY < cChunkDef::UpperLimit) && (DifZ >= 0) && (DifZ < cChunkDef::Width) ) { diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index b2a3324896..8b1639779d 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -20,7 +20,7 @@ cChunkDesc::cChunkDesc(cChunkCoords a_Coords) : m_bUseDefaultComposition(true), m_bUseDefaultFinish(true) { - m_BlockArea.Create(cChunkDef::Width, cChunkDef::Height, cChunkDef::Width); + m_BlockArea.Create(cChunkDef::Width, cChunkDef::UpperLimit, cChunkDef::Width); /* memset(m_BlockTypes, 0, sizeof(cChunkDef::BlockTypes)); memset(m_BlockMeta, 0, sizeof(cChunkDef::BlockNibbles)); @@ -156,7 +156,7 @@ void cChunkDesc::SetHeightFromShape(const Shape & a_Shape) { for (int x = 0; x < cChunkDef::Width; x++) { - for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--) + for (HEIGHTTYPE y = cChunkDef::UpperLimit - 1; y > cChunkDef::LowerLimit; y--) { if (a_Shape[y + x * 256 + z * 16 * 256] != 0) { @@ -179,12 +179,12 @@ void cChunkDesc::GetShapeFromHeight(Shape & a_Shape) const for (int x = 0; x < cChunkDef::Width; x++) { int height = cChunkDef::GetHeight(m_HeightMap, x, z); - for (int y = 0; y <= height; y++) + for (int y = cChunkDef::LowerLimit; y <= height; y++) { a_Shape[y + x * 256 + z * 16 * 256] = 1; } - for (int y = height + 1; y < cChunkDef::Height; y++) + for (int y = height + 1; y < cChunkDef::UpperLimit; y++) { a_Shape[y + x * 256 + z * 16 * 256] = 0; } // for y @@ -320,25 +320,25 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX a_MaxRelX = cChunkDef::Width; } - if (a_MinRelY < 0) + if (a_MinRelY < cChunkDef::LowerLimit) { - LOGWARNING("%s: MinRelY less than zero, adjusting to zero", __FUNCTION__); + LOGWARNING("%s: MinRelY less than chunk limit, adjusting to chunk limit", __FUNCTION__); a_MinRelY = 0; } - else if (a_MinRelY >= cChunkDef::Height) + else if (a_MinRelY >= cChunkDef::UpperLimit) { LOGWARNING("%s: MinRelY more than chunk height, adjusting to chunk height", __FUNCTION__); - a_MinRelY = cChunkDef::Height - 1; + a_MinRelY = cChunkDef::UpperLimit - 1; } if (a_MaxRelY < 0) { LOGWARNING("%s: MaxRelY less than zero, adjusting to zero", __FUNCTION__); a_MaxRelY = 0; } - else if (a_MaxRelY > cChunkDef::Height) + else if (a_MaxRelY > cChunkDef::UpperLimit) { LOGWARNING("%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__); - a_MaxRelY = cChunkDef::Height; + a_MaxRelY = cChunkDef::UpperLimit; } if (a_MinRelZ < 0) @@ -372,7 +372,7 @@ void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX a_Dest.m_Origin.z = m_Coords.m_ChunkZ * cChunkDef::Width + a_MinRelZ; a_Dest.SetSize(SizeX, SizeY, SizeZ, cBlockArea::baTypes | cBlockArea::baMetas); - for (int y = 0; y < SizeY; y++) + for (int y = cChunkDef::LowerLimit; y < SizeY; y++) { int CDY = a_MinRelY + y; for (int z = 0; z < SizeZ; z++) @@ -439,7 +439,7 @@ void cChunkDesc::FillRelCuboid( int MinY = std::max(a_MinY, 0); int MinZ = std::max(a_MinZ, 0); int MaxX = std::min(a_MaxX, cChunkDef::Width - 1); - int MaxY = std::min(a_MaxY, cChunkDef::Height - 1); + int MaxY = std::min(a_MaxY, cChunkDef::UpperLimit - 1); int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1); for (int y = MinY; y <= MaxY; y++) @@ -470,7 +470,7 @@ void cChunkDesc::ReplaceRelCuboid( int MinY = std::max(a_MinY, 0); int MinZ = std::max(a_MinZ, 0); int MaxX = std::min(a_MaxX, cChunkDef::Width - 1); - int MaxY = std::min(a_MaxY, cChunkDef::Height - 1); + int MaxY = std::min(a_MaxY, cChunkDef::UpperLimit - 1); int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1); for (int y = MinY; y <= MaxY; y++) @@ -506,7 +506,7 @@ void cChunkDesc::FloorRelCuboid( int MinY = std::max(a_MinY, 0); int MinZ = std::max(a_MinZ, 0); int MaxX = std::min(a_MaxX, cChunkDef::Width - 1); - int MaxY = std::min(a_MaxY, cChunkDef::Height - 1); + int MaxY = std::min(a_MaxY, cChunkDef::UpperLimit - 1); int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1); for (int y = MinY; y <= MaxY; y++) @@ -547,7 +547,7 @@ void cChunkDesc::RandomFillRelCuboid( int MinY = std::max(a_MinY, 0); int MinZ = std::max(a_MinZ, 0); int MaxX = std::min(a_MaxX, cChunkDef::Width - 1); - int MaxY = std::min(a_MaxY, cChunkDef::Height - 1); + int MaxY = std::min(a_MaxY, cChunkDef::UpperLimit - 1); int MaxZ = std::min(a_MaxZ, cChunkDef::Width - 1); for (int y = MinY; y <= MaxY; y++) @@ -616,7 +616,7 @@ void cChunkDesc::UpdateHeightmap(void) for (int z = 0; z < cChunkDef::Width; z++) { HEIGHTTYPE Height = 0; - for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--) + for (HEIGHTTYPE y = cChunkDef::UpperLimit - 1; y > cChunkDef::LowerLimit; y--) { BLOCKTYPE BlockType = GetBlockType(x, y, z); if (BlockType != E_BLOCK_AIR) @@ -655,7 +655,7 @@ void cChunkDesc::VerifyHeightmap(void) { for (int z = 0; z < cChunkDef::Width; z++) { - for (int y = cChunkDef::Height - 1; y > 0; y--) + for (int y = cChunkDef::UpperLimit - 1; y > cChunkDef::LowerLimit; y--) { BLOCKTYPE BlockType = GetBlockType(x, y, z); if (BlockType != E_BLOCK_AIR) diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index d10159dc90..a8d2954f56 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -32,8 +32,8 @@ class cChunkDesc /** The datatype used to represent the entire chunk worth of shape. 0 = air 1 = solid - Indexed as [y + 256 * x + 256 * 16 * z]. */ - typedef Byte Shape[256 * 16 * 16]; + Indexed as [y + cChunkDef::VerticalBlockCount * x + cChunkDef::VerticalBlockCount * cChunkDef::Width * z]. */ + typedef Byte Shape[cChunkDef::VerticalBlockCount * cChunkDef::Width * cChunkDef::Width]; /** Uncompressed block metas, 1 meta per byte */ typedef NIBBLETYPE BlockNibbleBytes[cChunkDef::NumBlocks]; diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 02786ede9b..d8dce3900b 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -256,17 +256,17 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); // Interpolate segments: - for (int Segment = 0; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) + for (int Segment = cChunkDef::LowerLimit; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) { // First update the high floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) + for (int z = cChunkDef::LowerLimit; z <= cChunkDef::Width / INTERPOL_Z; z++) for (int x = 0; x <= cChunkDef::Width / INTERPOL_X; x++) { // We need to store the intermediate result in a volatile variable, otherwise gcc -O2 optimizes // through the undefined behavior in cNoise and produces different data than the other platforms / build types (#4384) volatile int intermediate = m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z); - FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = intermediate / 256; + FloorHi[INTERPOL_X * x + (cChunkDef::Width + 1) * INTERPOL_Z * z] = intermediate / 256; } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); @@ -276,7 +276,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: int Threshold = static_cast(m_Noise1.CubicNoise2D(static_cast(BaseX + x) / 75, static_cast(BaseZ + z) / 75) * m_MaxThreshold); int Lo = FloorLo[x + 17 * z] / 256; int Hi = FloorHi[x + 17 * z] / 256; - for (int y = 0; y < SEGMENT_HEIGHT; y++) + for (int y = cChunkDef::LowerLimit; y < SEGMENT_HEIGHT; y++) { int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; if (Val < Threshold) diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp index 967a4a89c0..36377c955b 100644 --- a/src/Generating/CompoGenBiomal.cpp +++ b/src/Generating/CompoGenBiomal.cpp @@ -33,7 +33,7 @@ class cPattern constexpr cPattern(std::initializer_list a_TopBlocks) { - ASSERT(a_TopBlocks.size() <= cChunkDef::Height); + ASSERT(a_TopBlocks.size() <= cChunkDef::UpperLimit); // Copy the pattern into the top: size_t i = 0; for (const auto & Block : a_TopBlocks) @@ -48,7 +48,7 @@ class cPattern const BlockInfo * Get(void) const { return m_Pattern; } protected: - BlockInfo m_Pattern[cChunkDef::Height] = {}; + BlockInfo m_Pattern[cChunkDef::VerticalBlockCount] = {}; } ; @@ -174,7 +174,7 @@ class cCompoGenBiomal : HEIGHTTYPE m_SeaLevel; /** The pattern used for mesa biomes. Initialized by seed on generator creation. */ - cPattern::BlockInfo m_MesaPattern[2 * cChunkDef::Height]; + cPattern::BlockInfo m_MesaPattern[2 * cChunkDef::VerticalBlockCount]; /** Noise used for selecting between dirt and sand on the ocean floor. */ cNoise m_OceanFloorSelect; @@ -419,7 +419,7 @@ class cCompoGenBiomal : top = m_SeaLevel; a_ChunkDesc.SetHeight(a_RelX, a_RelZ, top - 1); } - for (int y = top; y > 0; y--) + for (int y = top; y > cChunkDef::LowerLimit; y--) { if (a_ShapeColumn[y] > 0) { @@ -492,7 +492,7 @@ class cCompoGenBiomal : { a_ChunkDesc.SetBlockType(a_RelX, y, a_RelZ, E_BLOCK_HARDENED_CLAY); } - for (int y = ClayFloor - 1; y > 0; y--) + for (int y = ClayFloor - 1; y > cChunkDef::LowerLimit; y--) { a_ChunkDesc.SetBlockType(a_RelX, y, a_RelZ, E_BLOCK_STONE); } @@ -501,10 +501,10 @@ class cCompoGenBiomal : } // Difficult case: use the mesa pattern and watch for overhangs: - int PatternIdx = cChunkDef::Height - (Top - ClayFloor); // We want the block at index ClayFloor to be pattern's 256th block (first stone) + int PatternIdx = cChunkDef::UpperLimit - (Top - ClayFloor); // We want the block at index ClayFloor to be pattern's 256th block (first stone) const cPattern::BlockInfo * Pattern = m_MesaPattern; bool HasHadWater = false; - for (int y = Top; y > 0; y--) + for (int y = Top; y > cChunkDef::LowerLimit; y--) { if (a_ShapeColumn[y] > 0) { diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp index a0732287b7..da5846080f 100644 --- a/src/Generating/DistortedHeightmap.cpp +++ b/src/Generating/DistortedHeightmap.cpp @@ -237,7 +237,7 @@ void cDistortedHeightmap::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape for (int x = 0; x < cChunkDef::Width; x++) { int idx = x + 17 * 257 * z; - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { a_Shape[y + x * 256 + z * 16 * 256] = (y < m_DistortedHeightmap[idx + y * 17]) ? 1 : 0; } // for y diff --git a/src/Generating/DistortedHeightmap.h b/src/Generating/DistortedHeightmap.h index f523b8109a..7370f90bdc 100644 --- a/src/Generating/DistortedHeightmap.h +++ b/src/Generating/DistortedHeightmap.h @@ -31,7 +31,7 @@ class cDistortedHeightmap : protected: typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; - // Linear upscaling step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively: + // Linear upscaling step sizes, must be divisors of cChunkDef::Width and cChunkDef::UpperLimit, respectively: static const int INTERPOL_X = 8; static const int INTERPOL_Y = 4; static const int INTERPOL_Z = 8; diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 96dd283332..1e134f226a 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -292,7 +292,7 @@ cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int m_ShapeGen(a_ShapeGen), m_MaxHalfSize((a_MaxSize + 1) / 2), m_MinHalfSize((a_MinSize + 1) / 2), - m_HeightProbability(cChunkDef::Height) + m_HeightProbability(cChunkDef::UpperLimit) { // Initialize the height probability distribution: m_HeightProbability.SetDefString(a_HeightDistrib); @@ -325,7 +325,7 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int m_ShapeGen.GenShape({ChunkX, ChunkZ}, shape); int height = 0; int idx = RelX * 256 + RelZ * 16 * 256; - for (int y = 6; y < cChunkDef::Height; y++) + for (int y = 6; y < cChunkDef::UpperLimit; y++) { if (shape[idx + y] != 0) { diff --git a/src/Generating/EndGen.cpp b/src/Generating/EndGen.cpp index 47ea052c63..c8936fd3b9 100644 --- a/src/Generating/EndGen.cpp +++ b/src/Generating/EndGen.cpp @@ -133,17 +133,17 @@ void cEndGen::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) // The distance from spawn is so big we don't need to calculate the max height anymore. // In fact, if we don't cut it off somewhere there is a chance the maxheight gets too big which // can cause corrupted looking terrain. - maxHeightLimit = static_cast(cChunkDef::Height); + maxHeightLimit = static_cast(cChunkDef::UpperLimit); } else { // Create a void between the main island and the other island using the formula 'x^3 - 3 * x' where x is distance from spawn. double pow = std::pow((distanceFromSpawn - m_MainIslandSize) / m_MainIslandSize, 3); double mult = 3 * ((distanceFromSpawn - m_MainIslandSize) / m_MainIslandSize); - maxHeightLimit = Clamp((pow - mult) * 100 + static_cast(voidOffset) * m_VoidOffsetNoiseMultiplier, 0.0, static_cast(cChunkDef::Height)); + maxHeightLimit = Clamp((pow - mult) * 100 + static_cast(voidOffset) * m_VoidOffsetNoiseMultiplier, static_cast(cChunkDef::LowerLimit), static_cast(cChunkDef::UpperLimit)); } - int maxHeight = static_cast(Clamp(m_BaseHeight + static_cast(noise) * m_TerrainTopMultiplier, 0.0, maxHeightLimit)); - int minHeight = static_cast(Clamp(m_BaseHeight - static_cast(noise) * m_TerrainBottomMultiplier, 0.0, static_cast(cChunkDef::Height))); + int maxHeight = static_cast(Clamp(m_BaseHeight + static_cast(noise) * m_TerrainTopMultiplier, static_cast(cChunkDef::LowerLimit), maxHeightLimit)); + int minHeight = static_cast(Clamp(m_BaseHeight - static_cast(noise) * m_TerrainBottomMultiplier, static_cast(cChunkDef::LowerLimit), static_cast(cChunkDef::UpperLimit))); for (int y = minHeight; y < maxHeight; y++) { @@ -164,9 +164,9 @@ void cEndGen::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & { for (int x = 0; x < cChunkDef::Width; x++) { - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { - if (a_Shape[(x + 16 * z) * 256 + y] != 0) + if (a_Shape[(x + cChunkDef::Width * z) * cChunkDef::VerticalBlockCount + y] != 0) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_END_STONE); } diff --git a/src/Generating/EnderDragonFightStructuresGen.cpp b/src/Generating/EnderDragonFightStructuresGen.cpp index 89292e0780..d23c29bbe4 100644 --- a/src/Generating/EnderDragonFightStructuresGen.cpp +++ b/src/Generating/EnderDragonFightStructuresGen.cpp @@ -90,7 +90,7 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int LOGWARNING("Got unknown parameters on generating obsidian pillars: %s, Please use \"Height|Radius|HasCage\"; ...", TowerProperty); continue; } - int Height = std::min(std::stoi(TowerPropertyVector[0]), cChunkDef::Height - 2); // The highest block placed is two blocks above the given height (the cage above some towers) + int Height = std::min(std::stoi(TowerPropertyVector[0]), cChunkDef::UpperLimit - 2); // The highest block placed is two blocks above the given height (the cage above some towers) int Radius = std::stoi(TowerPropertyVector[1]); bool HasCage; if (NoCaseCompare(TowerPropertyVector[2], "true") == 0) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 0ce48f90c2..450dbcf7b7 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -56,7 +56,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) int PosX = Val1 % 16; int PosZ = Val2 % 16; - for (int y = 1; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit + 1; y < cChunkDef::UpperLimit; y++) { if (a_ChunkDesc.GetBlockType(PosX, y, PosZ) != E_BLOCK_AIR) { @@ -118,15 +118,15 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a } int MinY = a_RelY - 2; - if (MinY < 0) // Check if the coordinate is outside the chunk. If it it then adjust it. + if (MinY < cChunkDef::LowerLimit) // Check if the coordinate is outside the chunk. If it it then adjust it. { - MinY = 0; + MinY = cChunkDef::LowerLimit; } int MaxY = a_RelY + 2; - if (MaxY > cChunkDef::Height) // Check if the coordinate is outside the chunk. If it it then adjust it. + if (MaxY > cChunkDef::UpperLimit) // Check if the coordinate is outside the chunk. If it it then adjust it. { - MaxY = cChunkDef::Height; + MaxY = cChunkDef::UpperLimit; } for (int x = MinX; x < MaxX; x++) @@ -137,11 +137,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a int zz = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z; for (int y = MinY; y < MaxY; y++) { - if ( - ((x < 0) || (x >= cChunkDef::Width)) || - ((y < 0) || (y >= cChunkDef::Height)) || - ((z < 0) || (z >= cChunkDef::Width)) - ) + if (!cChunkDef::IsValidRelPos({ x, y, z })) { continue; } @@ -253,7 +249,7 @@ void cFinishGenClumpTopBlock::TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int int Top = a_ChunkDesc.GetHeight(x, z); // Doesn't place if the blocks can't be placed. Checked value also depends on a_IsDoubleTall - if (Top + 1 + (a_IsDoubleTall ? 1 : 0) >= cChunkDef::Height) + if (Top + 1 + (a_IsDoubleTall ? 1 : 0) >= cChunkDef::UpperLimit) { continue; } @@ -537,7 +533,7 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) // Get the top block + 1. This is the place where the grass would finaly be placed: int y = a_ChunkDesc.GetHeight(x, z) + 1; - if (y >= cChunkDef::Height - 1) + if (y >= cChunkDef::UpperLimit - 1) { continue; } @@ -843,9 +839,9 @@ bool cFinishGenSprinkleFoliage::TryAddCactus(cChunkDesc & a_ChunkDesc, int a_Rel int CactusHeight = 1 + (m_Noise.IntNoise2DInt(a_RelX, a_RelZ) % m_MaxCactusHeight); // We'll be doing comparison with blocks above, so the coords should be 1 block away from chunk top - if (a_RelY + CactusHeight >= cChunkDef::Height - 1) + if (a_RelY + CactusHeight >= cChunkDef::UpperLimit - 1) { - CactusHeight = cChunkDef::Height - a_RelY - 1; + CactusHeight = cChunkDef::UpperLimit - a_RelY - 1; } // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges: @@ -903,9 +899,9 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_ } // We'll be doing comparison with blocks above, so the coords should be 1 block away from chunk top - if (a_RelY + SugarcaneHeight >= cChunkDef::Height - 1) + if (a_RelY + SugarcaneHeight >= cChunkDef::UpperLimit - 1) { - SugarcaneHeight = cChunkDef::Height - a_RelY - 1; + SugarcaneHeight = cChunkDef::UpperLimit - a_RelY - 1; } // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges: @@ -1098,7 +1094,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - if (!cBlockInfo::IsSnowable(a_ChunkDesc.GetBlockType(x, Height, z)) || (Height >= cChunkDef::Height - 1)) + if (!cBlockInfo::IsSnowable(a_ChunkDesc.GetBlockType(x, Height, z)) || (Height >= cChunkDef::UpperLimit - 1)) { // The top block can't be snown over. continue; @@ -1191,7 +1187,7 @@ void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) } HEIGHTTYPE Height = a_ChunkDesc.GetHeight(x, z); - if (Height >= cChunkDef::Height - 1) + if (Height >= cChunkDef::UpperLimit - 1) { // Too high up continue; @@ -1223,7 +1219,7 @@ void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) void cFinishGenBottomLava::GenFinish(cChunkDesc & a_ChunkDesc) { cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes(); - for (int y = m_Level; y > 0; y--) + for (int y = m_Level; y > cChunkDef::LowerLimit; y--) { for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) { @@ -1286,7 +1282,7 @@ void cFinishGenPreSimulator::CollapseSandGravel(cChunkDesc & a_ChunkDesc) { int LastY = -1; int HeightY = 0; - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { BLOCKTYPE Block = a_ChunkDesc.GetBlockType(x, y, z); switch (Block) @@ -1391,7 +1387,7 @@ void cFinishGenPreSimulator::StationarizeFluid( } // for z // Turn fluid at the chunk edges into non-stationary fluid: - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { for (int i = 0; i < cChunkDef::Width; i++) // i stands for both x and z here { @@ -1424,7 +1420,7 @@ void cFinishGenPreSimulator::StationarizeFluid( cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension) : m_Noise(a_Seed + a_Fluid * 100), // Need to take fluid into account, otherwise water and lava springs generate next to each other - m_HeightDistribution(cChunkDef::Height - 1), + m_HeightDistribution(cChunkDef::UpperLimit - 1), m_Fluid(a_Fluid) { bool IsWater = (a_Fluid == E_BLOCK_WATER); @@ -1647,7 +1643,7 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn) { - if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0)) + if ((a_RelY >= cChunkDef::UpperLimit - 1) || (a_RelY <= 0)) { return false; } @@ -2174,7 +2170,7 @@ void cFinishGenOrePockets::imprintSphere( int minY = std::max(FloorC(a_SphereY - a_Radius), 0); int minZ = std::max(FloorC(a_SphereZ - a_Radius), baseZ); int maxX = std::min(CeilC(a_SphereX + a_Radius), baseX + cChunkDef::Width - 1); - int maxY = std::min(CeilC(a_SphereY + a_Radius), cChunkDef::Height - 1); + int maxY = std::min(CeilC(a_SphereY + a_Radius), cChunkDef::UpperLimit - 1); int maxZ = std::min(CeilC(a_SphereZ + a_Radius), baseZ + cChunkDef::Width - 1); /* @@ -2184,7 +2180,7 @@ void cFinishGenOrePockets::imprintSphere( int blockZ = FloorC(a_SphereZ); if ( (blockX >= baseX) && (blockX < baseX + cChunkDef::Width) && - (blockY >= 0) && (blockY < cChunkDef::Height) && + cChunkDef::IsValidHeight(blockY) && (blockZ >= baseZ) && (blockZ < baseZ + cChunkDef::Width) ) { @@ -2255,7 +2251,7 @@ void cFinishGenForestRocks::GenFinish(cChunkDesc & a_ChunkDesc) 0, m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % cChunkDef::Width ); - Pos.y = a_ChunkDesc.GetHeight(Pos.x, Pos.z) % cChunkDef::Height; + Pos.y = a_ChunkDesc.GetHeight(Pos.x, Pos.z) % cChunkDef::UpperLimit; auto Biome = a_ChunkDesc.GetBiome(Pos.x, Pos.z); if ((Biome != biMegaTaiga) && (Biome != biMegaTaigaHills)) @@ -2294,7 +2290,7 @@ void cFinishGenForestRocks::GenFinish(cChunkDesc & a_ChunkDesc) Pos.y -= Radius - 1; - // Pos.y = Clamp(Pos.y - m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % Radius + 1, 0, cChunkDef::Height); + // Pos.y = Clamp(Pos.y - m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % Radius + 1, 0, cChunkDef::UpperLimit); for (int x = -Radius; x <= Radius; x++) { diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 2e4b4fb3ca..c2cbe549d8 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -64,7 +64,7 @@ class cHeiGenSteppy: ); for (size_t i = 0; i < ARRAYCOUNT(heights); i++) { - a_HeightMap[i] = static_cast(std::max(std::min(60 + heights[i], cChunkDef::Height - 60), 40)); + a_HeightMap[i] = static_cast(std::max(std::min(60 + heights[i], cChunkDef::UpperLimit - 60), 40)); } } diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index ecf135a268..8d4ebca140 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -210,15 +210,15 @@ void cNoise3DGenerator::GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::Bi void cNoise3DGenerator::Generate(cChunkDesc & a_ChunkDesc) { - NOISE_DATATYPE Noise[17 * 257 * 17]; + NOISE_DATATYPE Noise[(cChunkDef::Width + 1) * (cChunkDef::UpperLimit + 1) * (cChunkDef::Width + 1)]; GenerateNoiseArray(a_ChunkDesc.GetChunkCoords(), Noise); // Output noise into chunk: for (int z = 0; z < cChunkDef::Width; z++) { - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { - int idx = z * 17 * 257 + y * 17; + int idx = z * (cChunkDef::Width + 1) * (cChunkDef::UpperLimit + 1) + y * (cChunkDef::Width + 1); for (int x = 0; x < cChunkDef::Width; x++) { NOISE_DATATYPE n = Noise[idx++]; @@ -302,7 +302,7 @@ void cNoise3DGenerator::ComposeTerrain(cChunkDesc & a_ChunkDesc) { int LastAir = a_ChunkDesc.GetHeight(x, z) + 1; bool HasHadWater = false; - for (int y = LastAir - 1; y > 0; y--) + for (int y = LastAir - 1; y > cChunkDef::LowerLimit; y--) { switch (a_ChunkDesc.GetBlockType(x, y, z)) { @@ -491,9 +491,9 @@ void cNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape { for (int x = 0; x < cChunkDef::Width; x++) { - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { - a_Shape[y + x * 256 + z * 256 * 16] = (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; + a_Shape[y + x * cChunkDef::VerticalBlockCount + z * cChunkDef::VerticalBlockCount * cChunkDef::Width] = (m_NoiseArray[y + (cChunkDef::VerticalBlockCount + 1) * x + (cChunkDef::VerticalBlockCount + 1) * (cChunkDef::Width + 1) * z] > m_AirThreshold) ? 0 : 1; } } // for x } // for z @@ -784,9 +784,9 @@ void cBiomalNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc:: { for (int x = 0; x < cChunkDef::Width; x++) { - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { - a_Shape[y + x * 256 + z * 256 * 16] = (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; + a_Shape[y + x * cChunkDef::VerticalBlockCount + z * cChunkDef::VerticalBlockCount * cChunkDef::Width] = (m_NoiseArray[y + (cChunkDef::VerticalBlockCount + 1) * x + (cChunkDef::VerticalBlockCount + 1) * (cChunkDef::Width + 1) * z] > m_AirThreshold) ? 0 : 1; } } // for x } // for z diff --git a/src/Generating/Noise3DGenerator.h b/src/Generating/Noise3DGenerator.h index 9aceffc1d3..edbc1f4caf 100644 --- a/src/Generating/Noise3DGenerator.h +++ b/src/Generating/Noise3DGenerator.h @@ -35,14 +35,14 @@ class cNoise3DGenerator: virtual void Generate(cChunkDesc & a_ChunkDesc) override; protected: - // Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively: + // Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::UpperLimit, respectively: static const int UPSCALE_X = 4; static const int UPSCALE_Y = 8; static const int UPSCALE_Z = 4; // Linear interpolation buffer dimensions, calculated from the step sizes: static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X; - static const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y; + static const int DIM_Y = 1 + cChunkDef::VerticalBlockCount / UPSCALE_Y; static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z; /** The base 3D noise source for the actual composition */ diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 4e5d90770f..773f9debf4 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -360,7 +360,7 @@ void cStructGenRavines::cRavine::DrawIntoChunk(cChunkDesc & a_ChunkDesc) int DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); if (DistSq <= RadiusSq) { - int Top = std::min(itr->m_Top, static_cast(cChunkDef::Height)); // Stupid gcc needs int cast + int Top = std::min(itr->m_Top, static_cast(cChunkDef::UpperLimit)); // Stupid gcc needs int cast for (int y = std::max(itr->m_Bottom, 1); y <= Top; y++) { switch (a_ChunkDesc.GetBlockType(x, y, z)) diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index a39f7922db..2d8def46cf 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -86,7 +86,7 @@ class cRoughRavine: float m_Roughness; /** Number to add to the radius based on the height. This creates the "ledges" in the ravine walls. */ - float m_PerHeightRadius[cChunkDef::Height]; + float m_PerHeightRadius[cChunkDef::VerticalBlockCount]; /** Recursively subdivides the line between the points of the specified index. @@ -133,17 +133,17 @@ class cRoughRavine: void InitPerHeightRadius(int a_GridX, int a_GridZ) { - int h = 0; - while (h < cChunkDef::Height) + int h = cChunkDef::LowerLimit; + while (h < cChunkDef::UpperLimit) { m_Noise.SetSeed(m_Seed + h); int rnd = m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 13; int NumBlocks = (rnd % 3) + 2; rnd = rnd / 4; float Val = static_cast(rnd % 256) / 128.0f - 1.0f; // Random float in range [-1, +1] - if (h + NumBlocks > cChunkDef::Height) + if (!cChunkDef::IsValidHeight(h + NumBlocks)) { - NumBlocks = cChunkDef::Height - h; + NumBlocks = cChunkDef::UpperLimit - h; } for (int i = 0; i < NumBlocks; i++) { @@ -196,7 +196,7 @@ class cRoughRavine: continue; } - int Top = std::min(CeilC(itr->m_Top), +cChunkDef::Height); + int Top = std::min(CeilC(itr->m_Top), +cChunkDef::UpperLimit); for (int y = std::max(FloorC(itr->m_Bottom), 1); y <= Top; y++) { if ((itr->m_Radius + m_PerHeightRadius[y]) * (itr->m_Radius + m_PerHeightRadius[y]) < DistSq) diff --git a/src/Generating/ShapeGen.cpp b/src/Generating/ShapeGen.cpp index f46c0c8e9b..17846f1d92 100644 --- a/src/Generating/ShapeGen.cpp +++ b/src/Generating/ShapeGen.cpp @@ -47,7 +47,7 @@ class cTerrainHeightToShapeGen: { shapeColumn[y] = 1; } - for (int y = height; y < cChunkDef::Height; y++) + for (int y = height; y < cChunkDef::UpperLimit; y++) { shapeColumn[y] = 0; } diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 3bdf94d1cf..a59b6606f7 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -129,7 +129,7 @@ void cStructGenTrees::GenerateSingleTree( // Outside the chunk continue; } - if (itr->m_RelY >= cChunkDef::Height) + if (itr->m_RelY >= cChunkDef::UpperLimit) { // Above the chunk, cut off (this shouldn't happen too often, we're limiting trees to y < 230) continue; @@ -168,7 +168,7 @@ void cStructGenTrees::ApplyTreeImage( // Put the generated image into a_BlockTypes, push things outside this chunk into a_Blocks for (sSetBlockVector::const_iterator itr = a_Image.begin(), end = a_Image.end(); itr != end; ++itr) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ) && (itr->m_RelY < cChunkDef::Height)) + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ) && cChunkDef::IsValidHeight(itr->m_RelY)) { // Inside this chunk, integrate into a_ChunkDesc: switch (a_ChunkDesc.GetBlockType(itr->m_RelX, itr->m_RelY, itr->m_RelZ)) @@ -399,11 +399,11 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH // Turn air in the bottom half into liquid: for (int y = 0; y < 4; y++) { - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) + for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) { - if (BlockTypes[x + z * 16 + y * 16 * 16] == E_BLOCK_AIR) + if (BlockTypes[x + z * cChunkDef::Width + y * cChunkDef::Width * cChunkDef::Width] == E_BLOCK_AIR) { - BlockTypes[x + z * 16 + y * 16 * 16] = m_Fluid; + BlockTypes[x + z * cChunkDef::Width + y * cChunkDef::Width * cChunkDef::Width] = m_Fluid; } } // for z, x } // for y @@ -456,12 +456,12 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) int BaseY = 63; // Interpolate the lowest floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) + for (int z = 0; z <= cChunkDef::Width / INTERPOL_Z; z++) for (int x = 0; x <= cChunkDef::Width / INTERPOL_X; x++) { FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] = m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) * m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) / - 256; + cChunkDef::VerticalBlockCount; } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); @@ -469,25 +469,25 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) for (int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) { // First update the high floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) + for (int z = 0; z <= cChunkDef::Width / INTERPOL_Z; z++) for (int x = 0; x <= cChunkDef::Width / INTERPOL_X; x++) { FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = ( m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * - m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256 + m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / cChunkDef::VerticalBlockCount ); } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); // Interpolate between FloorLo and FloorHi: - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) + for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) { EMCSBiome biome = a_ChunkDesc.GetBiome(x, z); if ((biome == biExtremeHills) || (biome == biExtremeHillsEdge)) { - int Lo = FloorLo[x + 17 * z] / 256; - int Hi = FloorHi[x + 17 * z] / 256; - for (int y = 0; y < SEGMENT_HEIGHT; y++) + int Lo = FloorLo[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; + int Hi = FloorHi[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; + for (int y = cChunkDef::LowerLimit; y < SEGMENT_HEIGHT; y++) { int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; if (Val < 0) diff --git a/src/Generating/TwoHeights.cpp b/src/Generating/TwoHeights.cpp index 91c67608c5..6dee1275e1 100644 --- a/src/Generating/TwoHeights.cpp +++ b/src/Generating/TwoHeights.cpp @@ -58,10 +58,10 @@ class cTwoHeights: { for (int x = 0; x < cChunkDef::Width; x++) { - int idxChoice = 257 * 17 * z + 257 * x; + int idxChoice = (cChunkDef::VerticalBlockCount + 1) * (cChunkDef::Width + 1) * z + (cChunkDef::VerticalBlockCount + 1) * x; NOISE_DATATYPE heightA = static_cast(cChunkDef::GetHeight(heightsA, x, z)); NOISE_DATATYPE heightB = static_cast(cChunkDef::GetHeight(heightsB, x, z)); - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { int height = static_cast(ClampedLerp(heightA, heightB, choice[idxChoice++])); a_Shape[idxShape++] = (y < height) ? 1 : 0; diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index 6575b2f3ab..c9f0b989f3 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -134,7 +134,7 @@ class cVillageGen::cVillage: m_Density(a_Density), m_Borders( {a_OriginX - a_MaxSize, 0, a_OriginZ - a_MaxSize}, - {a_OriginX + a_MaxSize, cChunkDef::Height - 1, a_OriginZ + a_MaxSize} + {a_OriginX + a_MaxSize, cChunkDef::UpperLimit - 1, a_OriginZ + a_MaxSize} ), m_Prefabs(a_Prefabs), m_HeightGen(a_HeightGen) diff --git a/src/Items/ItemBigFlower.h b/src/Items/ItemBigFlower.h index cbdecbed7f..72cee920d1 100644 --- a/src/Items/ItemBigFlower.h +++ b/src/Items/ItemBigFlower.h @@ -20,7 +20,7 @@ class cItemBigFlowerHandler final: virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override { // Needs at least two free blocks to build in: - if (a_PlacePosition.y >= (cChunkDef::Height - 1)) + if (a_PlacePosition.y >= (cChunkDef::UpperLimit - 1)) { return false; } diff --git a/src/Items/ItemDye.h b/src/Items/ItemDye.h index e6beca0841..aeb4a5e457 100644 --- a/src/Items/ItemDye.h +++ b/src/Items/ItemDye.h @@ -377,7 +377,7 @@ class cItemDyeHandler final : if (Planter == GrowDoubleTallGrass) { const auto TwoAbove = Position.addedY(2); - if ((TwoAbove.y >= cChunkDef::Height) || (a_World.GetBlock(TwoAbove) != E_BLOCK_AIR)) + if ((TwoAbove.y >= cChunkDef::UpperLimit) || (a_World.GetBlock(TwoAbove) != E_BLOCK_AIR)) { // Insufficient space for tall grass: continue; @@ -385,7 +385,7 @@ class cItemDyeHandler final : } const auto PlantBase = Position.addedY(1); - if ((PlantBase.y >= cChunkDef::Height) || (a_World.GetBlock(PlantBase) != E_BLOCK_AIR)) + if ((PlantBase.y >= cChunkDef::UpperLimit) || (a_World.GetBlock(PlantBase) != E_BLOCK_AIR)) { // Insufficient space: continue; diff --git a/src/Items/ItemEndCrystal.h b/src/Items/ItemEndCrystal.h index 976bc83ec0..3d06b3d1c1 100644 --- a/src/Items/ItemEndCrystal.h +++ b/src/Items/ItemEndCrystal.h @@ -49,8 +49,8 @@ class cItemEndCrystalHandler final : if ( // Don't place if two blocks above placement block aren't air: - ((Above.y != cChunkDef::Height) && (a_World->GetBlock(Above) != E_BLOCK_AIR)) || - ((Above.y < (cChunkDef::Height - 1)) && (a_World->GetBlock(Above.addedY(1)) != E_BLOCK_AIR)) || + ((Above.y != cChunkDef::UpperLimit) && (a_World->GetBlock(Above) != E_BLOCK_AIR)) || + ((Above.y < (cChunkDef::UpperLimit - 1)) && (a_World->GetBlock(Above.addedY(1)) != E_BLOCK_AIR)) || // Refuse placement if there are any entities in a (1 by 2 by 1) bounding box with base at the block above: !a_World->ForEachEntityInBox( diff --git a/src/Items/ItemHoe.h b/src/Items/ItemHoe.h index 2bca5f5ca6..e53fc5b3e0 100644 --- a/src/Items/ItemHoe.h +++ b/src/Items/ItemHoe.h @@ -31,7 +31,7 @@ class cItemHoeHandler final: eBlockFace a_ClickedBlockFace ) const override { - if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockPos.y >= cChunkDef::Height)) + if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockPos.y >= cChunkDef::UpperLimit)) { return false; } diff --git a/src/Items/ItemPumpkin.h b/src/Items/ItemPumpkin.h index 2effb49897..65ed1e1122 100644 --- a/src/Items/ItemPumpkin.h +++ b/src/Items/ItemPumpkin.h @@ -42,7 +42,7 @@ class cItemPumpkinHandler final: bool TrySpawnGolem(cPlayer & a_Player, const Vector3i a_PumpkinPos) const { // A golem can't form with a pumpkin below level 2 or above level 255: - if ((a_PumpkinPos.y < 2) || (a_PumpkinPos.y >= cChunkDef::Height)) + if (cChunkDef::IsValidHeight(a_PumpkinPos, 2, 1)) { return false; } diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index f4aa1d69e1..dcbca94fa5 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -261,7 +261,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item) { for (int z = 0; z < cChunkDef::Width * 3; z++) { - for (int y = cChunkDef::Height / 2; y >= 0; y--) + for (int y = cChunkDef::UpperLimit / 2; y >= cChunkDef::LowerLimit; y--) { unsigned char Seeds [cChunkDef::Width * 3]; memcpy(Seeds, m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); @@ -292,7 +292,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item) { for (int z = 0; z < cChunkDef::Width * 3; z++) { - for (int y = cChunkDef::Height / 2; y >= 0; y--) + for (int y = cChunkDef::UpperLimit / 2; y >= 0; y--) { f1.Write(m_BlockTypes + y * BlocksPerYLayer + z * cChunkDef::Width * 3, cChunkDef::Width * 3); unsigned char SkyLight [cChunkDef::Width * 3]; @@ -357,7 +357,7 @@ void cLightingThread::PrepareSkyLight(void) m_NumSeeds = 0; // Fill the top of the chunk with all-light: - if (m_MaxHeight < cChunkDef::Height - 1) + if (cChunkDef::IsValidHeight(m_MaxHeight, 1)) { std::fill(m_SkyLight + (m_MaxHeight + 1) * BlocksPerYLayer, m_SkyLight + ARRAYCOUNT(m_SkyLight), static_cast(15)); } @@ -371,7 +371,7 @@ void cLightingThread::PrepareSkyLight(void) int idx = BaseZ + x; // Find the lowest block in this column that receives full sunlight (go through transparent blocks): int Current = m_HeightMap[idx]; - ASSERT(Current < cChunkDef::Height); + ASSERT(cChunkDef::IsValidHeight(Current)); while ( (Current >= 0) && cBlockInfo::IsTransparent(m_BlockTypes[idx + Current * BlocksPerYLayer]) && @@ -395,7 +395,7 @@ void cLightingThread::PrepareSkyLight(void) } // Add Current as a seed: - if (Current < cChunkDef::Height) + if (cChunkDef::IsValidHeight(Current)) { int CurrentIdx = idx + Current * BlocksPerYLayer; m_IsSeed1[CurrentIdx] = true; @@ -501,7 +501,7 @@ void cLightingThread::CalcLightStep( { PropagateLight(a_Light, SeedIdx, SeedIdx - cChunkDef::Width * 3, NumSeedsOut, a_IsSeedOut, a_SeedIdxOut); } - if (SeedIdx < (cChunkDef::Height - 1) * BlocksPerYLayer) + if (SeedIdx < (cChunkDef::UpperLimit - 1) * BlocksPerYLayer) { PropagateLight(a_Light, SeedIdx, SeedIdx + BlocksPerYLayer, NumSeedsOut, a_IsSeedOut, a_SeedIdxOut); } @@ -521,7 +521,7 @@ void cLightingThread::CompressLight(NIBBLETYPE * a_LightArray, NIBBLETYPE * a_Ch { int InIdx = cChunkDef::Width * 49; // Index to the first nibble of the middle chunk in the a_LightArray int OutIdx = 0; - for (int y = 0; y < cChunkDef::Height; y++) + for (int y = cChunkDef::LowerLimit; y < cChunkDef::UpperLimit; y++) { for (int z = 0; z < cChunkDef::Width; z++) { diff --git a/src/LightingThread.h b/src/LightingThread.h index 1097558a40..312a52e6be 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -116,9 +116,9 @@ class cLightingThread: // The blobs are XZY organized as a whole, instead of 3x3 XZY-organized subarrays -> // -> This means data has to be scatterred when reading and gathered when writing! static const int BlocksPerYLayer = cChunkDef::Width * cChunkDef::Width * 3 * 3; - BLOCKTYPE m_BlockTypes[BlocksPerYLayer * cChunkDef::Height]; - NIBBLETYPE m_BlockLight[BlocksPerYLayer * cChunkDef::Height]; - NIBBLETYPE m_SkyLight [BlocksPerYLayer * cChunkDef::Height]; + BLOCKTYPE m_BlockTypes[BlocksPerYLayer * cChunkDef::VerticalBlockCount]; + NIBBLETYPE m_BlockLight[BlocksPerYLayer * cChunkDef::VerticalBlockCount]; + NIBBLETYPE m_SkyLight [BlocksPerYLayer * cChunkDef::VerticalBlockCount]; HEIGHTTYPE m_HeightMap [BlocksPerYLayer]; // Seed management (5.7 MiB) @@ -126,10 +126,10 @@ class cLightingThread: // Each seed is represented twice in this structure - both as a "list" and as a "position". // "list" allows fast traversal from seed to seed // "position" allows fast checking if a coord is already a seed - unsigned char m_IsSeed1 [BlocksPerYLayer * cChunkDef::Height]; - unsigned int m_SeedIdx1[BlocksPerYLayer * cChunkDef::Height]; - unsigned char m_IsSeed2 [BlocksPerYLayer * cChunkDef::Height]; - unsigned int m_SeedIdx2[BlocksPerYLayer * cChunkDef::Height]; + unsigned char m_IsSeed1 [BlocksPerYLayer * cChunkDef::VerticalBlockCount]; + unsigned int m_SeedIdx1[BlocksPerYLayer * cChunkDef::VerticalBlockCount]; + unsigned char m_IsSeed2 [BlocksPerYLayer * cChunkDef::VerticalBlockCount]; + unsigned int m_SeedIdx2[BlocksPerYLayer * cChunkDef::VerticalBlockCount]; size_t m_NumSeeds; virtual void Execute(void) override; diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index 49eba9ac81..4857271f52 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -156,9 +156,9 @@ bool cLineBlockTracer::Trace(const Vector3d a_Start, const Vector3d a_End) FixStartBelowWorld(); m_Callbacks->OnIntoWorld(m_Start); } - else if (m_Start.y >= cChunkDef::Height) + else if (m_Start.y >= cChunkDef::UpperLimit) { - if (m_End.y >= cChunkDef::Height) + if (m_End.y >= cChunkDef::UpperLimit) { m_Callbacks->OnNoMoreHits(); return true; @@ -185,9 +185,9 @@ bool cLineBlockTracer::Trace(const Vector3d a_Start, const Vector3d a_End) void cLineBlockTracer::FixStartAboveWorld(void) { - // We must set the start Y to less than cChunkDef::Height so that it is considered inside the world later on + // We must set the start Y to less than cChunkDef::UpperLimit so that it is considered inside the world later on // Therefore we use an EPS-offset from the height, as small as reasonably possible. - const double Height = static_cast(cChunkDef::Height) - 0.00001; + const double Height = static_cast(cChunkDef::UpperLimit) - 0.00001; CalcXZIntersection(Height, m_Start.x, m_Start.z); m_Start.y = Height; } @@ -199,7 +199,7 @@ void cLineBlockTracer::FixStartAboveWorld(void) void cLineBlockTracer::FixStartBelowWorld(void) { CalcXZIntersection(0, m_Start.x, m_Start.z); - m_Start.y = 0; + m_Start.y = cChunkDef::LowerLimit; } @@ -245,7 +245,7 @@ bool cLineBlockTracer::MoveToNextBlock(void) // If the next XZ wall hit is closer, use it instead: if (std::abs(m_Diff.y) > EPS) { - double DestY = (m_Dir.y > 0) ? (m_Current.y + 1) : m_Current.y; + double DestY = (m_Dir.y > cChunkDef::LowerLimit) ? (m_Current.y + 1) : m_Current.y; double CoeffY = (DestY - m_Start.y) / m_Diff.y; if (CoeffY <= Coeff) // We need to include equality for the last block in the trace { @@ -269,7 +269,7 @@ bool cLineBlockTracer::MoveToNextBlock(void) switch (Direction) { case dirX: m_Current.x += m_Dir.x; m_CurrentFace = (m_Dir.x > 0) ? BLOCK_FACE_XM : BLOCK_FACE_XP; break; - case dirY: m_Current.y += m_Dir.y; m_CurrentFace = (m_Dir.y > 0) ? BLOCK_FACE_YM : BLOCK_FACE_YP; break; + case dirY: m_Current.y += m_Dir.y; m_CurrentFace = (m_Dir.y > cChunkDef::LowerLimit) ? BLOCK_FACE_YM : BLOCK_FACE_YP; break; case dirZ: m_Current.z += m_Dir.z; m_CurrentFace = (m_Dir.z > 0) ? BLOCK_FACE_ZM : BLOCK_FACE_ZP; break; case dirNONE: return false; } @@ -282,7 +282,7 @@ bool cLineBlockTracer::MoveToNextBlock(void) bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk) { - ASSERT((m_Current.y >= 0) && (m_Current.y < cChunkDef::Height)); // This should be provided by FixStartAboveWorld() / FixStartBelowWorld() + ASSERT(cChunkDef::IsValidHeight(m_Current)); // This should be provided by FixStartAboveWorld() / FixStartBelowWorld() // This is the actual line tracing loop. for (;;) @@ -298,7 +298,7 @@ bool cLineBlockTracer::ChunkCallback(cChunk * a_Chunk) return true; } - if ((m_Current.y < 0) || (m_Current.y >= cChunkDef::Height)) + if (cChunkDef::IsValidHeight(m_Current)) { // We've gone out of the world, that's the end of this trace double IntersectX, IntersectZ; diff --git a/src/Map.cpp b/src/Map.cpp index c02cd80f85..c6439cea38 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -137,7 +137,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) NIBBLETYPE TargetMeta; auto Height = a_Chunk.GetHeight(RelX, RelZ); - auto ChunkHeight = cChunkDef::Height; + auto ChunkHeight = cChunkDef::VerticalBlockCount; a_Chunk.GetBlockTypeMeta(RelX, Height, RelZ, TargetBlock, TargetMeta); auto ColourID = cBlockHandler::For(TargetBlock).GetMapBaseColourID(TargetMeta); diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index d5ed79fc40..cfe4ee6a19 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -74,7 +74,7 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, Vector3i a_RelPos, eMonsterType a_MobType, EMCSBiome a_Biome, bool a_DisableSolidBelowCheck) { - if ((a_RelPos.y >= cChunkDef::Height - 1) || (a_RelPos.y <= 0)) + if ((a_RelPos.y >= cChunkDef::UpperLimit - 1) || (a_RelPos.y <= cChunkDef::LowerLimit)) { return false; } diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp index f9c80d1e54..0ba50ec7a5 100644 --- a/src/Mobs/Guardian.cpp +++ b/src/Mobs/Guardian.cpp @@ -43,7 +43,7 @@ void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d Pos = GetPosition(); int RelY = FloorC(Pos.y); - if ((RelY < 0) || (RelY >= cChunkDef::Height)) + if ((RelY < cChunkDef::LowerLimit) || (RelY >= cChunkDef::UpperLimit)) { return; } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index e05264f9fe..0c7183e65f 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -542,11 +542,11 @@ void cMonster::HandleFalling() int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) { auto Position = GetPosition().Floor(); - Position.y = Clamp(Position.y, 0, cChunkDef::Height); + Position.y = Clamp(Position.y, cChunkDef::LowerLimit, cChunkDef::UpperLimit); if (!cBlockInfo::IsSolid(m_World->GetBlock(Position))) { - while (!cBlockInfo::IsSolid(m_World->GetBlock(Position)) && (Position.y > 0)) + while (!cBlockInfo::IsSolid(m_World->GetBlock(Position)) && (Position.y > cChunkDef::LowerLimit)) { Position.y--; } @@ -555,7 +555,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) } else { - while ((Position.y < cChunkDef::Height) && cBlockInfo::IsSolid(m_World->GetBlock(Position))) + while (cChunkDef::IsValidHeight(Position, 1) && cBlockInfo::IsSolid(m_World->GetBlock(Position))) { Position.y++; } @@ -1619,7 +1619,7 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn) } int RelY = POSY_TOINT; - if ((RelY < 0) || (RelY >= cChunkDef::Height)) + if ((RelY < cChunkDef::LowerLimit) || (RelY >= cChunkDef::UpperLimit)) { // Outside the world return; @@ -1645,7 +1645,7 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) { // If the Y coord is out of range, return the most logical result without considering anything else: int RelY = FloorC(a_Location.y); - if (RelY >= cChunkDef::Height) + if (RelY >= cChunkDef::UpperLimit) { // Always burn above the world return true; @@ -1670,7 +1670,7 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk) ) { int MobHeight = CeilC(a_Location.y + GetHeight()) - 1; // The block Y coord of the mob's head - if (MobHeight >= cChunkDef::Height) + if (MobHeight >= cChunkDef::UpperLimit) { return true; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 0127ec4ce7..42733ddee2 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -266,7 +266,7 @@ class cMonster: /** Finds the lowest non-air block position (not the highest, as cWorld::GetHeight does) If current Y is nonsolid, goes down to try to find a solid block, then returns that + 1 If current Y is solid, goes up to find first nonsolid block, and returns that. - If no suitable position is found, returns cChunkDef::Height. */ + If no suitable position is found, returns cChunkDef::UpperLimit. */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); /** Returns if the ultimate, final destination has been reached. */ diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index 05ccd6c397..aa06f36ea7 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -641,7 +641,7 @@ bool cPath::SpecialIsSolidFromThisDirection(BLOCKTYPE a_Type, NIBBLETYPE a_Meta, if (!cBlockInfo::IsSolid(a_Type)) { // Only treat as solid when we're coming from below - return (a_Direction.y > 0); + return (a_Direction.y > cChunkDef::LowerLimit); } /* switch (a_Type) diff --git a/src/Mobs/PathFinder.cpp b/src/Mobs/PathFinder.cpp index 2e832918a7..161d16c253 100644 --- a/src/Mobs/PathFinder.cpp +++ b/src/Mobs/PathFinder.cpp @@ -249,7 +249,7 @@ bool cPathFinder::EnsureProperPoint(Vector3d & a_Vector, cChunk & a_Chunk) } // If destination in water or solid, go up to the first air block. - while (BelowRel.y < cChunkDef::Height) + while (cChunkDef::IsValidHeight(BelowRel)) { Chunk->GetBlockTypeMeta(BelowRel, BlockType, BlockMeta); if (!IsWaterOrSolid(BlockType)) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index be4def2b7f..5889fc77c7 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -101,7 +101,7 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) int PosY = POSY_TOINT - 1; int PosZ = POSZ_TOINT; - if ((PosY <= 0) || (PosY >= cChunkDef::Height)) + if ((PosY <= cChunkDef::LowerLimit) || (PosY >= cChunkDef::UpperLimit)) { return; } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index fabcfb0701..728216dd12 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -49,7 +49,7 @@ void cSnowGolem::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { TakeDamage(dtEnvironment, nullptr, GetRawDamageAgainst(*this), GetKnockbackAmountAgainst(*this)); } - else if (const auto Below = Rel.addedY(-1); Below.y >= 0) + else if (const auto Below = Rel.addedY(-1); Below.y >= cChunkDef::LowerLimit) { if ((Chunk->GetBlock(Rel) == E_BLOCK_AIR) && cBlockInfo::IsSolid(Chunk->GetBlock(Below))) { diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 66320926dd..44ce9b3315 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -42,7 +42,7 @@ void cSquid::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // TODO: Not a real behavior, but cool :D int RelY = FloorC(Pos.y); - if ((RelY < 0) || (RelY >= cChunkDef::Height)) + if ((RelY < cChunkDef::LowerLimit) || (RelY >= cChunkDef::UpperLimit)) { return; } diff --git a/src/NetherPortalScanner.cpp b/src/NetherPortalScanner.cpp index b5f49eb2c4..cee3a13c3f 100644 --- a/src/NetherPortalScanner.cpp +++ b/src/NetherPortalScanner.cpp @@ -187,7 +187,7 @@ bool cNetherPortalScanner::OnAllChunksAvailable(void) int maxy = m_MaxY; std::vector Possibilities; int x, y, z; - for (y = 0; y < maxy - PortalHeight; y++) + for (y = cChunkDef::LowerLimit; y < maxy - PortalHeight; y++) { for (x = minx; x < maxx - PortalLength; x++) { diff --git a/src/Physics/Explodinator.cpp b/src/Physics/Explodinator.cpp index ba1a8cbcf1..8b3254be74 100644 --- a/src/Physics/Explodinator.cpp +++ b/src/Physics/Explodinator.cpp @@ -304,7 +304,7 @@ namespace Explodinator else if (a_Fiery && Random.RandBool(1 / 3.0)) // 33% chance of starting fires if it can start fires { const auto Below = a_Position.addedY(-1); - if ((Below.y >= 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(Below))) + if ((Below.y >= cChunkDef::LowerLimit) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(Below))) { // Start a fire: SetBlock(World, a_Chunk, Absolute, a_Position, DestroyedBlock, E_BLOCK_FIRE, a_ExplodingEntity); diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index a025f6afd7..e46f4076cf 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -97,7 +97,7 @@ void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, continue; } - auto BurnsForever = ((relPos.y > 0) && DoesBurnForever(a_Chunk->GetBlock(relPos.addedY(-1)))); + auto BurnsForever = ((relPos.y > cChunkDef::LowerLimit) && DoesBurnForever(a_Chunk->GetBlock(relPos.addedY(-1)))); auto BlockMeta = a_Chunk->GetMeta(relPos); auto Raining = std::any_of(std::begin(gCrossCoords), std::end(gCrossCoords), [a_Chunk, relPos](Vector3i cc) @@ -272,7 +272,7 @@ void cFireSimulator::AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, Vector3i a_RelPos) { bool IsBlockBelowSolid = false; - if (a_RelPos.y > 0) + if (a_RelPos.y > cChunkDef::LowerLimit) { BLOCKTYPE BlockBelow = a_Chunk->GetBlock(a_RelPos.addedY(-1)); if (DoesBurnForever(BlockBelow)) diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index 428c0dbc16..e11b46cf25 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -150,7 +150,7 @@ void cFloodyFluidSimulator::SpreadXZ(cChunk * a_Chunk, int a_RelX, int a_RelY, i bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_MyMeta) { // If we have a section above, check if there's fluid above this block that would feed it: - if (a_RelY < cChunkDef::Height - 1) + if (cChunkDef::IsValidHeight(a_RelY, 1)) { if (IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ))) { diff --git a/src/Simulator/IncrementalRedstoneSimulator/DoorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/DoorHandler.h index cb772bb5be..34a8ae758f 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/DoorHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/DoorHandler.h @@ -45,7 +45,7 @@ namespace DoorHandler } else { - if (TopPosition.y == cChunkDef::Height) + if (TopPosition.y >= cChunkDef::UpperLimit) { return; } diff --git a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp index 9c7560a6c0..e0d1097499 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator/ForEachSourceCallback.cpp @@ -65,7 +65,7 @@ void ForEachSourceCallback::CheckIndirectPower() const Vector3i OffsetYP(0, 1, 0); const auto Above = m_Position + OffsetYP; - if (Above.y == cChunkDef::Height) + if (Above.y >= cChunkDef::UpperLimit) { return; } diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h index b40491820e..299acf7c37 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h @@ -155,7 +155,7 @@ namespace RedstoneWireHandler if ( !IsYPTerracingBlocked && // A block above us blocks all YP terracing, so the check is static in the loop - (Adjacent.y < (cChunkDef::Height - 1)) && + (Adjacent.y < (cChunkDef::UpperLimit - 1)) && (NeighbourChunk->GetBlock(Adjacent + OffsetYP) == E_BLOCK_REDSTONE_WIRE) // Only terrace YP with another wire ) { @@ -173,7 +173,7 @@ namespace RedstoneWireHandler if ( // IsYMTerracingBlocked (i.e. check block above lower terracing position, a.k.a. just the plain adjacent) (!cBlockInfo::IsSolid(LateralBlock) || cBlockInfo::IsTransparent(LateralBlock)) && - (Adjacent.y > 0) && + (Adjacent.y > cChunkDef::LowerLimit) && (NeighbourChunk->GetBlock(Adjacent + OffsetYM) == E_BLOCK_REDSTONE_WIRE) // Only terrace YM with another wire ) { diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index 13bc6bb36d..15a4541abe 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -234,7 +234,7 @@ void cSandSimulator::FinishFalling( BLOCKTYPE a_FallingBlockType, NIBBLETYPE a_FallingBlockMeta ) { - ASSERT(a_BlockY < cChunkDef::Height); + ASSERT(cChunkDef::IsValidHeight(a_BlockY)); BLOCKTYPE CurrentBlockType = a_World->GetBlock({ a_BlockX, a_BlockY, a_BlockZ }); if ((a_FallingBlockType == E_BLOCK_ANVIL) || IsReplacedOnRematerialization(CurrentBlockType)) diff --git a/src/Simulator/SimulatorManager.cpp b/src/Simulator/SimulatorManager.cpp index 7e5b9d0368..27342f1df4 100644 --- a/src/Simulator/SimulatorManager.cpp +++ b/src/Simulator/SimulatorManager.cpp @@ -107,7 +107,7 @@ void cSimulatorManager::WakeUp(const cCuboid & a_Area) cCuboid area(a_Area); area.Sort(); area.Expand(1, 1, 1, 1, 1, 1); // Expand the area to contain the neighbors, too. - area.ClampY(0, cChunkDef::Height - 1); + area.ClampY(cChunkDef::LowerLimit, cChunkDef::UpperLimit - 1); cChunkCoords ChunkStart = cChunkDef::BlockToChunk(area.p1); cChunkCoords ChunkEnd = cChunkDef::BlockToChunk(area.p2); diff --git a/src/World.cpp b/src/World.cpp index 67ae6623b1..6a1d3d73db 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -153,7 +153,7 @@ cWorld::cWorld( m_Dimension(a_Dimension), m_IsSpawnExplicitlySet(false), m_SpawnX(0), - m_SpawnY(cChunkDef::Height), + m_SpawnY(cChunkDef::UpperLimit), m_SpawnZ(0), m_BroadcastDeathMessages(true), m_BroadcastAchievementMessages(true), @@ -726,7 +726,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius) } // Check 0, 0 first. - int SpawnY = 0; + int SpawnY = cChunkDef::LowerLimit; if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z)) { SetSpawn(BiomeOffset.x, SpawnY, BiomeOffset.z); diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index 7e67d80598..79452f7a5d 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -132,7 +132,7 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT) if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Short)) { unsigned int Height = static_cast(a_NBT.GetShort(CurrLine)); - if (Height >= cChunkDef::Height) + if (Height >= cChunkDef::UpperLimit) { return false; } diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index dfefb74d31..c4551c7973 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -435,7 +435,7 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT // DEBUG magic: Invert the underground, so that we can see the MC generator in action :) bool ShouldInvert[cChunkDef::Width * cChunkDef::Width]; memset(ShouldInvert, 0, sizeof(ShouldInvert)); - for (int y = cChunkDef::Height - 1; y >= 0; y--) + for (int y = cChunkDef::UpperLimit - 1; y >= cChunkDef::LowerLimit; y--) { for (int x = 0; x < cChunkDef::Width; x++) for (int z = 0; z < cChunkDef::Width; z++) { @@ -590,7 +590,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntities & a_BlockEntities, const // Get the BlockEntity's position Vector3i absPos; - if (!GetBlockEntityNBTPos(a_NBT, Child, absPos) || (absPos.y < 0) || (absPos.y >= cChunkDef::Height)) + if (!GetBlockEntityNBTPos(a_NBT, Child, absPos) || (absPos.y < cChunkDef::LowerLimit) || (absPos.y >= cChunkDef::UpperLimit)) { LOGWARNING("Bad block entity, missing the coords. Will be ignored."); continue; @@ -631,7 +631,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntities & a_BlockEntities, const OwnedBlockEntity cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a_Tag, Vector3i a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - ASSERT((a_Pos.y >= 0) && (a_Pos.y < cChunkDef::Height)); + ASSERT(cChunkDef::IsValidHeight(a_Pos)); // Load the specific BlockEntity type: switch (a_BlockType) diff --git a/tests/Generating/BasicGeneratorTest.cpp b/tests/Generating/BasicGeneratorTest.cpp index 10c66050b0..e14330fe08 100644 --- a/tests/Generating/BasicGeneratorTest.cpp +++ b/tests/Generating/BasicGeneratorTest.cpp @@ -16,7 +16,7 @@ static void verifyChunkDescHeightmap(const cChunkDesc & a_ChunkDesc) { for (int z = 0; z < cChunkDef::Width; z++) { - for (int y = cChunkDef::Height - 1; y > 0; y--) + for (int y = cChunkDef::UpperLimit - 1; y > cChunkDef::LowerLimit; y--) { BLOCKTYPE BlockType = a_ChunkDesc.GetBlockType(x, y, z); if (BlockType != E_BLOCK_AIR) @@ -37,7 +37,7 @@ static void verifyChunkDescHeightmap(const cChunkDesc & a_ChunkDesc) static AString chunkSHA1(const cChunkDesc & a_ChunkDesc) { cSha1Checksum cs; - cs.Update(a_ChunkDesc.GetBlockTypes(), cChunkDef::Width * cChunkDef::Width * cChunkDef::Height); + cs.Update(a_ChunkDesc.GetBlockTypes(), cChunkDef::Width * cChunkDef::Width * cChunkDef::VerticalBlockCount); cSha1Checksum::Checksum digest; cs.Finalize(digest); AString res; @@ -52,11 +52,11 @@ static AString chunkSHA1(const cChunkDesc & a_ChunkDesc) /** Prints out the entire column from the chunk, one block type per line. */ static void printChunkColumn(const cChunkDesc & a_ChunkDesc, int a_X, int a_Z) { - auto prevBlockType = a_ChunkDesc.GetBlockType(a_X, cChunkDef::Height - 1, a_Z); + auto prevBlockType = a_ChunkDesc.GetBlockType(a_X, cChunkDef::UpperLimit - 1, a_Z); int count = 1; LOG("Column {%d, %d}:", a_X, a_Z); LOG("Yfrom\tYto\tcnt\ttype\ttypeStr"); - for (int y = cChunkDef::Height - 2; y >= 0; --y) + for (int y = cChunkDef::UpperLimit - 2; y >= cChunkDef::LowerLimit; --y) { auto blockType = a_ChunkDesc.GetBlockType(a_X, y, a_Z); if (blockType != prevBlockType) @@ -126,10 +126,10 @@ static void testGenerateOverworld(cChunkGenerator & aDefaultOverworldGen) TEST_EQUAL_MSG(validOverworldBlockTypes.count(blockType), 1, Printf("Block at {%d, %d, %d}: %d", x, y, z, blockType) ); - if (y < cChunkDef::Height - 1) + if (cChunkDef::IsValidHeight(y, 1)) { - TEST_EQUAL_MSG(chd.GetBlockType(x, cChunkDef::Height - 1, z), E_BLOCK_AIR, - Printf("Air at {%d, %d, %d}", x, cChunkDef::Height - 1, z) + TEST_EQUAL_MSG(chd.GetBlockType(x, cChunkDef::UpperLimit - 1, z), E_BLOCK_AIR, + Printf("Air at {%d, %d, %d}", x, cChunkDef::UpperLimit - 1, z) ); } }