Cuberite
A lightweight, fast and extensible game server for Minecraft
EnderCrystal.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "EnderCrystal.h"
5 #include "../ClientHandle.h"
6 #include "../Chunk.h"
7 #include "../World.h"
8 
9 
10 
11 
12 
13 cEnderCrystal::cEnderCrystal(Vector3d a_Pos, bool a_ShowBottom) :
14  cEnderCrystal(a_Pos, {}, false, a_ShowBottom)
15 {
16 }
17 
18 
19 
20 
21 
22 cEnderCrystal::cEnderCrystal(Vector3d a_Pos, Vector3i a_BeamTarget, bool a_DisplayBeam, bool a_ShowBottom) :
23  Super(etEnderCrystal, a_Pos, 2.0f, 2.0f),
24  m_BeamTarget(a_BeamTarget),
25  m_DisplayBeam(a_DisplayBeam),
26  m_ShowBottom(a_ShowBottom)
27 {
28  SetMaxHealth(5);
29 }
30 
31 
32 
33 
34 
35 void cEnderCrystal::SetShowBottom(bool a_ShowBottom)
36 {
37  m_ShowBottom = a_ShowBottom;
39 }
40 
41 
42 
43 
44 
46 {
47  m_BeamTarget = a_BeamTarget;
49 }
50 
51 
52 
53 
54 
55 void cEnderCrystal::SetDisplayBeam(bool a_DisplayBeam)
56 {
57  m_DisplayBeam = a_DisplayBeam;
59 }
60 
61 
62 
63 
64 
65 void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle)
66 {
67  a_ClientHandle.SendSpawnEntity(*this);
68  a_ClientHandle.SendEntityMetadata(*this);
69 }
70 
71 
72 
73 
74 
75 void cEnderCrystal::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
76 {
77  UNUSED(a_Dt);
79  {
81  }
82 }
83 
84 
85 
86 
87 
89 {
90  Super::KilledBy(a_TDI);
91 
92  // Destroy first so the Explodinator doesn't find us (when iterating through entities):
93  Destroy();
94 
95  m_World->DoExplosionAt(6.0, GetPosX(), GetPosY() + GetHeight() / 2, GetPosZ(), true, esEnderCrystal, this);
96 
97  const auto Position = GetPosition().Floor();
98  if (cChunkDef::IsValidHeight(Position))
99  {
100  m_World->SetBlock(Position, E_BLOCK_FIRE, 0);
101  }
102 }
@ E_BLOCK_FIRE
Definition: BlockType.h:61
@ dimEnd
Definition: Defines.h:234
@ esEnderCrystal
Definition: Defines.h:311
#define POS_TOINT
Definition: Entity.h:34
#define UNUSED
Definition: Globals.h:72
Definition: Chunk.h:36
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
Definition: ChunkDef.h:185
void SendSpawnEntity(const cEntity &a_Entity)
void SendEntityMetadata(const cEntity &a_Entity)
void SetDisplayBeam(bool a_DisplayBeam)
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
void SetShowBottom(bool a_ShowBottom)
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
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...
void SetBeamTarget(Vector3i a_BeamTarget)
bool m_DisplayBeam
Definition: EnderCrystal.h:41
Vector3i m_BeamTarget
Definition: EnderCrystal.h:40
cEnderCrystal(Vector3d a_Pos, bool a_ShowBottom)
Definition: Entity.h:76
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
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
Definition: Entity.cpp:851
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
Definition: Entity.cpp:1887
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
Definition: Vector3.h:177
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
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Returns the block type at the specified position.
Definition: World.h:363
virtual eDimension GetDimension(void) const override
Definition: World.h:133
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
Definition: World.cpp:1743