Fixed entity chunking.

Sand simulator was off, sand in negative coords wouldn't fall properly

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1489 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-05-19 11:49:01 +00:00
parent 1e4aaa774a
commit 34fa53ca3a
5 changed files with 24 additions and 6 deletions

View File

@ -500,7 +500,7 @@ void cChunk::Tick(float a_Dt)
void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
{
cChunk * Neighbor = GetNeighborChunk((int)a_Entity->GetPosX(), (int)a_Entity->GetPosZ());
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
if (Neighbor == NULL)
{
Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
@ -512,6 +512,8 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
}
}
ASSERT(Neighbor != this); // Moving into the same chunk? wtf?
Neighbor->AddEntity(a_Entity);
class cMover :

View File

@ -122,8 +122,8 @@ public:
double GetSpeedY (void) const { return m_Speed.y; }
double GetSpeedZ (void) const { return m_Speed.z; }
int GetChunkX(void) const {return FAST_FLOOR_DIV(((int)m_Pos.x), cChunkDef::Width); }
int GetChunkZ(void) const {return FAST_FLOOR_DIV(((int)m_Pos.z), cChunkDef::Width); }
int GetChunkX(void) const {return (int)floor(m_Pos.x / cChunkDef::Width); }
int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); }
void SetHeadYaw (double a_HeadYaw);
void SetMass (double a_Mass);

View File

@ -49,9 +49,9 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
int BlockX = (int)m_OriginalPosition.x;
int BlockX = m_OriginalPosition.x;
int BlockY = (int)(GetPosY() - 0.5);
int BlockZ = (int)m_OriginalPosition.z;
int BlockZ = m_OriginalPosition.z;
if (BlockY < 0)
{
@ -83,6 +83,15 @@ void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
else if (!cSandSimulator::CanContinueFallThrough(BlockBelow))
{
// Fallen onto a solid block
/*
LOGD(
"Sand: Checked below at {%d, %d, %d} (rel {%d, %d, %d}), it's %s, finishing the fall.",
BlockX, BlockY, BlockZ,
BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width,
ItemTypeToString(BlockBelow).c_str()
);
*/
cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta);
Destroy();
return;

View File

@ -23,6 +23,7 @@ class cFallingBlock :
public:
CLASS_PROTODEF(cFallingBlock);
/// Creates a new falling block. a_BlockPosition is expected in world coords
cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
@ -36,7 +37,7 @@ public:
private:
BLOCKTYPE m_BlockType;
NIBBLETYPE m_BlockMeta;
Vector3i m_OriginalPosition;
Vector3i m_OriginalPosition; // Position where the falling block has started, in world coords
} ;

View File

@ -53,6 +53,12 @@ void cSandSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChun
Pos.x = itr->x + BaseX;
Pos.y = itr->y;
Pos.z = itr->z + BaseZ;
/*
LOGD(
"Creating a falling block at {%d, %d, %d} of type %s, block below: %s",
Pos.x, Pos.y, Pos.z, ItemTypeToString(BlockType).c_str(), ItemTypeToString(BlockBelow).c_str()
);
*/
cFallingBlock * FallingBlock = new cFallingBlock(Pos, BlockType, a_Chunk->GetMeta(itr->x, itr->y, itr->z));
FallingBlock->Initialize(&m_World);
a_Chunk->SetBlock(itr->x, itr->y, itr->z, E_BLOCK_AIR, 0);