
net.minecraft.server.EntitySlime Maven / Gradle / Ivy
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.entity.Slime;
import org.bukkit.event.entity.SlimeSplitEvent;
import org.jetbrains.annotations.NotNull;
// CraftBukkit end
public class EntitySlime extends EntityInsentient implements IMonster {
public float a;
public float b;
public float c;
private boolean bk;
public EntitySlime(World world) {
super(world);
this.moveController = new EntitySlime.ControllerMoveSlime(this);
this.goalSelector.addTask(1, new EntitySlime.PathfinderGoalSlimeRandomJump(this));
this.goalSelector.addTask(2, new EntitySlime.PathfinderGoalSlimeNearestPlayer(this));
this.goalSelector.addTask(3, new EntitySlime.PathfinderGoalSlimeRandomDirection(this));
this.goalSelector.addTask(5, new EntitySlime.PathfinderGoalSlimeIdle(this));
this.targetSelector.addTask(1, new PathfinderGoalTargetNearestPlayer(this));
this.targetSelector.addTask(3, new PathfinderGoalNearestAttackableTargetInsentient(this, EntityIronGolem.class));
}
protected void entityInit() {
super.entityInit();
this.datawatcher.a(16, (byte) 1);
}
@NotNull
@Override
public Slime getEntityBukkit() {
return (Slime) super.getEntityBukkit();
}
public int getSize() {
return this.datawatcher.getByte(16);
}
public void setSize(int i) {
this.datawatcher.watch(16, (byte) i);
this.setSize(0.51000005F * (float) i, 0.51000005F * (float) i);
this.setPosition(this.locX, this.locY, this.locZ);
this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(i * i);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.2F + 0.1F * (float) i);
this.setHealth(this.getMaxHealth());
this.experienceValue = i;
}
public void saveEntityData(NBTTagCompound tag) {
super.saveEntityData(tag);
tag.setInt("Size", this.getSize() - 1);
tag.setBoolean("wasOnGround", this.bk);
}
public void loadEntityData(NBTTagCompound tag) {
super.loadEntityData(tag);
int i = tag.getInt("Size");
if (i < 0) {
i = 0;
}
this.setSize(i + 1);
this.bk = tag.getBoolean("wasOnGround");
}
protected EnumParticle n() {
return EnumParticle.SLIME;
}
protected String ck() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
public void onUpdate() {
if (!this.world.isClientSide && this.world.getDifficulty() == EnumDifficulty.PEACEFUL && this.getSize() > 0) {
this.dead = true;
}
this.b += (this.a - this.b) * 0.5F;
this.c = this.b;
super.onUpdate();
if (this.onGround && !this.bk) {
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;
World world = this.world;
EnumParticle enumparticle = this.n();
double d0 = this.locX + (double) f2;
double d1 = this.locZ + (double) f3;
world.addParticle(enumparticle, d0, this.getBoundingBox().b, d1, 0.0D, 0.0D, 0.0D);
}
if (this.cl()) {
this.playSound(this.ck(), this.getSoundVolume(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) / 0.8F);
}
this.a = -0.5F;
} else if (!this.onGround && this.bk) {
this.a = 1.0F;
}
this.bk = this.onGround;
this.ch();
}
protected void ch() {
this.a *= 0.6F;
}
protected int cg() {
return this.random.nextInt(20) + 10;
}
protected EntitySlime cf() {
return new EntitySlime(this.world);
}
public void onDataWatcherUpdate(int i) {
if (i == 16) {
int j = this.getSize();
this.setSize(0.51000005F * (float) j, 0.51000005F * (float) j);
this.yaw = this.rotationYawHead;
this.renderYawOffset = this.rotationYawHead;
if (this.isInWater() && this.random.nextInt(20) == 0) {
this.resetHeight();
}
}
super.onDataWatcherUpdate(i);
}
public void die() {
int i = this.getSize();
if (!this.world.isClientSide && i > 1 && this.getHealth() <= 0.0F) {
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) {
j = event.getCount();
} else {
super.die();
return;
}
// CraftBukkit end
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.cf();
if (this.hasCustomName()) {
entityslime.setCustomName(this.getCustomName());
}
if (this.isPersistent()) {
entityslime.enablePersistence();
}
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
}
}
super.die();
}
public void applyEntityCollision(Entity entity) {
super.applyEntityCollision(entity);
if (entity instanceof EntityIronGolem && this.ci()) {
this.e((EntityLiving) entity);
}
}
public void onCollideWithPlayer(EntityHuman entityhuman) {
if (this.ci()) {
this.e((EntityLiving) entityhuman);
}
}
protected void e(EntityLiving entityliving) {
int i = this.getSize();
if (this.hasLineOfSight(entityliving) && this.getDistanceSquaredToEntity(entityliving) < 0.6D * (double) i * 0.6D * (double) i && entityliving.damageEntity(DamageSource.mobAttack(this), (float) this.cj())) {
this.playSound("mob.attack", 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
this.applyEnchantments(this, entityliving);
}
}
public float getHeadHeight() {
return 0.625F * this.length;
}
protected boolean ci() {
return this.getSize() > 1;
}
protected int cj() {
return this.getSize();
}
protected String getHurtSound() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
protected String getDeathSound() {
return "mob.slime." + (this.getSize() > 1 ? "big" : "small");
}
protected Item getLoot() {
return this.getSize() == 1 ? Items.SLIME : null;
}
public boolean getCanSpawnHere() {
BlockPosition blockposition = new BlockPosition(MathHelper.floor(this.locX), 0, MathHelper.floor(this.locZ));
Chunk chunk = this.world.getChunkAtWorldCoords(blockposition);
if (this.world.getWorldData().getType() == WorldType.FLAT && this.random.nextInt(4) != 1) {
return false;
} else {
if (this.world.getDifficulty() != EnumDifficulty.PEACEFUL) {
BiomeBase biomebase = this.world.getBiome(blockposition);
if (biomebase == BiomeBase.SWAMPLAND && this.locY > 50.0D && this.locY < 70.0D && this.random.nextFloat() < 0.5F && this.random.nextFloat() < this.world.y() && this.world.getLightLevel(new BlockPosition(this)) <= this.random.nextInt(8)) {
return super.getCanSpawnHere();
}
if (this.random.nextInt(10) == 0 && chunk.a(987234911L).nextInt(10) == 0 && this.locY < 40.0D) {
return super.getCanSpawnHere();
}
}
return false;
}
}
protected float getSoundVolume() {
return 0.4F * (float) this.getSize();
}
public int getVerticalFaceSpeed() {
return 0;
}
protected boolean cn() {
return this.getSize() > 0;
}
protected boolean cl() {
return this.getSize() > 2;
}
protected void jump() {
this.motY = 0.41999998688697815D;
this.isAirBorne = true;
}
public GroupDataEntity prepare(DifficultyDamageScaler scaler, GroupDataEntity data) {
int i = this.random.nextInt(3);
if (i < 2 && this.random.nextFloat() < 0.5F * scaler.c()) {
++i;
}
int j = 1 << i;
this.setSize(j);
return super.prepare(scaler, data);
}
static class PathfinderGoalSlimeIdle extends PathfinderGoal {
private final EntitySlime a;
public PathfinderGoalSlimeIdle(EntitySlime entityslime) {
this.a = entityslime;
this.setMutexBits(5);
}
public boolean a() {
return true;
}
public void e() {
((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(1.0D);
}
}
static class PathfinderGoalSlimeRandomJump extends PathfinderGoal {
private final EntitySlime a;
public PathfinderGoalSlimeRandomJump(EntitySlime entityslime) {
this.a = entityslime;
this.setMutexBits(5);
((Navigation) entityslime.getNavigation()).d(true);
}
public boolean a() {
return this.a.isInWater() || this.a.isInLava();
}
public void e() {
if (this.a.getRandom().nextFloat() < 0.8F) {
this.a.getControllerJump().a();
}
((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(1.2D);
}
}
static class PathfinderGoalSlimeRandomDirection extends PathfinderGoal {
private final EntitySlime a;
private float b;
private int c;
public PathfinderGoalSlimeRandomDirection(EntitySlime entityslime) {
this.a = entityslime;
this.setMutexBits(2);
}
public boolean a() {
return this.a.getGoalTarget() == null && (this.a.onGround || this.a.isInWater() || this.a.isInLava());
}
public void e() {
if (--this.c <= 0) {
this.c = 40 + this.a.getRandom().nextInt(60);
this.b = (float) this.a.getRandom().nextInt(360);
}
((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(this.b, false);
}
}
static class PathfinderGoalSlimeNearestPlayer extends PathfinderGoal {
private final EntitySlime a;
private int b;
public PathfinderGoalSlimeNearestPlayer(EntitySlime entityslime) {
this.a = entityslime;
this.setMutexBits(2);
}
public boolean a() {
EntityLiving entityliving = this.a.getGoalTarget();
return entityliving != null && (entityliving.isAlive() && (!(entityliving instanceof EntityHuman) || !((EntityHuman) entityliving).abilities.isInvulnerable));
}
public void c() {
this.b = 300;
super.c();
}
public boolean b() {
EntityLiving entityliving = this.a.getGoalTarget();
return entityliving != null && (entityliving.isAlive() && ((!(entityliving instanceof EntityHuman) || !((EntityHuman) entityliving).abilities.isInvulnerable) && --this.b > 0));
}
public void e() {
this.a.faceEntity(this.a.getGoalTarget(), 10.0F, 10.0F);
((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(this.a.yaw, this.a.ci());
}
}
static class ControllerMoveSlime extends ControllerMove {
private final EntitySlime i;
private float g;
private int h;
private boolean j;
public ControllerMoveSlime(EntitySlime entityslime) {
super(entityslime);
this.i = entityslime;
}
public void a(float f, boolean flag) {
this.g = f;
this.j = flag;
}
public void a(double d0) {
this.e = d0;
this.f = true;
}
public void c() {
this.a.yaw = this.a(this.a.yaw, this.g, 30.0F);
this.a.rotationYawHead = this.a.yaw;
this.a.renderYawOffset = this.a.yaw;
if (!this.f) {
this.a.setMoveForward(0.0F);
} else {
this.f = false;
if (this.a.onGround) {
this.a.setAIMoveSpeed((float) (this.e * this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue()));
if (this.h-- <= 0) {
this.h = this.i.cg();
if (this.j) {
this.h /= 3;
}
this.i.getControllerJump().a();
if (this.i.cn()) {
this.i.playSound(this.i.ck(), this.i.getSoundVolume(), ((this.i.getRandom().nextFloat() - this.i.getRandom().nextFloat()) * 0.2F + 1.0F) * 0.8F);
}
} else {
this.i.moveStrafing = this.i.moveForward = 0.0F;
this.a.setAIMoveSpeed(0.0F);
}
} else {
this.a.setAIMoveSpeed((float) (this.e * this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue()));
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy