-
Notifications
You must be signed in to change notification settings - Fork 755
/
BlueSlime.java
568 lines (488 loc) · 17.4 KB
/
BlueSlime.java
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package tconstruct.entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import tconstruct.TConstruct;
import tconstruct.common.TRepo;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.ToolCore;
public class BlueSlime extends EntityLiving implements IMob, IBossDisplayData
{
private static final float[] field_100000_e = new float[] { 1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F };
public float sizeOffset;
public float sizeFactor;
public float sizeHeight;
/** the time between each jump of the slime */
protected int slimeJumpDelay = 0;
public BlueSlime(World world)
{
super(world);
// this.texture = "/mods/tinker/textures/mob/slimeedible.png";
int offset = this.rand.nextInt(299);
if (offset < 149)
offset = 1;
else if (offset < 298)
offset = 2;
else
offset = 3;
int size = 1 << offset;
this.yOffset = 0.0F;
this.slimeJumpDelay = this.rand.nextInt(120) + 40;
this.setSlimeSize(size);
this.jumpMovementFactor = 0.004F * size + 0.01F;
this.setHealth(getMaxHealthForSize());
}
protected void damageEntity (DamageSource damageSource, int damage)
{
if (damageSource.damageType.equals("arrow"))
damage = damage / 2;
super.damageEntity(damageSource, damage);
}
public String getEntityName ()
{
String s = EntityList.getEntityString(this);
if (s == null)
{
s = "generic";
}
if (getSlimeSize() >= 8)
s = "TConstruct.KingSlime";
return StatCollector.translateToLocal("entity." + s + ".name");
}
public IEntityLivingData onSpawnWithEgg (IEntityLivingData par1EntityLivingData)
{
Object par1EntityLivingData1 = super.onSpawnWithEgg(par1EntityLivingData);
if (getSlimeSize() == 2 && rand.nextInt(8) == 0)
{
EntitySkeleton entityskeleton = new EntitySkeleton(this.worldObj);
entityskeleton.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
entityskeleton.onSpawnWithEgg(par1EntityLivingData);
this.worldObj.spawnEntityInWorld(entityskeleton);
entityskeleton.mountEntity(this);
}
if (getSlimeSize() == 4 && rand.nextInt(12) == 0)
{
EntityCreeper creeper = new EntityCreeper(this.worldObj);
creeper.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
creeper.onSpawnWithEgg(par1EntityLivingData);
this.worldObj.spawnEntityInWorld(creeper);
creeper.mountEntity(this);
}
if (getSlimeSize() == 8)
{
for (int i = 0; i < 5; i++)
{
BlueSlime slime = new BlueSlime(this.worldObj);
slime.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
slime.onSpawnWithEgg(par1EntityLivingData);
this.worldObj.spawnEntityInWorld(slime);
}
BlueSlime slime = new BlueSlime(this.worldObj);
slime.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
slime.setSlimeSize(2);
this.worldObj.spawnEntityInWorld(slime);
EntitySkeleton skelton = new EntitySkeleton(this.worldObj);
skelton.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
skelton.onSpawnWithEgg(par1EntityLivingData);
this.worldObj.spawnEntityInWorld(skelton);
skelton.mountEntity(slime);
}
return (IEntityLivingData) par1EntityLivingData1;
}
@Override
public double getMountedYOffset ()
{
return this.height * 0.3;
}
public void jump ()
{
this.motionY = 0.05 * getSlimeSize() + 0.37;
if (this.isPotionActive(Potion.jump))
{
this.motionY += (double) ((float) (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
}
if (this.isSprinting())
{
float f = this.rotationYaw * 0.017453292F;
this.motionX -= (double) (MathHelper.sin(f) * 0.2F);
this.motionZ += (double) (MathHelper.cos(f) * 0.2F);
}
if (this.getBrightness(1.0F) > 0.9F && rand.nextInt(5) == 0
&& this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)))
{
int size = this.getSlimeSize() - 1;
if (size < 7)
{
if (size <= 0)
this.kill();
else
this.setSlimeSize(size);
}
}
this.isAirBorne = true;
ForgeHooks.onLivingJump(this);
}
protected void fall (float par1)
{
}
protected String getSlimeParticle ()
{
return "blueslime";
}
@Override
public boolean getCanSpawnHere ()
{
return isValidLightLevel() && this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty()
&& !this.worldObj.isAnyLiquid(this.boundingBox);
}
protected boolean isValidLightLevel ()
{
int x = MathHelper.floor_double(this.posX);
int y = MathHelper.floor_double(this.boundingBox.minY);
int z = MathHelper.floor_double(this.posZ);
if (y < 60 && rand.nextInt(5) != 0)
{
return false;
}
if (this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, x, y, z) > this.rand.nextInt(32))
{
return false;
}
else
{
int light = this.worldObj.getBlockLightValue(x, y, z);
if (this.worldObj.isThundering())
{
int i1 = this.worldObj.skylightSubtracted;
this.worldObj.skylightSubtracted = 10;
light = this.worldObj.getBlockLightValue(x, y, z);
this.worldObj.skylightSubtracted = i1;
}
return light <= this.rand.nextInt(8);
}
}
protected void entityInit ()
{
super.entityInit();
this.dataWatcher.addObject(16, new Byte((byte) 1));
}
public void setSlimeSize (int size)
{
this.dataWatcher.updateObject(16, new Byte((byte) size));
this.setSize(0.6F * (float) size, 0.6F * (float) size);
this.setPosition(this.posX, this.posY, this.posZ);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.getMaxHealth());
this.setHealth(this.getMaxHealth());
this.experienceValue = size + 2 ^ (size);
if (size >= 8)
this.experienceValue = 500;
}
// Invoked by constructor to set max health dependant on current size
private float getMaxHealthForSize ()
{
int i = this.getSlimeSize();
if (i == 1)
return 4;
if (i == 8)
return 100;
return (float) Math.min(i * i + 8, 49);
}
/**
* Returns the size of the slime.
*/
public int getSlimeSize ()
{
return this.dataWatcher.getWatchableObjectByte(16);
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT (NBTTagCompound par1NBTTagCompound)
{
super.writeEntityToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("Size", this.getSlimeSize() - 1);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT (NBTTagCompound par1NBTTagCompound)
{
super.readEntityFromNBT(par1NBTTagCompound);
this.setSlimeSize(par1NBTTagCompound.getInteger("Size") + 1);
// this.dataWatcher.updateObject(17, Integer.valueOf(this.health));
}
/**
* Returns the name of the sound played when the slime jumps.
*/
protected String getJumpSound ()
{
return "mob.slime." + (this.getSlimeSize() > 1 ? "big" : "small");
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate ()
{
if (!this.worldObj.isRemote && this.worldObj.difficultySetting == EnumDifficulty.PEACEFUL && this.getSlimeSize() > 0)
{
this.isDead = true;
}
this.sizeFactor += (this.sizeOffset - this.sizeFactor) * 0.5F;
this.sizeHeight = this.sizeFactor;
boolean flag = this.onGround;
super.onUpdate();
int i;
if (this.onGround && !flag)
{
i = this.getSlimeSize();
for (int j = 0; j < i * 8; ++j)
{
float f = this.rand.nextFloat() * (float) Math.PI * 2.0F;
float offset = this.rand.nextFloat() * 0.5F + 0.5F;
float xPos = MathHelper.sin(f) * (float) i * 0.5F * offset;
float zPos = MathHelper.cos(f) * (float) i * 0.5F * offset;
TConstruct.proxy.spawnParticle(this.getSlimeParticle(), this.posX + (double) xPos, this.boundingBox.minY, this.posZ + (double) zPos, 0.0D, 0.0D, 0.0D);
}
if (this.makesSoundOnLand())
{
this.playSound(this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) / 0.8F);
}
this.sizeOffset = -0.5F;
}
else if (!this.onGround && flag)
{
this.sizeOffset = 1.0F;
}
this.alterSquishAmount();
if (this.worldObj.isRemote)
{
i = this.getSlimeSize();
this.setSize(0.6F * (float) i, 0.6F * (float) i);
}
}
protected void updateEntityActionState ()
{
// Minecraft.getMinecraft().getLogAgent().logInfo("Collided with "+entity.getEntityName());
this.despawnEntity();
EntityPlayer entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D);
if (entityplayer != null)
{
this.faceEntity(entityplayer, 10.0F, 20.0F);
}
else if (this.onGround && this.slimeJumpDelay == 1)
{
this.rotationYaw = this.rotationYaw + rand.nextFloat() * 180 - 90;
if (rotationYaw > 360)
rotationYaw -= 360;
if (rotationYaw < 0)
rotationYaw += 360;
}
if (this.onGround && this.slimeJumpDelay-- <= 0)
{
this.slimeJumpDelay = this.getJumpDelay();
if (entityplayer != null)
{
this.slimeJumpDelay /= 12;
}
this.isJumping = true;
if (this.makesSoundOnJump())
{
this.playSound(this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F);
}
this.moveStrafing = 1.0F - this.rand.nextFloat() * 2.0F;
this.moveForward = (float) (1 * this.getSlimeSize());
}
else
{
this.isJumping = false;
if (this.onGround)
{
this.moveStrafing = this.moveForward = 0.0F;
}
}
}
public boolean handleWaterMovement ()
{
return false;
}
protected void alterSquishAmount ()
{
this.sizeOffset *= 0.6F;
}
/**
* Gets the amount of time the slime needs to wait between jumps.
*/
protected int getJumpDelay ()
{
return this.rand.nextInt(120) + 40;
}
protected BlueSlime createInstance ()
{
return new BlueSlime(this.worldObj);
}
/**
* Will get destroyed next tick.
*/
public void setDead ()
{
int size = this.getSlimeSize();
if (!this.worldObj.isRemote && size > 1 && this.getHealth() <= 0 && size < 8)
{
float f = (-0.5F) * (float) size / 4.0F;
float f1 = (-0.5F) * (float) size / 4.0F;
BlueSlime entityslime = this.createInstance();
entityslime.setSlimeSize(size / 2);
entityslime.setLocationAndAngles(this.posX + (double) f, this.posY + 0.5D, this.posZ + (double) f1, this.rand.nextFloat() * 360.0F, 0.0F);
this.worldObj.spawnEntityInWorld(entityslime);
}
super.setDead();
}
protected void dropFewItems (boolean par1, int par2)
{
int size = this.getSlimeSize();
Item j = this.getDropItem();
if (j != null && (rand.nextInt(2) == 0) || size >= 8)
{
int k = rand.nextInt(3) + rand.nextInt(this.getSlimeSize());
if (par2 > 0)
{
k += this.rand.nextInt(par2 + 1);
}
for (int l = 0; l < k; ++l)
{
this.entityDropItem(new ItemStack(j), 1);
}
}
if (size == 8)
{
ToolCore tool = getValidTool();
Item accessory = tool.getAccessoryItem();
ItemStack accessoryStack = accessory != null ? new ItemStack(tool.getAccessoryItem(), 1, 17) : null;
ItemStack toolStack = ToolBuilder.instance.buildTool(new ItemStack(tool.getHeadItem(), 1, 17), new ItemStack(tool.getHandleItem(), 1, 17), accessoryStack,
"King Slime " + tool.getToolName());
NBTTagCompound tags = toolStack.getTagCompound().getCompoundTag("InfiTool");
tags.setInteger("Attack", 3 + tool.getDamageVsEntity(null));
tags.setInteger("TotalDurability", 2500);
tags.setInteger("BaseDurability", 2500);
tags.setInteger("MiningSpeed", 1400);
this.entityDropItem(toolStack, 0f);
if (rand.nextInt(5) == 0)
{
ItemStack dropStack = new ItemStack(TRepo.heartCanister, 1, 1);
this.entityDropItem(dropStack, 0f);
}
}
}
ToolCore getValidTool ()
{
ToolCore tool = TConstructRegistry.tools.get(rand.nextInt(TConstructRegistry.tools.size()));
if (tool.getAccessoryItem() != null)
tool = getValidTool();
return tool;
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer (EntityPlayer par1EntityPlayer)
{
if (this.canDamagePlayer())
{
int i = this.getSlimeSize();
if (this.canEntityBeSeen(par1EntityPlayer) && this.getDistanceSqToEntity(par1EntityPlayer) < 0.6D * (double) i * 0.6D * (double) i
&& par1EntityPlayer.attackEntityFrom(DamageSource.causeMobDamage(this), this.getAttackStrength()))
{
this.playSound("mob.attack", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
}
}
}
/**
* Indicates weather the slime is able to damage the player (based upon the
* slime's size)
*/
protected boolean canDamagePlayer ()
{
return this.getSlimeSize() > 1;
}
/**
* Gets the amount of damage dealt to the player when "attacked" by the
* slime.
*/
protected int getAttackStrength ()
{
return this.getSlimeSize();
}
/**
* Returns the sound this mob makes when it is hurt.
*/
protected String getHurtSound ()
{
return "mob.slime." + (this.getSlimeSize() > 1 ? "big" : "small");
}
/**
* Returns the sound this mob makes on death.
*/
protected String getDeathSound ()
{
return "mob.slime." + (this.getSlimeSize() > 1 ? "big" : "small");
}
/**
* Returns the item ID for the item the mob drops on death.
*/
protected Item getDropItem ()
{
return TRepo.strangeFood;
}
/**
* Returns the volume for the sounds this mob makes.
*/
protected float getSoundVolume ()
{
return Math.min(0.05F * (float) this.getSlimeSize(), 0.3f);
}
/**
* The speed it takes to move the entityliving's rotationPitch through the
* faceEntity method. This is only currently use in wolves.
*/
public int getVerticalFaceSpeed ()
{
return 0;
}
/**
* Returns true if the slime makes a sound when it jumps (based upon the
* slime's size)
*/
protected boolean makesSoundOnJump ()
{
return this.getSlimeSize() > 0;
}
/**
* Returns true if the slime makes a sound when it lands after a jump (based
* upon the slime's size)
*/
protected boolean makesSoundOnLand ()
{
return this.getSlimeSize() > 2;
}
/*
* @Override public int getBossHealth () { return
* this.dataWatcher.getWatchableObjectInt(17); }
*/
}