Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created constant for lower bound of chunk #5488

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
30 changes: 30 additions & 0 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Notes = "The width of a chunk, in number of blocks.",
Notes = "The X or Z size of a chunk, in number of blocks.",

},
LowerLimit =
{
Notes = "The lower limit of the chunk coordinate vertical range.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Notes = "The lower limit of the chunk coordinate vertical range.",
Notes = "The lower limit of the chunk coordinate vertical (Y) range.",

},
UpperLimit =
{
Notes = "The upper limit of the chunk coordinate vertical range.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Notes = "The upper limit of the chunk coordinate vertical range.",
Notes = "The upper limit of the chunk coordinate vertical (Y) 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 = [[
Expand Down
9 changes: 9 additions & 0 deletions src/Bindings/ManualBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be exported as cChunkDef.Height; once we clean up the C++ code so that it doesn't use Height as the upper limit, we can change the C++ counterpart to Height, too.

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);
Expand Down
10 changes: 5 additions & 5 deletions src/Bindings/ManualBindings_BlockArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/BlockArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BlockEntities/BeaconEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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<double>(cChunkDef::Height), -Radius);
auto Area = cBoundingBox(m_Pos, Radius, Radius + static_cast<double>(cChunkDef::UpperLimit), -Radius);
GetWorld()->ForEachEntityInBox(Area, [&](cEntity & a_Entity)
{
if (!a_Entity.IsPlayer())
Expand Down
2 changes: 1 addition & 1 deletion src/BlockEntities/ChestEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion src/BlockEntities/EnderChestEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion src/BlockEntities/HopperEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/BlockTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockBigFlower.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down
6 changes: 3 additions & 3 deletions src/Blocks/BlockCactus.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ 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)
)
{
++top;
}
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)
)
{
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockCarpet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockCrops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Blocks/BlockDoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}


Expand All @@ -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<NIBBLETYPE>((DownMeta & 0x07) | 0x08 | (Meta << 4));
Expand All @@ -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<NIBBLETYPE>(Meta | (UpMeta << 4));
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockFarmland.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockFire.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockFlower.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}


Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockLeaves.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockNetherWart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockPortal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockSapling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}


Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockStems.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockSugarCane.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
{
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockTallGrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockVines.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ 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));
}

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;
Expand Down