1
0
Fork 0

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:
Tommy Santerre 2015-02-14 17:11:38 -05:00
parent abd3f06a76
commit 3f6d823aa4
18 changed files with 31 additions and 22 deletions

View File

@ -80,7 +80,7 @@ void cChestEntity::UsedBy(cPlayer * a_Player)
void cChestEntity::OpenNewWindow(void) void cChestEntity::OpenNewWindow(void)
{ {
// TODO: cats are an obstruction // 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 // Obstruction, don't open
return; return;
@ -99,7 +99,7 @@ void cChestEntity::OpenNewWindow(void)
virtual bool Item(cChestEntity * a_Chest) override 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 // Obstruction, don't open
return false; return false;

View File

@ -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 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)));
} }

View File

@ -59,7 +59,7 @@ public:
a_Chunk.GetWorld()->QueueLightChunk(a_Chunk.GetPosX(), a_Chunk.GetPosZ()); a_Chunk.GetWorld()->QueueLightChunk(a_Chunk.GetPosX(), a_Chunk.GetPosZ());
return; 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 // Source block is not bright enough to spread
return; return;

View File

@ -45,7 +45,7 @@ public:
} }
// Farmland too dry. If nothing is growing on top, turn back to dirt: // 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) switch (UpperBlock)
{ {
case E_BLOCK_CROPS: case E_BLOCK_CROPS:

View File

@ -99,7 +99,7 @@ public:
// Check if it's fuel: // Check if it's fuel:
BLOCKTYPE BlockType; BLOCKTYPE BlockType;
if ( 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) || !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) ||
!cFireSimulator::IsFuel(BlockType) !cFireSimulator::IsFuel(BlockType)
) )
@ -126,7 +126,7 @@ public:
for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++) for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++)
{ {
if ( 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) && a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) &&
(BlockType == E_BLOCK_AIR) (BlockType == E_BLOCK_AIR)
) )

View File

@ -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 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 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
} }

View File

@ -931,7 +931,7 @@ void cChunk::ApplyWeatherToTop()
FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1); 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); 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) 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); LOGWARNING("UnboundedRelSetBlock(): requesting a block with a_RelY out of range: %d", a_RelY);
return false; 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) 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); LOGWARNING("UnboundedRelFastSetBlock(): requesting a block with a_RelY out of range: %d", a_RelY);
return false; return false;

View File

@ -1006,6 +1006,12 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
int BlockY = a_BlockY; int BlockY = a_BlockY;
int BlockZ = a_BlockZ; int BlockZ = a_BlockZ;
AddFaceDirection(BlockX, BlockY, BlockZ, a_BlockFace); AddFaceDirection(BlockX, BlockY, BlockZ, a_BlockFace);
if ((BlockY < 0) || (BlockY >= cChunkDef::Height))
{
return;
}
if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(BlockX, BlockY, BlockZ))->IsClickedThrough()) if (cBlockInfo::GetHandler(m_Player->GetWorld()->GetBlock(BlockX, BlockY, BlockZ))->IsClickedThrough())
{ {
a_BlockX = BlockX; a_BlockX = BlockX;

View File

@ -98,7 +98,7 @@ void cBoat::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed 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; return;
} }

View File

@ -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); Destroy(true);
return; return;
} }

View File

@ -571,7 +571,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc)
continue; 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. // The top block can't be snown over.
continue; continue;

View File

@ -41,7 +41,7 @@ public:
{ {
for (int x = 0; x < cChunkDef::Width; x++) 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]); Byte * shapeColumn = &(a_Shape[(x + 16 * z) * 256]);
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {

View File

@ -34,7 +34,7 @@ public:
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
// Door (bottom block) can be placed in Y range of [1, 254]: // 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; return false;
} }

View File

@ -132,7 +132,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
BLOCKTYPE TargetBlock = E_BLOCK_AIR; BLOCKTYPE TargetBlock = E_BLOCK_AIR;
if (a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock)) 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; return false;
} }

View File

@ -135,7 +135,7 @@ void cMonster::TickPathFinding()
{ 0, -1}, { 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 // Too low/high, can't really do anything
FinishPathFinding(); FinishPathFinding();

View File

@ -91,7 +91,7 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
int PosY = POSY_TOINT - 1; int PosY = POSY_TOINT - 1;
int PosZ = POSZ_TOINT; int PosZ = POSZ_TOINT;
if ((PosY <= 0) || (PosY > cChunkDef::Height)) if ((PosY <= 0) || (PosY >= cChunkDef::Height))
{ {
return; return;
} }

View File

@ -377,7 +377,7 @@ void cFireSimulator::RemoveFuelNeighbors(cChunk * a_Chunk, int a_RelX, int a_Rel
if (BlockType == E_BLOCK_TNT) if (BlockType == E_BLOCK_TNT)
{ {
m_World.SpawnPrimedTNT(AbsX, Y, AbsZ, 0); 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; return;
} }

View File

@ -31,7 +31,7 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY,
{ {
return; return;
} }
else if ((a_BlockY < 0) || (a_BlockY > cChunkDef::Height)) else if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height))
{ {
return; 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... if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above...
{ {
BLOCKTYPE Type = 0; BLOCKTYPE Type = 0;
if (a_RelBlockY + 1 >= cChunkDef::Height) if (a_RelBlockY >= cChunkDef::Height - 1)
{ {
continue; continue;
} }