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
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "HangingEntity.h"
#include "BlockInfo.h"
#include "Player.h"
#include "Chunk.h"
#include "../ClientHandle.h"
cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Vector3d a_Pos) :
Super(a_EntityType, a_Pos, 0.5f, 0.5f), m_Facing(cHangingEntity::BlockFaceToProtocolFace(a_Facing))
{
SetMaxHealth(1);
SetHealth(1);
}
bool cHangingEntity::IsValidSupportBlock(const BLOCKTYPE a_BlockType)
{
return cBlockInfo::IsSolid(a_BlockType) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_OFF) &&
(a_BlockType != E_BLOCK_REDSTONE_REPEATER_ON);
}
void cHangingEntity::KilledBy(TakeDamageInfo & a_TDI)
{
Super::KilledBy(a_TDI);
Destroy();
}
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
SetYaw(GetProtocolFacing() * 90);
}
void cHangingEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
UNUSED(a_Dt);
// Check for a valid support block once every 64 ticks (3.2 seconds):
if ((m_World->GetWorldTickAge() % 64_tick) != 0_tick)
{
return;
}
BLOCKTYPE Block;
const auto SupportPosition =
AddFaceDirection(cChunkDef::AbsoluteToRelative(GetPosition()), ProtocolFaceToBlockFace(m_Facing), true);
if (!a_Chunk.UnboundedRelGetBlockType(SupportPosition, Block) || IsValidSupportBlock(Block))
{
return;
}
// Take environmental damage, intending to self-destruct, with "take damage" handling done by child classes:
TakeDamage(dtEnvironment, nullptr, static_cast<int>(GetMaxHealth()), 0);
}
|