Correct world height validations.
Unify the way we test block above the current one (Height - 1 instead of a_RelY + 1). Allow generation of world of flat height = 255
This commit is contained in:
parent
abd3f06a76
commit
3f6d823aa4
@ -80,7 +80,7 @@ void cChestEntity::UsedBy(cPlayer * a_Player)
|
||||
void cChestEntity::OpenNewWindow(void)
|
||||
{
|
||||
// TODO: cats are an obstruction
|
||||
if ((GetPosY() + 1 < cChunkDef::Height) && cBlockInfo::IsSolid(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ())))
|
||||
if ((GetPosY() < cChunkDef::Height - 1) && cBlockInfo::IsSolid(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ())))
|
||||
{
|
||||
// Obstruction, don't open
|
||||
return;
|
||||
@ -99,7 +99,7 @@ void cChestEntity::OpenNewWindow(void)
|
||||
|
||||
virtual bool Item(cChestEntity * a_Chest) override
|
||||
{
|
||||
if ((a_Chest->GetPosY() + 1 < cChunkDef::Height) && cBlockInfo::IsSolid(a_Chest->GetWorld()->GetBlock(a_Chest->GetPosX(), a_Chest->GetPosY() + 1, a_Chest->GetPosZ())))
|
||||
if ((a_Chest->GetPosY() < cChunkDef::Height - 1) && cBlockInfo::IsSolid(a_Chest->GetWorld()->GetBlock(a_Chest->GetPosX(), a_Chest->GetPosY() + 1, a_Chest->GetPosZ())))
|
||||
{
|
||||
// Obstruction, don't open
|
||||
return false;
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
|
||||
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||
{
|
||||
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER)));
|
||||
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height - 1) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
a_Chunk.GetWorld()->QueueLightChunk(a_Chunk.GetPosX(), a_Chunk.GetPosZ());
|
||||
return;
|
||||
}
|
||||
else if (std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ))) < 9)
|
||||
else if ((a_RelY < cChunkDef::Height - 1) && std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ))) < 9)
|
||||
{
|
||||
// Source block is not bright enough to spread
|
||||
return;
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
}
|
||||
|
||||
// Farmland too dry. If nothing is growing on top, turn back to dirt:
|
||||
BLOCKTYPE UpperBlock = (a_RelY >= cChunkDef::Height) ? E_BLOCK_AIR : a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
|
||||
BLOCKTYPE UpperBlock = (a_RelY >= cChunkDef::Height - 1) ? E_BLOCK_AIR : a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
|
||||
switch (UpperBlock)
|
||||
{
|
||||
case E_BLOCK_CROPS:
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
// Check if it's fuel:
|
||||
BLOCKTYPE BlockType;
|
||||
if (
|
||||
((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) ||
|
||||
((a_RelY + y < 0) || (a_RelY + y >= cChunkDef::Height)) ||
|
||||
!a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) ||
|
||||
!cFireSimulator::IsFuel(BlockType)
|
||||
)
|
||||
@ -126,7 +126,7 @@ public:
|
||||
for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++)
|
||||
{
|
||||
if (
|
||||
((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y <= cChunkDef::Height)) &&
|
||||
((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y < cChunkDef::Height)) &&
|
||||
a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) &&
|
||||
(BlockType == E_BLOCK_AIR)
|
||||
)
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
|
||||
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
||||
{
|
||||
if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height))
|
||||
if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height - 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
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ void cChunk::ApplyWeatherToTop()
|
||||
FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1);
|
||||
}
|
||||
}
|
||||
else if (cBlockInfo::IsSnowable(TopBlock) && (Height + 1 < cChunkDef::Height))
|
||||
else if (cBlockInfo::IsSnowable(TopBlock) && (Height < cChunkDef::Height - 1))
|
||||
{
|
||||
SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0);
|
||||
}
|
||||
@ -1253,7 +1253,7 @@ bool cChunk::UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBB
|
||||
|
||||
bool cChunk::UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||
{
|
||||
if ((a_RelY < 0) || (a_RelY > cChunkDef::Height))
|
||||
if ((a_RelY < 0) || (a_RelY >= cChunkDef::Height))
|
||||
{
|
||||
LOGWARNING("UnboundedRelSetBlock(): requesting a block with a_RelY out of range: %d", a_RelY);
|
||||
return false;
|
||||
@ -1274,7 +1274,7 @@ bool cChunk::UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE
|
||||
|
||||
bool cChunk::UnboundedRelFastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||
{
|
||||
if ((a_RelY < 0) || (a_RelY > cChunkDef::Height))
|
||||
if ((a_RelY < 0) || (a_RelY >= cChunkDef::Height))
|
||||
{
|
||||
LOGWARNING("UnboundedRelFastSetBlock(): requesting a block with a_RelY out of range: %d", a_RelY);
|
||||
return false;
|
||||
|
@ -1006,6 +1006,12 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
|
||||
int BlockY = a_BlockY;
|
||||
int BlockZ = a_BlockZ;
|
||||
AddFaceDirection(BlockX, BlockY, BlockZ, a_BlockFace);
|
||||
|
||||
if ((BlockY < 0) || (BlockY >= cChunkDef::Height))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(BlockX, BlockY, BlockZ))->IsClickedThrough())
|
||||
{
|
||||
a_BlockX = BlockX;
|
||||
|
@ -98,7 +98,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 < 0) || (POSY_TOINT >= cChunkDef::Height))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -77,7 +77,10 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
||||
);
|
||||
*/
|
||||
|
||||
cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta);
|
||||
if (BlockY < cChunkDef::Height - 1)
|
||||
{
|
||||
cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta);
|
||||
}
|
||||
Destroy(true);
|
||||
return;
|
||||
}
|
||||
|
@ -571,7 +571,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::Height - 1))
|
||||
{
|
||||
// The top block can't be snown over.
|
||||
continue;
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
{
|
||||
for (int x = 0; x < cChunkDef::Width; x++)
|
||||
{
|
||||
HEIGHTTYPE height = cChunkDef::GetHeight(heightMap, x, z) + 1;
|
||||
int height = cChunkDef::GetHeight(heightMap, x, z) + 1;
|
||||
Byte * shapeColumn = &(a_Shape[(x + 16 * z) * 256]);
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
||||
|
||||
// Door (bottom block) can be placed in Y range of [1, 254]:
|
||||
if ((a_BlockY < 1) || (a_BlockY + 2 >= cChunkDef::Height))
|
||||
if ((a_BlockY < 1) || (a_BlockY >= cChunkDef::Height - 2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
|
||||
BLOCKTYPE TargetBlock = E_BLOCK_AIR;
|
||||
if (a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock))
|
||||
{
|
||||
if ((a_RelY + 1 > cChunkDef::Height) || (a_RelY - 1 < 0))
|
||||
if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ void cMonster::TickPathFinding()
|
||||
{ 0, -1},
|
||||
} ;
|
||||
|
||||
if ((PosY - 1 < 0) || (PosY + 2 > cChunkDef::Height) /* PosY + 1 will never be true if PosY + 2 is not */)
|
||||
if ((PosY - 1 < 0) || (PosY + 2 >= cChunkDef::Height) /* PosY + 1 will never be true if PosY + 2 is not */)
|
||||
{
|
||||
// Too low/high, can't really do anything
|
||||
FinishPathFinding();
|
||||
|
@ -91,7 +91,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 <= 0) || (PosY >= cChunkDef::Height))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
|
||||
if (BlockType == E_BLOCK_TNT)
|
||||
{
|
||||
m_World.SpawnPrimedTNT(AbsX, Y, AbsZ, 0);
|
||||
Neighbour->SetBlock(X, a_RelY + Y, Z, E_BLOCK_AIR, 0);
|
||||
Neighbour->SetBlock(X, Y, Z, E_BLOCK_AIR, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY,
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if ((a_BlockY < 0) || (a_BlockY > cChunkDef::Height))
|
||||
else if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -556,7 +556,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_RelBlockX, int a_Re
|
||||
if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above...
|
||||
{
|
||||
BLOCKTYPE Type = 0;
|
||||
if (a_RelBlockY + 1 >= cChunkDef::Height)
|
||||
if (a_RelBlockY >= cChunkDef::Height - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user