2013-07-29 07:13:03 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "FallingBlock.h"
|
2020-04-03 02:57:01 -04:00
|
|
|
#include "../BlockInfo.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-29 08:59:24 -04:00
|
|
|
cFallingBlock::cFallingBlock(Vector3i a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
|
|
|
|
super(etFallingBlock, Vector3d(0.5, 0, 0.5) + a_BlockPosition, 0.98, 0.98),
|
2013-07-29 07:13:03 -04:00
|
|
|
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
|
|
|
{
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
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);
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2013-07-29 07:13:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!cSandSimulator::CanContinueFallThrough(BlockBelow))
|
|
|
|
{
|
|
|
|
// Fallen onto a solid block
|
|
|
|
/*
|
2018-09-24 16:33:39 -04:00
|
|
|
FLOGD(
|
|
|
|
"Sand: Checked below at {0} (rel {1}), it's {2}, finishing the fall.",
|
|
|
|
Vector3i{BlockX, BlockY, BlockZ},
|
|
|
|
cChunkDef::AbsoluteToRelative({BlockX, BlockY, BlockZ}, {a_Chunk.GetPosX(), a_Chunk.GetPosZ()}),
|
|
|
|
ItemTypeToString(BlockBelow)
|
2013-07-29 07:13:03 -04:00
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
}
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2013-07-29 07:13:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2018-01-03 11:33:31 -05:00
|
|
|
else if ((m_BlockType == E_BLOCK_CONCRETE_POWDER) && IsBlockWater(BlockBelow))
|
|
|
|
{
|
|
|
|
// Concrete powder falling into water solidifies on the first water it touches
|
|
|
|
cSandSimulator::FinishFalling(m_World, BlockX, BlockY, BlockZ, E_BLOCK_CONCRETE, m_BlockMeta);
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2018-01-03 11:33:31 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|