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