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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.material.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.damagesource.h"
#include "com.mojang.nbt.h"
#include "JavaMath.h"
#include "SharedConstants.h"
#include "ExperienceOrb.h"
#include "SoundTypes.h"
const int ExperienceOrb::LIFETIME = 5 * 60 * SharedConstants::TICKS_PER_SECOND; // Five minutes!
void ExperienceOrb::_init()
{
tickCount = 0;
age = 0;
throwTime = 0;
health = 5;
value = 0;
followingPlayer = nullptr;
followingTime = 0;
}
ExperienceOrb::ExperienceOrb(Level *level, double x, double y, double z, int count) : Entity(level)
{
_init();
setSize(0.5f, 0.5f);
heightOffset = bbHeight / 2.0f;
setPos(x, y, z);
yRot = static_cast<float>(Math::random() * 360);
xd = static_cast<float>(Math::random() * 0.2f - 0.1f) * 2;
yd = static_cast<float>(Math::random() * 0.2) * 2;
zd = static_cast<float>(Math::random() * 0.2f - 0.1f) * 2;
value = count;
}
bool ExperienceOrb::makeStepSound()
{
return false;
}
ExperienceOrb::ExperienceOrb(Level *level) : Entity( level )
{
_init();
setSize(0.25f, 0.25f);
heightOffset = bbHeight / 2.0f;
}
void ExperienceOrb::defineSynchedData()
{
}
int ExperienceOrb::getLightColor(float a)
{
float l = 0.5f;
if (l < 0) l = 0;
if (l > 1) l = 1;
int br = Entity::getLightColor(a);
int br1 = (br) & 0xff;
int br2 = (br >> 16) & 0xff;
br1 += static_cast<int>(l * 15 * 16);
if (br1 > 15 * 16) br1 = 15 * 16;
// br2 = 15*16;
return br1 | br2 << 16;
}
void ExperienceOrb::tick()
{
Entity::tick();
if (throwTime > 0) throwTime--;
xo = x;
yo = y;
zo = z;
yd -= 0.03f;
if (level->getMaterial(Mth::floor(x), Mth::floor(y), Mth::floor(z)) == Material::lava)
{
yd = 0.2f;
xd = (random->nextFloat() - random->nextFloat()) * 0.2f;
zd = (random->nextFloat() - random->nextFloat()) * 0.2f;
playSound(eSoundType_RANDOM_FIZZ, 0.4f, 2.0f + random->nextFloat() * 0.4f);
}
checkInTile(x, (bb->y0 + bb->y1) / 2, z);
double maxDist = 8;
// 4J - PC Comment
// Usually exp orbs will get created at the same time so smoothen the lagspikes
if (followingTime < tickCount - SharedConstants::TICKS_PER_SECOND + (entityId % 100))
{
if (followingPlayer == nullptr || followingPlayer->distanceToSqr(shared_from_this()) > maxDist * maxDist)
{
followingPlayer = level->getNearestPlayer(shared_from_this(), maxDist);
}
followingTime = tickCount;
}
if (followingPlayer != nullptr)
{
double xdd = (followingPlayer->x - x) / maxDist;
double ydd = (followingPlayer->y + followingPlayer->getHeadHeight() - y) / maxDist;
double zdd = (followingPlayer->z - z) / maxDist;
double dd = sqrt(xdd * xdd + ydd * ydd + zdd * zdd);
double power = 1 - dd;
if (power > 0)
{
power = power * power;
xd += xdd / dd * power * 0.1;
yd += ydd / dd * power * 0.1;
zd += zdd / dd * power * 0.1;
}
}
move(xd, yd, zd);
float friction = 0.98f;
if (onGround)
{
friction = 0.6f * 0.98f;
int t = level->getTile(Mth::floor(x), Mth::floor(bb->y0) - 1, Mth::floor(z));
if (t > 0)
{
friction = Tile::tiles[t]->friction * 0.98f;
}
}
xd *= friction;
yd *= 0.98f;
zd *= friction;
if (onGround)
{
yd *= -0.9f;
}
tickCount++;
age++;
if (age >= LIFETIME)
{
remove();
}
}
bool ExperienceOrb::updateInWaterState()
{
return level->checkAndHandleWater(bb, Material::water, shared_from_this());
}
void ExperienceOrb::burn(int dmg)
{
hurt(DamageSource::inFire, dmg);
}
bool ExperienceOrb::hurt(DamageSource *source, float damage)
{
if (isInvulnerable()) return false;
markHurt();
health -= damage;
if (health <= 0)
{
remove();
}
return false;
}
void ExperienceOrb::addAdditonalSaveData(CompoundTag *entityTag)
{
entityTag->putShort(L"Health", static_cast<byte>(health));
entityTag->putShort(L"Age", static_cast<short>(age));
entityTag->putShort(L"Value", static_cast<short>(value));
}
void ExperienceOrb::readAdditionalSaveData(CompoundTag *tag)
{
health = tag->getShort(L"Health") & 0xff;
age = tag->getShort(L"Age");
value = tag->getShort(L"Value");
}
void ExperienceOrb::playerTouch(shared_ptr<Player> player)
{
if (level->isClientSide) return;
if (throwTime == 0 && player->takeXpDelay == 0)
{
player->takeXpDelay = 2;
// 4J - sound change brought forward from 1.2.3
playSound(eSoundType_RANDOM_ORB, 0.1f, 0.5f * ((random->nextFloat() - random->nextFloat()) * 0.7f + 1.8f));
player->take(shared_from_this(), 1);
player->increaseXp(value);
remove();
}
}
int ExperienceOrb::getValue()
{
return value;
}
int ExperienceOrb::getIcon()
{
if (value >= 2477)
{
return 10;
}
else if (value >= 1237)
{
return 9;
}
else if (value >= 617)
{
return 8;
}
else if (value >= 307)
{
return 7;
}
else if (value >= 149)
{
return 6;
}
else if (value >= 73)
{
return 5;
}
else if (value >= 37)
{
return 4;
}
else if (value >= 17)
{
return 3;
}
else if (value >= 7)
{
return 2;
}
else if (value >= 3)
{
return 1;
}
return 0;
}
/**
* Fetches the biggest possible experience orb value based on a maximum
* value. The current algorithm is next prime which is at least twice more
* than the previous one.
*
* @param maxValue
* @return
*/
int ExperienceOrb::getExperienceValue(int maxValue)
{
if (maxValue >= 2477)
{
return 2477;
}
else if (maxValue >= 1237)
{
return 1237;
}
else if (maxValue >= 617)
{
return 617;
}
else if (maxValue >= 307)
{
return 307;
}
else if (maxValue >= 149)
{
return 149;
}
else if (maxValue >= 73)
{
return 73;
}
else if (maxValue >= 37)
{
return 37;
}
else if (maxValue >= 17)
{
return 17;
}
else if (maxValue >= 7)
{
return 7;
}
else if (maxValue >= 3)
{
return 3;
}
return 1;
}
bool ExperienceOrb::isAttackable()
{
return false;
}
// 4J added
bool ExperienceOrb::shouldRender(Vec3 *c)
{
double xd = x - c->x;
double yd = y - c->y;
double zd = z - c->z;
double distance = xd * xd + yd * yd + zd * zd;
// 4J - don't render experience orbs that are less than 2 metres away, to try and avoid large particles that are causing us problems with photosensitivity testing - issues when you go
// near a large pile of experience orbs that all rush towards the near clip plane
if( distance < 4 ) return false;
return Entity::shouldRender(c);
}
|