2011-10-01 01:50:19 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2013-03-29 02:43:19 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
2013-07-01 13:03:00 +02:00
|
|
|
import org.bukkit.event.entity.SlimeSplitEvent;
|
2013-03-29 02:43:19 +01:00
|
|
|
// CraftBukkit end
|
2012-07-22 08:18:00 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public class EntitySlime extends EntityInsentient implements IMonster {
|
2011-10-01 01:50:19 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public float h;
|
|
|
|
public float i;
|
|
|
|
public float j;
|
|
|
|
private int jumpDelay;
|
2013-03-29 02:43:19 +01:00
|
|
|
private Entity lastTarget; // CraftBukkit
|
2011-10-01 01:50:19 +02:00
|
|
|
|
|
|
|
public EntitySlime(World world) {
|
|
|
|
super(world);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected void c() {
|
|
|
|
super.c();
|
2011-10-01 01:50:19 +02:00
|
|
|
this.datawatcher.a(16, new Byte((byte) 1));
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
// CraftBukkit - protected -> public
|
2011-10-01 01:50:19 +02:00
|
|
|
public void setSize(int i) {
|
|
|
|
this.datawatcher.watch(16, new Byte((byte) i));
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(0.6F * (float) i, 0.6F * (float) i);
|
2011-10-01 01:50:19 +02:00
|
|
|
this.setPosition(this.locX, this.locY, this.locZ);
|
2013-07-09 01:43:37 +02:00
|
|
|
this.getAttributeInstance(GenericAttributes.a).setValue((double) (i * i));
|
2013-07-02 19:34:40 +02:00
|
|
|
this.setHealth(this.getMaxHealth());
|
2013-07-01 13:03:00 +02:00
|
|
|
this.b = 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
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected String bN() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return "slime";
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected String bT() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public void h() {
|
|
|
|
if (!this.world.isStatic && this.world.difficulty == EnumDifficulty.PEACEFUL && this.getSize() > 0) {
|
2011-11-20 09:01:14 +01:00
|
|
|
this.dead = true;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.i += (this.h - this.i) * 0.5F;
|
|
|
|
this.j = this.i;
|
2011-10-01 01:50:19 +02:00
|
|
|
boolean flag = this.onGround;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
super.h();
|
2012-11-06 13:05:28 +01:00
|
|
|
int i;
|
|
|
|
|
2011-10-01 01:50:19 +02:00
|
|
|
if (this.onGround && !flag) {
|
2012-11-06 13:05:28 +01:00
|
|
|
i = this.getSize();
|
2011-10-01 01:50:19 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
this.world.addParticle(this.bN(), 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
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.bU()) {
|
|
|
|
this.makeSound(this.bT(), this.bf(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.h = -0.5F;
|
2012-07-29 09:33:13 +02:00
|
|
|
} else if (!this.onGround && flag) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.h = 1.0F;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
this.bQ();
|
2012-11-06 13:05:28 +01:00
|
|
|
if (this.world.isStatic) {
|
|
|
|
i = this.getSize();
|
|
|
|
this.a(0.6F * (float) i, 0.6F * (float) i);
|
|
|
|
}
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected void bq() {
|
|
|
|
this.w();
|
2013-03-29 02:43:19 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
Entity entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // EntityHuman -> Entity
|
|
|
|
EntityTargetEvent event = null;
|
|
|
|
|
|
|
|
if (entityhuman != null && !entityhuman.equals(lastTarget)) {
|
|
|
|
event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
|
|
|
|
} else if (lastTarget != null && entityhuman == null) {
|
|
|
|
event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.FORGOT_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event != null && !event.isCancelled()) {
|
|
|
|
entityhuman = event.getTarget() == null ? null : ((CraftEntity) event.getTarget()).getHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lastTarget = entityhuman;
|
|
|
|
// CraftBukkit end
|
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) {
|
2013-11-04 14:07:38 +01:00
|
|
|
this.jumpDelay = this.bP();
|
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
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bd = true;
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.bW()) {
|
|
|
|
this.makeSound(this.bT(), this.bf(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
this.be = 1.0F - this.random.nextFloat() * 2.0F;
|
|
|
|
this.bf = (float) (1 * this.getSize());
|
2011-10-01 01:50:19 +02:00
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.bd = false;
|
2011-10-01 01:50:19 +02:00
|
|
|
if (this.onGround) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.be = this.bf = 0.0F;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected void bQ() {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.h *= 0.6F;
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected int bP() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.random.nextInt(20) + 10;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected EntitySlime bO() {
|
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();
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (!this.world.isStatic && i > 1 && this.getHealth() <= 0.0F) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int j = 2 + this.random.nextInt(3);
|
|
|
|
|
2011-10-01 01:50:19 +02:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
SlimeSplitEvent event = new SlimeSplitEvent((org.bukkit.entity.Slime) 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;
|
2013-11-04 14:07:38 +01:00
|
|
|
EntitySlime entityslime = this.bO();
|
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);
|
2012-04-14 08:38:22 +02:00
|
|
|
this.world.addEntity(entityslime, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
super.die();
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void b_(EntityHuman entityhuman) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.bR()) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int i = this.getSize();
|
2011-10-01 01:50:19 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.o(entityhuman) && this.e(entityhuman) < 0.6D * (double) i * 0.6D * (double) i && entityhuman.damageEntity(DamageSource.mobAttack(this), (float) this.bS())) {
|
2012-11-06 13:05:28 +01:00
|
|
|
this.makeSound("mob.attack", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected boolean bR() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize() > 1;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected int bS() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize();
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected String aT() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected String aU() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected Item getLoot() {
|
|
|
|
return this.getSize() == 1 ? Items.SLIME_BALL : Item.d(0);
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public boolean canSpawn() {
|
2011-10-01 01:50:19 +02:00
|
|
|
Chunk chunk = this.world.getChunkAtWorldCoords(MathHelper.floor(this.locX), MathHelper.floor(this.locZ));
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.world.getWorldData().getType() == WorldType.FLAT && this.random.nextInt(4) != 1) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.getSize() == 1 || this.world.difficulty != EnumDifficulty.PEACEFUL) {
|
2013-03-13 23:33:27 +01:00
|
|
|
BiomeBase biomebase = this.world.getBiome(MathHelper.floor(this.locX), MathHelper.floor(this.locZ));
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (biomebase == BiomeBase.SWAMPLAND && this.locY > 50.0D && this.locY < 70.0D && this.random.nextFloat() < 0.5F && this.random.nextFloat() < this.world.x() && this.world.getLightLevel(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) <= this.random.nextInt(8)) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return super.canSpawn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.random.nextInt(10) == 0 && chunk.a(987234911L).nextInt(10) == 0 && this.locY < 40.0D) {
|
|
|
|
return super.canSpawn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected float bf() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return 0.4F * (float) this.getSize();
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public int x() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected boolean bW() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.getSize() > 0;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected boolean bU() {
|
2011-11-20 09:01:14 +01:00
|
|
|
return this.getSize() > 2;
|
2011-10-01 01:50:19 +02:00
|
|
|
}
|
|
|
|
}
|