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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#include "stdafx.h"
#include "JavaMath.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.world.level.h"
#include "PrimedTnt.h"
void PrimedTnt::_init()
{
life = 0;
// Original Java Ctor
blocksBuilding = true;
setSize(0.98f, 0.98f);
heightOffset = bbHeight / 2.0f;
owner = weak_ptr<LivingEntity>();
}
PrimedTnt::PrimedTnt(Level *level) : Entity( level )
{
// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
// the derived version of the function is called
this->defineSynchedData();
_init();
}
PrimedTnt::PrimedTnt(Level *level, double x, double y, double z, shared_ptr<LivingEntity> owner) : Entity( level )
{
_init();
setPos(x, y, z);
float rot = (float) (Math::random() * PI * 2);
xd = -sin(rot) * 0.02f;
yd = +0.2f;
zd = -cos(rot) * 0.02f;
life = 80;
xo = x;
yo = y;
zo = z;
this->owner = weak_ptr<LivingEntity>(owner);
}
void PrimedTnt::defineSynchedData()
{
}
bool PrimedTnt::makeStepSound()
{
return false;
}
bool PrimedTnt::isPickable()
{
return !removed;
}
void PrimedTnt::tick()
{
xo = x;
yo = y;
zo = z;
yd -= 0.04f;
move(xd, yd, zd);
xd *= 0.98f;
yd *= 0.98f;
zd *= 0.98f;
if (onGround)
{
xd *= 0.7f;
zd *= 0.7f;
yd *= -0.5f;
}
if (life-- <= 0)
{
remove();
if (!level->isClientSide)
{
explode();
}
}
else
{
level->addParticle(eParticleType_smoke, x, y + 0.5f, z, 0, 0, 0);
}
}
void PrimedTnt::explode()
{
float r = 4.0f;
level->explode(shared_from_this(), x, y, z, r, true);
}
void PrimedTnt::addAdditonalSaveData(CompoundTag *entityTag)
{
entityTag->putByte(L"Fuse", (byte) life);
}
void PrimedTnt::readAdditionalSaveData(CompoundTag *tag)
{
life = tag->getByte(L"Fuse");
}
float PrimedTnt::getShadowHeightOffs()
{
return 0;
}
shared_ptr<LivingEntity> PrimedTnt::getOwner()
{
return owner.lock();
}
|