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, int a_FuseTicks) :
12  super(etTNT, a_Pos, 0.98, 0.98),
13  m_FuseTicks(a_FuseTicks)
14 {
15  SetGravity(-16.0f);
16  SetAirDrag(0.4f);
17 }
18 
19 
20 
21 
22 
23 void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle)
24 {
25  a_ClientHandle.SendSpawnObject(*this, 50, 1, 0, 0); // 50 means TNT
26  m_bDirtyOrientation = false;
27  m_bDirtyHead = false;
28 }
29 
30 
31 
32 
33 
35 {
36  m_FuseTicks = 0;
37  Destroy(true);
38  FLOGD("BOOM at {0}", GetPosition());
39  m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
40 }
41 
42 
43 
44 
45 
46 void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
47 {
48  super::Tick(a_Dt, a_Chunk);
49  if (!IsTicking())
50  {
51  // The base class tick destroyed us
52  return;
53  }
55 
56  m_FuseTicks -= 1;
57  if (m_FuseTicks <= 0)
58  {
59  Explode();
60  }
61 }
62 
63 
64 
65 
double GetPosY(void) const
Definition: Entity.h:207
double GetPosX(void) const
Definition: Entity.h:206
cWorld * m_World
Definition: Entity.h:620
void SendSpawnObject(const cEntity &a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
void Explode(void)
Explode the tnt.
Definition: TNTEntity.cpp:34
Definition: Chunk.h:49
virtual void Destroy(bool a_ShouldBroadcast=true)
Destroys the entity and schedules it for memory freeing; if a_ShouldBroadcast is set to true...
Definition: Entity.cpp:219
bool m_bDirtyHead
Stores whether head yaw has been set manually.
Definition: Entity.h:594
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:2201
void SetGravity(float a_Gravity)
Definition: Entity.h:288
#define FLOGD(...)
Definition: LoggerSimple.h:48
cTNTEntity(Vector3d a_Pos, int a_FuseTicks=80)
Definition: TNTEntity.cpp:11
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
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:1399
Definition: Entity.h:73
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:307
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:292
double GetPosZ(void) const
Definition: Entity.h:208
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: TNTEntity.cpp:46
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
Definition: Entity.cpp:841
int m_FuseTicks
How much ticks is left, while the tnt will explode.
Definition: TNTEntity.h:39
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
Definition: Entity.cpp:1878