Paper/src/main/java/net/minecraft/server/EntitySlime.java

249 Zeilen
7.4 KiB
Java

package net.minecraft.server;
import org.bukkit.event.entity.SlimeSplitEvent; // CraftBukkit
public class EntitySlime extends EntityLiving implements IMonster {
public float b;
2011-11-20 09:01:14 +01:00
public float c;
public float d;
private int jumpDelay = 0;
public EntitySlime(World world) {
super(world);
this.texture = "/mob/slime.png";
int i = 1 << this.random.nextInt(3);
this.height = 0.0F;
this.jumpDelay = this.random.nextInt(20) + 10;
this.setSize(i);
}
2012-07-29 09:33:13 +02:00
protected void a() {
super.a();
this.datawatcher.a(16, new Byte((byte) 1));
}
2012-11-06 13:05:28 +01:00
// CraftBukkit - protected -> public
public void setSize(int i) {
boolean updateMaxHealth = this.getMaxHealth() == this.maxHealth; // CraftBukkit
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);
this.setPosition(this.locX, this.locY, this.locZ);
// CraftBukkit start
if (updateMaxHealth) {
this.maxHealth = this.getMaxHealth();
}
this.setHealth(this.maxHealth);
// CraftBukkit end
2012-12-20 05:03:52 +01:00
this.bd = i;
2011-11-20 09:01:14 +01:00
}
public int getMaxHealth() {
int i = this.getSize();
return i * i;
}
public int getSize() {
return this.datawatcher.getByte(16);
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setInt("Size", this.getSize() - 1);
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.setSize(nbttagcompound.getInt("Size") + 1);
2011-11-20 09:01:14 +01:00
}
protected String h() {
2011-11-20 09:01:14 +01:00
return "slime";
}
protected String n() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
public void j_() {
2011-11-20 09:01:14 +01:00
if (!this.world.isStatic && this.world.difficulty == 0 && this.getSize() > 0) {
this.dead = true;
}
this.c += (this.b - this.c) * 0.5F;
this.d = this.c;
boolean flag = this.onGround;
super.j_();
2012-11-06 13:05:28 +01:00
int i;
if (this.onGround && !flag) {
2012-11-06 13:05:28 +01:00
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;
this.world.addParticle(this.h(), this.locX + (double) f2, this.boundingBox.b, this.locZ + (double) f3, 0.0D, 0.0D, 0.0D);
}
if (this.o()) {
2012-11-06 13:05:28 +01:00
this.makeSound(this.n(), this.aX(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
}
this.b = -0.5F;
2012-07-29 09:33:13 +02:00
} else if (!this.onGround && flag) {
this.b = 1.0F;
}
this.k();
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);
}
}
2012-11-06 13:05:28 +01:00
protected void bn() {
this.bk();
EntityHuman entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // CraftBukkit TODO: EntityTargetEvent
if (entityhuman != null) {
this.a(entityhuman, 10.0F, 20.0F);
}
if (this.onGround && this.jumpDelay-- <= 0) {
this.jumpDelay = this.j();
if (entityhuman != null) {
this.jumpDelay /= 3;
}
2012-12-20 05:03:52 +01:00
this.bF = true;
if (this.q()) {
2012-11-06 13:05:28 +01:00
this.makeSound(this.n(), this.aX(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
}
2012-12-20 05:03:52 +01:00
this.bC = 1.0F - this.random.nextFloat() * 2.0F;
this.bD = (float) (1 * this.getSize());
} else {
2012-12-20 05:03:52 +01:00
this.bF = false;
if (this.onGround) {
2012-12-20 05:03:52 +01:00
this.bC = this.bD = 0.0F;
}
}
}
protected void k() {
this.b *= 0.6F;
2011-11-20 09:01:14 +01:00
}
protected int j() {
2011-11-20 09:01:14 +01:00
return this.random.nextInt(20) + 10;
}
protected EntitySlime i() {
2011-11-20 09:01:14 +01:00
return new EntitySlime(this.world);
}
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);
// CraftBukkit start
SlimeSplitEvent event = new SlimeSplitEvent((org.bukkit.entity.Slime) this.getBukkitEntity(), j);
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;
}
// 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;
EntitySlime entityslime = this.i();
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, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason
2011-11-20 09:01:14 +01:00
}
}
super.die();
}
2012-11-06 13:05:28 +01:00
public void c_(EntityHuman entityhuman) {
if (this.l()) {
2011-11-20 09:01:14 +01:00
int i = this.getSize();
2012-11-06 13:05:28 +01:00
if (this.n(entityhuman) && this.e(entityhuman) < 0.6D * (double) i * 0.6D * (double) i && entityhuman.damageEntity(DamageSource.mobAttack(this), this.m())) {
this.makeSound("mob.attack", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2011-11-20 09:01:14 +01:00
}
}
}
protected boolean l() {
2011-11-20 09:01:14 +01:00
return this.getSize() > 1;
}
protected int m() {
2011-11-20 09:01:14 +01:00
return this.getSize();
}
2012-11-06 13:05:28 +01:00
protected String aZ() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
2012-11-06 13:05:28 +01:00
protected String ba() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
protected int getLootId() {
return this.getSize() == 1 ? Item.SLIME_BALL.id : 0;
}
public boolean canSpawn() {
Chunk chunk = this.world.getChunkAtWorldCoords(MathHelper.floor(this.locX), MathHelper.floor(this.locZ));
if (this.world.getWorldData().getType() == WorldType.FLAT && this.random.nextInt(4) != 1) {
return false;
} else {
if (this.getSize() == 1 || this.world.difficulty > 0) {
if (this.world.getBiome(MathHelper.floor(this.locX), MathHelper.floor(this.locZ)) == BiomeBase.SWAMPLAND && this.locY > 50.0D && this.locY < 70.0D && this.world.getLightLevel(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) <= this.random.nextInt(8)) {
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
}
2012-11-06 13:05:28 +01:00
protected float aX() {
2011-11-20 09:01:14 +01:00
return 0.4F * (float) this.getSize();
}
2012-11-06 13:05:28 +01:00
public int bp() {
2011-11-20 09:01:14 +01:00
return 0;
}
protected boolean q() {
return this.getSize() > 0;
}
protected boolean o() {
2011-11-20 09:01:14 +01:00
return this.getSize() > 2;
}
}