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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
#include "stdafx.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.item.h"
#include "SharedConstants.h"
#include "JavaMath.h"
#include "EyeOfEnderSignal.h"
void EyeOfEnderSignal::_init()
{
// 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();
// Initialisors
shakeTime = 0;
tx = ty = tz = 0.0;
life = 0;
surviveAfterDeath = false;
}
EyeOfEnderSignal::EyeOfEnderSignal(Level *level) : Entity(level)
{
_init();
setSize(0.25f, 0.25f);
}
void EyeOfEnderSignal::defineSynchedData()
{
}
bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance)
{
double size = bb->getSize() * 4;
size *= 64.0f;
return distance < size * size;
}
EyeOfEnderSignal::EyeOfEnderSignal(Level *level, double x, double y, double z) : Entity(level)
{
_init();
life = 0;
setSize(0.25f, 0.25f);
setPos(x, y, z);
heightOffset = 0;
}
void EyeOfEnderSignal::signalTo(double tx, int ty, double tz)
{
double dx = tx - x, dz = tz - z;
float dist = sqrt(dx * dx + dz * dz);
if (dist > 12)
{
this->tx = x + (dx / dist) * 12;
this->tz = z + (dz / dist) * 12;
this->ty = y + 8;
}
else
{
this->tx = tx;
this->ty = ty;
this->tz = tz;
}
life = 0;
surviveAfterDeath = random->nextInt(5) > 0;
}
void EyeOfEnderSignal::lerpMotion(double xd, double yd, double zd)
{
this->xd = xd;
this->yd = yd;
this->zd = zd;
if (xRotO == 0 && yRotO == 0)
{
float sd = (float) sqrt(xd * xd + zd * zd);
yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI);
xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI);
}
}
void EyeOfEnderSignal::tick()
{
xOld = x;
yOld = y;
zOld = z;
Entity::tick();
x += xd;
y += yd;
z += zd;
float sd = (float) sqrt(xd * xd + zd * zd);
yRot = (float) (atan2(xd, zd) * 180 / PI);
xRot = (float) (atan2(yd, (double)sd) * 180 / PI);
while (xRot - xRotO < -180)
xRotO -= 360;
while (xRot - xRotO >= 180)
xRotO += 360;
while (yRot - yRotO < -180)
yRotO -= 360;
while (yRot - yRotO >= 180)
yRotO += 360;
xRot = xRotO + (xRot - xRotO) * 0.2f;
yRot = yRotO + (yRot - yRotO) * 0.2f;
if (!level->isClientSide)
{
double dx = tx - x, dz = tz - z;
float tdist = (float) sqrt(dx * dx + dz * dz);
float angle = (float) atan2(dz, dx);
double tspeed = (sd + (tdist - sd) * .0025);
if (tdist < 1)
{
tspeed *= .8;
yd *= .8;
}
xd = cos(angle) * tspeed;
zd = sin(angle) * tspeed;
if (y < ty)
{
yd = yd + (1 - yd) * .015f;
}
else
{
yd = yd + (-1 - yd) * .015f;
}
}
float s = 1 / 4.0f;
if (isInWater())
{
for (int i = 0; i < 4; i++)
{
level->addParticle(eParticleType_bubble, x - xd * s, y - yd * s, z - zd * s, xd, yd, zd);
}
}
else
{
level->addParticle(eParticleType_ender, x - xd * s + random->nextDouble() * .6 - .3, y - yd * s - .5, z - zd * s + random->nextDouble() * .6 - .3, xd, yd, zd);
}
if (!level->isClientSide)
{
setPos(x, y, z);
life++;
if (life > SharedConstants::TICKS_PER_SECOND * 4 && !level->isClientSide)
{
remove();
if (surviveAfterDeath)
{
level->addEntity(shared_ptr<ItemEntity>( new ItemEntity(level, x, y, z, shared_ptr<ItemInstance>(new ItemInstance(Item::eyeOfEnder)))));
}
else
{
level->levelEvent(LevelEvent::PARTICLES_EYE_OF_ENDER_DEATH, (int) Math::round(x), (int) Math::round(y), (int) Math::round(z), 0);
}
}
}
}
void EyeOfEnderSignal::addAdditonalSaveData(CompoundTag *tag)
{
}
void EyeOfEnderSignal::readAdditionalSaveData(CompoundTag *tag)
{
}
float EyeOfEnderSignal::getShadowHeightOffs()
{
return 0;
}
float EyeOfEnderSignal::getBrightness(float a)
{
return 1.0f;
}
int EyeOfEnderSignal::getLightColor(float a)
{
return 15 << 20 | 15 << 4;
}
bool EyeOfEnderSignal::isAttackable()
{
return false;
}
|