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
|
#include "stdafx.h"
#include "net.minecraft.world.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.storage.h"
#include "net.minecraft.world.level.chunk.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.ai.attributes.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.monster.h"
#include "net.minecraft.world.damagesource.h"
#include "com.mojang.nbt.h"
#include "Slime.h"
#include "..\Minecraft.Client\Textures.h"
#include "SoundTypes.h"
void Slime::_init()
{
jumpDelay = 0;
targetSquish = 0;
squish = 0;
oSquish = 0;
}
Slime::Slime(Level *level) : Mob( 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();
registerAttributes();
setHealth(getMaxHealth());
_init();
int size = 1 << (random->nextInt(3));
heightOffset = 0;
jumpDelay = random->nextInt(20) + 10;
setSize(size);
}
void Slime::defineSynchedData()
{
Mob::defineSynchedData();
entityData->define(ID_SIZE, (byte) 1);
}
void Slime::setSize(int size)
{
entityData->set(ID_SIZE, (byte) size);
setSize(0.6f * size, 0.6f * size);
setPos(x, y, z);
getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(size * size);
setHealth(getMaxHealth());
xpReward = size;
}
int Slime::getSize()
{
return entityData->getByte(ID_SIZE);
}
void Slime::addAdditonalSaveData(CompoundTag *tag)
{
Mob::addAdditonalSaveData(tag);
tag->putInt(L"Size", getSize() - 1);
}
void Slime::readAdditionalSaveData(CompoundTag *tag)
{
Mob::readAdditionalSaveData(tag);
setSize(tag->getInt(L"Size") + 1);
}
ePARTICLE_TYPE Slime::getParticleName()
{
return eParticleType_slime;
}
int Slime::getSquishSound()
{
return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME_SMALL;
}
void Slime::tick()
{
if (!level->isClientSide && level->difficulty == Difficulty::PEACEFUL && getSize() > 0)
{
removed = true;
}
squish = squish + (targetSquish - squish) * .5f;
oSquish = squish;
bool wasOnGround = onGround;
Mob::tick();
if (onGround && !wasOnGround)
{
int size = getSize();
for (int i = 0; i < size * 8; i++)
{
float dir = random->nextFloat() * PI * 2;
float d = random->nextFloat() * 0.5f + 0.5f;
float xd = Mth::sin(dir) * size * 0.5f * d;
float zd = Mth::cos(dir) * size * 0.5f * d;
level->addParticle(getParticleName(), x + xd, bb->y0, z + zd, 0, 0, 0);
}
if (doPlayLandSound())
{
playSound(getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) / 0.8f);
}
targetSquish = -0.5f;
}
// 4J Stu - Brought forward from 1.3 in TU7 to fix lava slime render
else if (!onGround && wasOnGround)
{
targetSquish = 1;
}
decreaseSquish();
if (level->isClientSide)
{
int size = getSize();
setSize(0.6f * size, 0.6f * size);
}
}
void Slime::serverAiStep()
{
checkDespawn();
shared_ptr<Player> player = level->getNearestAttackablePlayer(shared_from_this(), 16);
if (player != NULL)
{
lookAt(player, 10, 20);
}
if (onGround && jumpDelay-- <= 0)
{
jumpDelay = getJumpDelay();
if (player != NULL)
{
jumpDelay /= 3;
}
jumping = true;
if (doPlayJumpSound())
{
playSound(getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 0.8f);
}
// 4J Removed TU7 to bring forward change to fix lava slime render in MP
//targetSquish = 1;
xxa = 1 - random->nextFloat() * 2;
yya = (float) 1 * getSize();
}
else
{
jumping = false;
if (onGround)
{
xxa = yya = 0;
}
}
}
void Slime::decreaseSquish()
{
targetSquish = targetSquish * 0.6f;
}
int Slime::getJumpDelay()
{
return random->nextInt(20) + 10;
}
shared_ptr<Slime> Slime::createChild()
{
return shared_ptr<Slime>( new Slime(level) );
}
void Slime::remove()
{
int size = getSize();
if (!level->isClientSide && size > 1 && getHealth() <= 0)
{
int count = 2 + random->nextInt(3);
for (int i = 0; i < count; i++)
{
// The mob spawner can currently make a maximum of 25 slimes (limited to 50% of the total amount of monsters which is 50)
// and so limit to slightly more than this so we have some head room to make a few spawned children. Also always create at least one
// new slime since we are getting rid of this one anyway.
if( i == 0 || level->countInstanceOf( eTYPE_SLIME, true) < 35 )
{
float xd = (i % 2 - 0.5f) * size / 4.0f;
float zd = (i / 2 - 0.5f) * size / 4.0f;
shared_ptr<Slime> slime = createChild();
slime->setSize(size / 2);
slime->moveTo(x + xd, y + 0.5, z + zd, random->nextFloat() * 360, 0);
level->addEntity(slime);
}
}
}
Mob::remove();
}
void Slime::playerTouch(shared_ptr<Player> player)
{
if (isDealsDamage())
{
int size = getSize();
if (canSee(player) && distanceToSqr(player) < (0.6 * size) * (0.6 * size))
{
DamageSource *damageSource = DamageSource::mobAttack( dynamic_pointer_cast<Mob>( shared_from_this() ) );
if (player->hurt(damageSource, getAttackDamage()))
{
playSound(eSoundType_MOB_SLIME_ATTACK, 1, (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f);
}
delete damageSource;
}
}
}
bool Slime::isDealsDamage()
{
return getSize() > 1;
}
int Slime::getAttackDamage()
{
return getSize();
}
int Slime::getHurtSound()
{
return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME_SMALL;
}
int Slime::getDeathSound()
{
return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME_SMALL;
}
int Slime::getDeathLoot()
{
if (getSize() == 1) return Item::slimeBall->id;
return 0;
}
bool Slime::canSpawn()
{
LevelChunk *lc = level->getChunkAt( Mth::floor(x), Mth::floor(z));
if (level->getLevelData()->getGenerator() == LevelType::lvl_flat && random->nextInt(4) != 1)
{
return false;
}
Random *lcr = lc->getRandom(987234911l); // 4J - separated out so we can delete
if ((getSize() == 1 || level->difficulty > Difficulty::PEACEFUL))
{
// spawn slime in swamplands at night
Biome *biome = level->getBiome(Mth::floor(x), Mth::floor(z));
if (biome == Biome::swampland && y > 50 && y < 70 && random->nextFloat() < 0.5f)
{
if (random->nextFloat() < level->getMoonBrightness() && level->getRawBrightness(Mth::floor(x), Mth::floor(y), Mth::floor(z)) <= random->nextInt(8))
{
return Mob::canSpawn();
}
}
if (random->nextInt(10) == 0 && lcr->nextInt(10) == 0 && y < 40)
{
return Mob::canSpawn();
}
}
delete lcr;
return false;
}
float Slime::getSoundVolume()
{
return 0.4f * getSize();
}
int Slime::getMaxHeadXRot()
{
return 0;
}
bool Slime::doPlayJumpSound()
{
return getSize() > 0;
}
bool Slime::doPlayLandSound()
{
return getSize() > 2;
}
|