1
0
cuberite-2a/src/Entities/TNTEntity.cpp

75 lines
1.2 KiB
C++
Raw Normal View History

#include "Globals.h"
#include "TNTEntity.h"
#include "../World.h"
#include "../ClientHandle.h"
cTNTEntity::cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks) :
2020-04-13 16:38:06 +00:00
Super(etTNT, a_Pos, 0.98, 0.98),
2014-03-08 11:24:33 +00:00
m_FuseTicks(a_FuseTicks)
{
SetGravity(-16.0f);
2020-03-19 02:35:21 +00:00
SetAirDrag(0.02f);
}
void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
2020-04-20 19:46:04 +00:00
a_ClientHandle.SendSpawnEntity(*this);
m_bDirtyOrientation = false; // TODO: why?
m_bDirtyHead = false;
}
void cTNTEntity::Explode(void)
{
FLOGD("BOOM at {0}", GetPosition());
// Destroy first so the Explodinator doesn't find us (when iterating through entities):
Destroy();
// TODO: provided centred coordinates to all calls to DoExplosionAt, from entities and blocks
// This is to ensure maximum efficiency of explosions
m_World->DoExplosionAt(4.0, GetPosX(), GetPosY() + GetHeight() / 2, GetPosZ(), true, esPrimedTNT, this);
}
void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
2020-04-13 16:38:06 +00:00
Super::Tick(a_Dt, a_Chunk);
if (!IsTicking())
{
// The base class tick destroyed us
return;
}
BroadcastMovementUpdate();
2016-02-05 21:45:45 +00:00
if (m_FuseTicks > 0)
{
--m_FuseTicks;
}
if (m_FuseTicks == 0)
{
Explode();
}
}