summaryrefslogtreecommitdiffstats
path: root/source/Entity.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-18 10:24:34 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-18 10:24:34 +0200
commit547c34132530a4dba841879595bd0762ef52a22d (patch)
tree8c9f14efe8e313244c0dc7a69e5e1952fc3da384 /source/Entity.cpp
parentExtended the cloc stats for the entire project (diff)
downloadcuberite-547c34132530a4dba841879595bd0762ef52a22d.tar
cuberite-547c34132530a4dba841879595bd0762ef52a22d.tar.gz
cuberite-547c34132530a4dba841879595bd0762ef52a22d.tar.bz2
cuberite-547c34132530a4dba841879595bd0762ef52a22d.tar.lz
cuberite-547c34132530a4dba841879595bd0762ef52a22d.tar.xz
cuberite-547c34132530a4dba841879595bd0762ef52a22d.tar.zst
cuberite-547c34132530a4dba841879595bd0762ef52a22d.zip
Diffstat (limited to '')
-rw-r--r--source/Entity.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/Entity.cpp b/source/Entity.cpp
index 09cb3d030..082e1e925 100644
--- a/source/Entity.cpp
+++ b/source/Entity.cpp
@@ -211,26 +211,35 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
{
- //TODO Add collision detection with entities.
+ // TODO Add collision detection with entities.
a_Dt /= 1000;
Vector3d NextPos = Vector3d(GetPosX(),GetPosY(),GetPosZ());
Vector3d NextSpeed = Vector3d(GetSpeedX(),GetSpeedY(),GetSpeedZ());
int BlockX = (int) floor(NextPos.x);
int BlockY = (int) floor(NextPos.y);
int BlockZ = (int) floor(NextPos.z);
- //Make sure we got the correct chunk and a valid one. No one ever knows...
+
+ if ((BlockY >= cChunkDef::Height) || (BlockY < 0))
+ {
+ // Outside of the world
+ // TODO: Current speed should still be added to the entity position
+ // Otherwise TNT explosions in the void will still effect the bottommost layers of the world
+ return;
+ }
+
+ // Make sure we got the correct chunk and a valid one. No one ever knows...
cChunk * NextChunk = a_Chunk.GetNeighborChunk(BlockX,BlockZ);
if (NextChunk != NULL)
{
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
- if(!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block
+ if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block
{
- if( m_bOnGround ) // check if it's still on the ground
+ if (m_bOnGround) // check if it's still on the ground
{
BLOCKTYPE BlockBelow = NextChunk->GetBlock( RelBlockX, BlockY - 1, RelBlockZ );
- if(!g_BlockIsSolid[BlockBelow]) //Check if block below is air or water.
+ if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water.
{
m_bOnGround = false;
}
@@ -353,14 +362,15 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NextPos += (NextSpeed * a_Dt);
}
else
- { // We didn't hit anything, so move =]
+ {
+ // We didn't hit anything, so move =]
NextPos += (NextSpeed * a_Dt);
}
}
BlockX = (int) floor(NextPos.x);
- BlockZ = (int) floor(NextPos.z);
+ BlockZ = (int) floor(NextPos.z);
NextChunk = NextChunk->GetNeighborChunk(BlockX,BlockZ);
- //See if we can commit our changes. If not, we will discard them.
+ // See if we can commit our changes. If not, we will discard them.
if (NextChunk != NULL)
{
if (NextPos.x != GetPosX()) SetPosX(NextPos.x);