2013-07-29 07:13:03 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "FallingBlock.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../World.h"
|
|
|
|
#include "../ClientHandle.h"
|
|
|
|
#include "../Simulator/SandSimulator.h"
|
|
|
|
#include "../Chunk.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cFallingBlock::cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
|
|
|
|
super(etFallingBlock, a_BlockPosition.x + 0.5f, a_BlockPosition.y + 0.5f, a_BlockPosition.z + 0.5f, 0.98, 0.98),
|
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_BlockMeta(a_BlockMeta),
|
|
|
|
m_OriginalPosition(a_BlockPosition)
|
|
|
|
{
|
2015-03-30 19:42:32 -04:00
|
|
|
SetGravity(-16.0f);
|
2015-03-31 11:03:35 -04:00
|
|
|
SetAirDrag(0.02f);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle)
|
|
|
|
{
|
|
|
|
a_ClientHandle.SendSpawnFallingBlock(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// GetWorld()->BroadcastTeleportEntity(*this); // Test position
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-03-05 17:12:48 -05:00
|
|
|
int BlockX = POSX_TOINT;
|
2015-05-24 07:56:56 -04:00
|
|
|
int BlockY = static_cast<int>(GetPosY() - 0.5);
|
2014-03-05 17:12:48 -05:00
|
|
|
int BlockZ = POSZ_TOINT;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (BlockY < 0)
|
|
|
|
{
|
|
|
|
// Fallen out of this world, just continue falling until out of sight, then destroy:
|
2014-03-05 17:12:48 -05:00
|
|
|
if (BlockY < VOID_BOUNDARY)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
Destroy(true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (BlockY >= cChunkDef::Height)
|
|
|
|
{
|
|
|
|
// Above the world, just wait for it to fall back down
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width);
|
|
|
|
NIBBLETYPE BelowMeta = a_Chunk.GetMeta(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width);
|
2013-07-29 07:13:03 -04:00
|
|
|
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);
|
|
|
|
Destroy(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
2015-02-14 17:11:38 -05:00
|
|
|
if (BlockY < cChunkDef::Height - 1)
|
|
|
|
{
|
|
|
|
cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta);
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
Destroy(true);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
float MilliDt = a_Dt.count() * 0.001f;
|
2014-03-05 17:12:48 -05:00
|
|
|
AddSpeedY(MilliDt * -9.8f);
|
|
|
|
AddPosition(GetSpeed() * MilliDt);
|
|
|
|
|
2014-05-04 09:15:10 -04:00
|
|
|
// If not static (one billionth precision) broadcast movement
|
2014-04-27 12:35:41 -04:00
|
|
|
if ((fabs(GetSpeedX()) > std::numeric_limits<double>::epsilon()) || (fabs(GetSpeedZ()) > std::numeric_limits<double>::epsilon()))
|
2014-03-05 17:12:48 -05:00
|
|
|
{
|
|
|
|
BroadcastMovementUpdate();
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|