2011-10-01 01:50:19 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
public class EntitySlime extends EntityLiving implements IMonster {
|
|
|
|
|
|
|
|
public float a;
|
|
|
|
public float b;
|
2011-11-20 09:01:14 +01:00
|
|
|
public float c;
|
2011-11-30 00:17:43 +01:00
|
|
|
private int jumpDelay = 0;
|
2011-10-01 01:50:19 +02:00
|
|
|
|
|
|
|
public EntitySlime(World world) {
|
|
|
|
super(world);
|
|
|
|
this.texture = "/mob/slime.png";
|
|
|
|
int i = 1 << this.random.nextInt(3);
|
|
|
|
|
|
|
|
this.height = 0.0F;
|
2011-11-30 00:17:43 +01:00
|
|
|
this.jumpDelay = this.random.nextInt(20) + 10;
|
2011-10-01 01:50:19 +02:00
|
|
|
this.setSize(i);
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aA = i;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void b() {
|
|
|
|
super.b();
|
|
|
|
this.datawatcher.a(16, new Byte((byte) 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSize(int i) {
|
|
|
|
this.datawatcher.watch(16, new Byte((byte) i));
|
|
|
|
this.b(0.6F * (float) i, 0.6F * (float) i);
|
|
|
|
this.setPosition(this.locX, this.locY, this.locZ);
|
2011-11-20 09:01:14 +01:00
|
|
|
this.setHealth(this.getMaxHealth());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxHealth() {
|
|
|
|
int i = this.getSize();
|
|
|
|
|
|
|
|
return i * i;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getSize() {
|
|
|
|
return this.datawatcher.getByte(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setInt("Size", this.getSize() - 1);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
2011-11-30 00:17:43 +01:00
|
|
|
this.setSize(nbttagcompound.getInt("Size") + 1);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected String v() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return "slime";
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected String F() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return "mob.slime";
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public void y_() {
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!this.world.isStatic && this.world.difficulty == 0 && this.getSize() > 0) {
|
|
|
|
this.dead = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.b += (this.a - this.b) * 0.5F;
|
|
|
|
this.c = this.b;
|
2011-10-01 01:50:19 +02:00
|
|
|
boolean flag = this.onGround;
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
super.y_();
|
2011-10-01 01:50:19 +02:00
|
|
|
if (this.onGround && !flag) {
|
|
|
|
int i = this.getSize();
|
|
|
|
|
|
|
|
for (int j = 0; j < i * 8; ++j) {
|
|
|
|
float f = this.random.nextFloat() * 3.1415927F * 2.0F;
|
|
|
|
float f1 = this.random.nextFloat() * 0.5F + 0.5F;
|
|
|
|
float f2 = MathHelper.sin(f) * (float) i * 0.5F * f1;
|
|
|
|
float f3 = MathHelper.cos(f) * (float) i * 0.5F * f1;
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
this.world.a(this.v(), this.locX + (double) f2, this.boundingBox.b, this.locZ + (double) f3, 0.0D, 0.0D, 0.0D);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
if (this.H()) {
|
|
|
|
this.world.makeSound(this, this.F(), this.o(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.a = -0.5F;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
this.C();
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected void m_() {
|
2012-01-12 23:10:13 +01:00
|
|
|
this.au();
|
2011-11-30 00:17:43 +01:00
|
|
|
EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D);
|
2011-10-01 01:50:19 +02:00
|
|
|
|
|
|
|
if (entityhuman != null) {
|
|
|
|
this.a(entityhuman, 10.0F, 20.0F);
|
|
|
|
}
|
|
|
|
|
2011-11-30 00:17:43 +01:00
|
|
|
if (this.onGround && this.jumpDelay-- <= 0) {
|
2012-01-12 23:10:13 +01:00
|
|
|
this.jumpDelay = this.B();
|
2011-10-01 01:50:19 +02:00
|
|
|
if (entityhuman != null) {
|
2011-11-30 00:17:43 +01:00
|
|
|
this.jumpDelay /= 3;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aZ = true;
|
|
|
|
if (this.J()) {
|
|
|
|
this.world.makeSound(this, this.F(), this.o(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.a = 1.0F;
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aW = 1.0F - this.random.nextFloat() * 2.0F;
|
|
|
|
this.aX = (float) (1 * this.getSize());
|
2011-10-01 01:50:19 +02:00
|
|
|
} else {
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aZ = false;
|
2011-10-01 01:50:19 +02:00
|
|
|
if (this.onGround) {
|
2012-01-12 23:10:13 +01:00
|
|
|
this.aW = this.aX = 0.0F;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected void C() {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.a *= 0.6F;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected int B() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.random.nextInt(20) + 10;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected EntitySlime z() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return new EntitySlime(this.world);
|
|
|
|
}
|
|
|
|
|
2011-10-01 01:50:19 +02:00
|
|
|
public void die() {
|
|
|
|
int i = this.getSize();
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!this.world.isStatic && i > 1 && this.getHealth() <= 0) {
|
|
|
|
int j = 2 + this.random.nextInt(3);
|
|
|
|
|
2011-10-01 01:50:19 +02:00
|
|
|
// CraftBukkit start
|
2011-11-20 09:01:14 +01:00
|
|
|
org.bukkit.event.entity.SlimeSplitEvent event = new org.bukkit.event.entity.SlimeSplitEvent(this.getBukkitEntity(), j);
|
2011-10-01 01:50:19 +02:00
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled() && event.getCount() > 0) {
|
2011-11-20 09:01:14 +01:00
|
|
|
j = event.getCount();
|
|
|
|
} else {
|
|
|
|
super.die();
|
|
|
|
return;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
for (int k = 0; k < j; ++k) {
|
|
|
|
float f = ((float) (k % 2) - 0.5F) * (float) i / 4.0F;
|
|
|
|
float f1 = ((float) (k / 2) - 0.5F) * (float) i / 4.0F;
|
2012-01-12 23:10:13 +01:00
|
|
|
EntitySlime entityslime = this.z();
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
entityslime.setSize(i / 2);
|
|
|
|
entityslime.setPositionRotation(this.locX + (double) f, this.locY + 0.5D, this.locZ + (double) f1, this.random.nextFloat() * 360.0F, 0.0F);
|
|
|
|
this.world.addEntity(entityslime);
|
|
|
|
}
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
super.die();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a_(EntityHuman entityhuman) {
|
2012-01-12 23:10:13 +01:00
|
|
|
if (this.D()) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int i = this.getSize();
|
2011-10-01 01:50:19 +02:00
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
if (this.g(entityhuman) && (double) this.h(entityhuman) < 0.6D * (double) i && entityhuman.damageEntity(DamageSource.mobAttack(this), this.E())) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.world.makeSound(this, "mob.slimeattack", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
|
|
|
|
}
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected boolean D() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize() > 1;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected int E() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String m() {
|
2011-10-01 01:50:19 +02:00
|
|
|
return "mob.slime";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected String n() {
|
2011-10-01 01:50:19 +02:00
|
|
|
return "mob.slime";
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
protected int e() {
|
2011-10-01 01:50:19 +02:00
|
|
|
return this.getSize() == 1 ? Item.SLIME_BALL.id : 0;
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
public boolean g() {
|
2011-10-01 01:50:19 +02:00
|
|
|
Chunk chunk = this.world.getChunkAtWorldCoords(MathHelper.floor(this.locX), MathHelper.floor(this.locZ));
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
return (this.getSize() == 1 || this.world.difficulty > 0) && this.random.nextInt(10) == 0 && chunk.a(987234911L).nextInt(10) == 0 && this.locY < 40.0D ? super.g() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float o() {
|
|
|
|
return 0.4F * (float) this.getSize();
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public int x() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected boolean J() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize() > 1;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
protected boolean H() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize() > 2;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|