Cuberite
A lightweight, fast and extensible game server for Minecraft
TNTEntity.cpp
Go to the documentation of this file.
1 #include "Globals.h"
2 
3 #include "TNTEntity.h"
4 #include "../World.h"
5 #include "../ClientHandle.h"
6 
7 
8 
9 
10 
11 cTNTEntity::cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks) :
12  Super(etTNT, a_Pos, 0.98f, 0.98f),
13  m_FuseTicks(a_FuseTicks)
14 {
15  SetGravity(-16.0f);
16  SetAirDrag(0.02f);
17 }
18 
19 
20 
21 
22 
23 void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle)
24 {
25  a_ClientHandle.SendSpawnEntity(*this);
26  m_bDirtyOrientation = false; // TODO: why?
27  m_bDirtyHead = false;
28 }
29 
30 
31 
32 
33 
35 {
36  FLOGD("BOOM at {0}", GetPosition());
37 
38  // Destroy first so the Explodinator doesn't find us (when iterating through entities):
39  Destroy();
40 
41  // TODO: provided centred coordinates to all calls to DoExplosionAt, from entities and blocks
42  // This is to ensure maximum efficiency of explosions
43  m_World->DoExplosionAt(4.0, GetPosX(), GetPosY() + GetHeight() / 2, GetPosZ(), true, esPrimedTNT, this);
44 }
45 
46 
47 
48 
49 
50 void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
51 {
52  Super::Tick(a_Dt, a_Chunk);
53  if (!IsTicking())
54  {
55  // The base class tick destroyed us
56  return;
57  }
58 
60 
61  if (m_FuseTicks > 0)
62  {
63  --m_FuseTicks;
64  }
65 
66  if (m_FuseTicks == 0)
67  {
68  Explode();
69  }
70 }
71 
72 
73 
74 
@ esPrimedTNT
Definition: Defines.h:316
#define FLOGD
Definition: LoggerSimple.h:91
Definition: Chunk.h:36
void SendSpawnEntity(const cEntity &a_Entity)
Definition: Entity.h:76
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
Definition: Entity.cpp:909
bool m_bDirtyOrientation
Stores whether our yaw / pitch / roll (body orientation) has been set manually.
Definition: Entity.h:597
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2259
void SetGravity(float a_Gravity)
Definition: Entity.h:282
double GetPosX(void) const
Definition: Entity.h:195
cWorld * m_World
Definition: Entity.h:624
double GetPosZ(void) const
Definition: Entity.h:197
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
double GetPosY(void) const
Definition: Entity.h:196
float GetHeight(void) const
Definition: Entity.h:193
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:286
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
bool m_bDirtyHead
Stores whether head yaw has been set manually.
Definition: Entity.h:594
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
Definition: Entity.cpp:1966
unsigned m_FuseTicks
How much ticks is left, while the tnt will explode.
Definition: TNTEntity.h:42
virtual void SpawnOn(cClientHandle &a_ClientHandle) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
Definition: TNTEntity.cpp:23
cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks=80)
Definition: TNTEntity.cpp:11
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: TNTEntity.cpp:50
void Explode(void)
Explode the tnt.
Definition: TNTEntity.cpp:34
virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void *a_SourceData) override
Does an explosion with the specified strength at the specified coordinates.
Definition: World.cpp:1384