summaryrefslogtreecommitdiffstats
path: root/src/Entities/EnderCrystal.cpp
blob: defa396f57d230f6b63574ad7fcadd89e92ccb33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#include "Globals.h"  // NOTE: MSVC stupidness requires this to be the same across all modules

#include "EnderCrystal.h"
#include "../ClientHandle.h"
#include "../Chunk.h"
#include "../World.h"





cEnderCrystal::cEnderCrystal(Vector3d a_Pos, bool a_ShowBottom) :
	cEnderCrystal(a_Pos, {}, false, a_ShowBottom)
{
}





cEnderCrystal::cEnderCrystal(Vector3d a_Pos, Vector3i a_BeamTarget, bool a_DisplayBeam, bool a_ShowBottom) :
	Super(etEnderCrystal, a_Pos, 1.0, 1.0),
	m_BeamTarget(a_BeamTarget),
	m_DisplayBeam(a_DisplayBeam),
	m_ShowBottom(a_ShowBottom)
{
	SetMaxHealth(5);
}





void cEnderCrystal::SetShowBottom(bool a_ShowBottom)
{
	m_ShowBottom = a_ShowBottom;
	m_World->BroadcastEntityMetadata(*this);
}





void cEnderCrystal::SetBeamTarget(Vector3i a_BeamTarget)
{
	m_BeamTarget = a_BeamTarget;
	m_World->BroadcastEntityMetadata(*this);
}





void cEnderCrystal::SetDisplayBeam(bool a_DisplayBeam)
{
	m_DisplayBeam = a_DisplayBeam;
	m_World->BroadcastEntityMetadata(*this);
}





void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle)
{
	a_ClientHandle.SendSpawnEntity(*this);
	a_ClientHandle.SendEntityMetadata(*this);
}





void cEnderCrystal::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	UNUSED(a_Dt);
	if ((m_World->GetDimension() == dimEnd) && (m_World->GetBlock(POS_TOINT) != E_BLOCK_FIRE))
	{
		m_World->SetBlock(POS_TOINT, E_BLOCK_FIRE, 0);
	}
}





void cEnderCrystal::KilledBy(TakeDamageInfo & a_TDI)
{
	Super::KilledBy(a_TDI);

	// Destroy first so the Explodinator doesn't find us (when iterating through entities):
	Destroy();

	m_World->DoExplosionAt(6.0, GetPosX(), GetPosY() + (GetHeight() / 2.0), GetPosZ(), true, esEnderCrystal, this);

	const auto Position = GetPosition().Floor();
	if (cChunkDef::IsValidHeight(Position.y))
	{
		m_World->SetBlock(Position, E_BLOCK_FIRE, 0);
	}
}