2012-09-30 12:37:44 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "FallingBlock.h"
|
|
|
|
#include "World.h"
|
|
|
|
#include "ClientHandle.h"
|
2013-03-02 14:57:09 -05:00
|
|
|
#include "Simulator/SandSimulator.h"
|
2013-04-13 17:02:10 -04:00
|
|
|
#include "Chunk.h"
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
2012-12-21 07:21:20 -05:00
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
2013-03-02 14:57:09 -05:00
|
|
|
cFallingBlock::cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
|
2013-07-01 06:39:56 -04:00
|
|
|
super(etFallingBlock, a_BlockPosition.x + 0.5f, a_BlockPosition.y + 0.5f, a_BlockPosition.z + 0.5f, 0.98, 0.98),
|
2013-03-02 14:57:09 -05:00
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_BlockMeta(a_BlockMeta),
|
|
|
|
m_OriginalPosition(a_BlockPosition)
|
2012-09-30 12:37:44 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cFallingBlock::Initialize(cWorld * a_World)
|
|
|
|
{
|
2013-03-02 14:57:09 -05:00
|
|
|
super::Initialize(a_World);
|
2013-07-07 09:06:06 -04:00
|
|
|
a_World->BroadcastSpawnEntity(*this);
|
2012-09-30 12:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
|
|
|
|
{
|
2012-12-26 04:12:00 -05:00
|
|
|
a_ClientHandle.SendSpawnFallingBlock(*this);
|
2012-09-30 12:37:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk)
|
2012-09-30 12:37:44 -04:00
|
|
|
{
|
|
|
|
float MilliDt = a_Dt * 0.001f;
|
2013-03-23 00:33:47 -04:00
|
|
|
AddSpeedY(MilliDt * -9.8f);
|
|
|
|
AddPosY(GetSpeedY() * MilliDt);
|
2012-09-30 12:37:44 -04:00
|
|
|
|
2013-03-02 14:57:09 -05:00
|
|
|
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
|
|
|
|
|
2013-05-19 07:49:01 -04:00
|
|
|
int BlockX = m_OriginalPosition.x;
|
2013-03-22 02:33:10 -04:00
|
|
|
int BlockY = (int)(GetPosY() - 0.5);
|
2013-05-19 07:49:01 -04:00
|
|
|
int BlockZ = m_OriginalPosition.z;
|
2013-03-02 14:57:09 -05:00
|
|
|
|
|
|
|
if (BlockY < 0)
|
|
|
|
{
|
|
|
|
// Fallen out of this world, just continue falling until out of sight, then destroy:
|
|
|
|
if (BlockY < 100)
|
|
|
|
{
|
2013-06-25 02:36:59 -04:00
|
|
|
Destroy(true);
|
2013-03-02 14:57:09 -05:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
if (BlockY >= cChunkDef::Height)
|
2012-09-30 12:37:44 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
// Above the world, just wait for it to fall back down
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = a_Chunk.MakeIndexNoCheck(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width);
|
|
|
|
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(idx);
|
|
|
|
NIBBLETYPE BelowMeta = a_Chunk.GetMeta(idx);
|
|
|
|
if (cSandSimulator::DoesBreakFallingThrough(BlockBelow, BelowMeta))
|
|
|
|
{
|
|
|
|
// Fallen onto a block that breaks this into pickups (e. g. half-slab)
|
|
|
|
// Must finish the fall with coords one below the block:
|
|
|
|
cSandSimulator::FinishFalling(m_World, BlockX, BlockY, BlockZ, m_BlockType, m_BlockMeta);
|
2013-06-25 02:36:59 -04:00
|
|
|
Destroy(true);
|
2013-04-13 17:02:10 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!cSandSimulator::CanContinueFallThrough(BlockBelow))
|
|
|
|
{
|
|
|
|
// Fallen onto a solid block
|
2013-05-19 07:49:01 -04:00
|
|
|
/*
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta);
|
2013-06-25 02:36:59 -04:00
|
|
|
Destroy(true);
|
2013-04-13 17:02:10 -04:00
|
|
|
return;
|
2012-09-30 12:37:44 -04:00
|
|
|
}
|
2012-12-21 07:21:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|