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

1079 Zeilen
32 KiB
Java

package net.minecraft.server;
2011-09-15 02:23:52 +02:00
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.craftbukkit.event.CraftEventFactory;
2011-03-17 18:24:36 +01:00
import org.bukkit.event.entity.EntityDamageByBlockEvent;
2011-01-20 09:10:47 +01:00
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
// CraftBukkit end
public abstract class EntityLiving extends Entity {
2011-01-29 22:50:29 +01:00
public int maxNoDamageTicks = 20;
2011-09-15 02:23:52 +02:00
public float S;
public float T;
public float U = 0.0F;
public float V = 0.0F;
protected float W;
protected float X;
protected float Y;
protected float Z;
protected boolean aa = true;
2011-01-29 22:50:29 +01:00
protected String texture = "/mob/char.png";
2011-09-15 02:23:52 +02:00
protected boolean ac = true;
protected float ad = 0.0F;
protected String ae = null;
protected float af = 1.0F;
protected int ag = 0;
protected float ah = 0.0F;
public boolean ai = false;
public float aj = 0.1F;
public float ak = 0.02F;
public float al;
public float am;
2011-01-29 22:50:29 +01:00
public int health = 10;
2011-09-15 02:23:52 +02:00
public int ao;
private int a;
2011-01-29 22:50:29 +01:00
public int hurtTicks;
2011-09-15 02:23:52 +02:00
public int aq;
public float ar = 0.0F;
2011-01-29 22:50:29 +01:00
public int deathTicks = 0;
public int attackTicks = 0;
2011-09-15 02:23:52 +02:00
public float au;
public float av;
protected boolean aw = false;
protected int ax;
public int ay = -1;
public float az = (float) (Math.random() * 0.8999999761581421D + 0.10000000149011612D);
public float aA;
public float aB;
public float aC;
private EntityHuman b = null;
private int c = 0;
public int aD = 0;
public int aE = 0;
protected HashMap effects = new HashMap();
2011-09-15 02:23:52 +02:00
protected int aG;
protected double aH;
protected double aI;
protected double aJ;
protected double aK;
protected double aL;
float aM = 0.0F;
2011-05-14 16:29:42 +02:00
public int lastDamage = 0; // CraftBukkit - protected -> public
2011-09-15 02:23:52 +02:00
protected int aO = 0;
protected float aP;
protected float aQ;
protected float aR;
protected boolean aS = false;
protected float aT = 0.0F;
protected float aU = 0.7F;
private Entity d;
protected int aV = 0;
public int expToDrop = 0; // CraftBukkit added
public EntityLiving(World world) {
super(world);
2011-09-15 02:23:52 +02:00
this.aY = true;
this.T = (float) (Math.random() + 1.0D) * 0.01F;
this.setPosition(this.locX, this.locY, this.locZ);
2011-09-15 02:23:52 +02:00
this.S = (float) Math.random() * 12398.0F;
2011-01-29 22:50:29 +01:00
this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
2011-09-15 02:23:52 +02:00
this.bI = 0.5F;
}
2011-04-20 22:47:26 +02:00
protected void b() {}
2011-09-15 02:23:52 +02:00
public boolean f(Entity entity) {
2011-06-30 00:02:25 +02:00
return this.world.a(Vec3D.create(this.locX, this.locY + (double) this.t(), this.locZ), Vec3D.create(entity.locX, entity.locY + (double) entity.t(), entity.locZ)) == null;
}
2011-09-15 02:23:52 +02:00
public boolean r_() {
2011-01-29 22:50:29 +01:00
return !this.dead;
}
2011-09-15 02:23:52 +02:00
public boolean g() {
2011-01-29 22:50:29 +01:00
return !this.dead;
}
2011-06-30 00:02:25 +02:00
public float t() {
2011-01-29 22:50:29 +01:00
return this.width * 0.85F;
}
2011-04-20 22:47:26 +02:00
public int e() {
return 80;
}
2011-09-15 02:23:52 +02:00
public void Z() {
String s = this.h();
2011-02-23 03:37:56 +01:00
if (s != null) {
2011-09-15 02:23:52 +02:00
this.world.makeSound(this, s, this.l(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2011-02-23 03:37:56 +01:00
}
}
2011-09-15 02:23:52 +02:00
public void aa() {
this.al = this.am;
super.aa();
2011-01-29 22:50:29 +01:00
if (this.random.nextInt(1000) < this.a++) {
2011-04-20 22:47:26 +02:00
this.a = -this.e();
2011-09-15 02:23:52 +02:00
this.Z();
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.ac() && this.O()) {
2011-01-20 09:49:35 +01:00
// CraftBukkit start
EntityDamageEvent event = new EntityDamageEvent(this.getBukkitEntity(), EntityDamageEvent.DamageCause.SUFFOCATION, 1);
this.world.getServer().getPluginManager().callEvent(event);
2011-01-29 22:50:29 +01:00
if (!event.isCancelled()) {
2011-09-15 18:36:27 +02:00
this.damageEntity(DamageSource.STUCK, event.getDamage());
2011-01-20 09:49:35 +01:00
}
// CraftBukkit end
}
2011-01-29 22:50:29 +01:00
if (this.fireProof || this.world.isStatic) {
2011-01-29 22:50:29 +01:00
this.fireTicks = 0;
}
2011-01-29 22:50:29 +01:00
int i;
if (this.ac() && this.a(Material.WATER) && !this.b_() && !this.effects.containsKey(Integer.valueOf(MobEffectList.WATER_BREATHING.id))) {
2011-01-29 22:50:29 +01:00
--this.airTicks;
if (this.airTicks == -20) {
this.airTicks = 0;
for (i = 0; i < 8; ++i) {
float f = this.random.nextFloat() - this.random.nextFloat();
float f1 = this.random.nextFloat() - this.random.nextFloat();
float f2 = this.random.nextFloat() - this.random.nextFloat();
this.world.a("bubble", this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, this.motX, this.motY, this.motZ);
}
2011-01-30 10:26:45 +01:00
// CraftBukkit start
EntityDamageEvent event = new EntityDamageEvent(this.getBukkitEntity(), EntityDamageEvent.DamageCause.DROWNING, 2);
this.world.getServer().getPluginManager().callEvent(event);
2011-01-30 10:26:45 +01:00
if (!event.isCancelled() && event.getDamage() != 0) {
2011-09-15 18:36:27 +02:00
this.damageEntity(DamageSource.DROWN, event.getDamage());
2011-01-30 10:26:45 +01:00
}
// CraftBukkit end
}
2011-01-29 22:50:29 +01:00
this.fireTicks = 0;
} else {
2011-01-29 22:50:29 +01:00
this.airTicks = this.maxAirTicks;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.au = this.av;
2011-01-29 22:50:29 +01:00
if (this.attackTicks > 0) {
--this.attackTicks;
}
2011-01-29 22:50:29 +01:00
if (this.hurtTicks > 0) {
--this.hurtTicks;
}
2011-01-29 22:50:29 +01:00
if (this.noDamageTicks > 0) {
--this.noDamageTicks;
}
2011-01-29 22:50:29 +01:00
if (this.health <= 0) {
++this.deathTicks;
if (this.deathTicks > 20) {
// CraftBukkit start - update getExpReward() below if this changes!
if (expToDrop > 0) {
i = expToDrop;
2011-09-15 02:23:52 +02:00
while (i > 0) {
int j = EntityExperienceOrb.b(i);
i -= j;
this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
}
}
// CraftBukkit end
2011-09-15 02:23:52 +02:00
this.ag();
this.die();
2011-01-29 22:50:29 +01:00
for (i = 0; i < 20; ++i) {
double d0 = this.random.nextGaussian() * 0.02D;
double d1 = this.random.nextGaussian() * 0.02D;
double d2 = this.random.nextGaussian() * 0.02D;
this.world.a("explode", this.locX + (double) (this.random.nextFloat() * this.length * 2.0F) - (double) this.length, this.locY + (double) (this.random.nextFloat() * this.width), this.locZ + (double) (this.random.nextFloat() * this.length * 2.0F) - (double) this.length, d0, d1, d2);
}
}
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.c > 0) {
--this.c;
} else {
this.b = null;
}
this.aj();
this.Z = this.Y;
this.V = this.U;
2011-01-29 22:50:29 +01:00
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
}
2011-09-15 02:23:52 +02:00
protected int a(EntityHuman entityhuman) {
return this.ax;
}
// CraftBukkit start
public int getExpReward() {
int exp = a(this.b);
if (this.c > 0 || this.X()) {
return exp;
} else {
return 0;
}
}
// CraftBukkit end
2011-09-15 02:23:52 +02:00
protected boolean X() {
return false;
}
public void ab() {
2011-01-29 22:50:29 +01:00
for (int i = 0; i < 20; ++i) {
double d0 = this.random.nextGaussian() * 0.02D;
double d1 = this.random.nextGaussian() * 0.02D;
double d2 = this.random.nextGaussian() * 0.02D;
double d3 = 10.0D;
2011-01-29 22:50:29 +01:00
this.world.a("explode", this.locX + (double) (this.random.nextFloat() * this.length * 2.0F) - (double) this.length - d0 * d3, this.locY + (double) (this.random.nextFloat() * this.width) - d1 * d3, this.locZ + (double) (this.random.nextFloat() * this.length * 2.0F) - (double) this.length - d2 * d3, d0, d1, d2);
}
}
2011-09-15 02:23:52 +02:00
public void I() {
super.I();
this.W = this.X;
this.X = 0.0F;
}
2011-09-15 02:23:52 +02:00
public void s_() {
super.s_();
if (this.aD > 0) {
if (this.aE <= 0) {
this.aE = 60;
}
--this.aE;
if (this.aE <= 0) {
--this.aD;
}
}
this.s();
2011-01-29 22:50:29 +01:00
double d0 = this.locX - this.lastX;
double d1 = this.locZ - this.lastZ;
float f = MathHelper.a(d0 * d0 + d1 * d1);
2011-09-15 02:23:52 +02:00
float f1 = this.U;
2011-01-29 22:50:29 +01:00
float f2 = 0.0F;
2011-09-15 02:23:52 +02:00
this.W = this.X;
float f3 = 0.0F;
2011-01-29 22:50:29 +01:00
if (f > 0.05F) {
f3 = 1.0F;
f2 = f * 3.0F;
2011-05-14 16:29:42 +02:00
// CraftBukkit - Math -> TrigMath
2011-02-23 13:56:36 +01:00
f1 = (float) TrigMath.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.am > 0.0F) {
2011-01-29 22:50:29 +01:00
f1 = this.yaw;
}
2011-01-29 22:50:29 +01:00
if (!this.onGround) {
f3 = 0.0F;
}
2011-09-15 02:23:52 +02:00
this.X += (f3 - this.X) * 0.3F;
2011-01-29 22:50:29 +01:00
float f4;
2011-09-15 02:23:52 +02:00
for (f4 = f1 - this.U; f4 < -180.0F; f4 += 360.0F) {
;
}
2011-01-29 22:50:29 +01:00
while (f4 >= 180.0F) {
f4 -= 360.0F;
}
2011-09-15 02:23:52 +02:00
this.U += f4 * 0.3F;
2011-01-29 22:50:29 +01:00
float f5;
2011-09-15 02:23:52 +02:00
for (f5 = this.yaw - this.U; f5 < -180.0F; f5 += 360.0F) {
;
}
2011-01-29 22:50:29 +01:00
while (f5 >= 180.0F) {
f5 -= 360.0F;
}
2011-01-29 22:50:29 +01:00
boolean flag = f5 < -90.0F || f5 >= 90.0F;
if (f5 < -75.0F) {
f5 = -75.0F;
}
2011-01-29 22:50:29 +01:00
if (f5 >= 75.0F) {
f5 = 75.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.U = this.yaw - f5;
2011-01-29 22:50:29 +01:00
if (f5 * f5 > 2500.0F) {
2011-09-15 02:23:52 +02:00
this.U += f5 * 0.2F;
}
2011-01-29 22:50:29 +01:00
if (flag) {
2011-01-29 22:50:29 +01:00
f2 *= -1.0F;
}
2011-01-29 22:50:29 +01:00
while (this.yaw - this.lastYaw < -180.0F) {
this.lastYaw -= 360.0F;
}
2011-01-29 22:50:29 +01:00
while (this.yaw - this.lastYaw >= 180.0F) {
this.lastYaw += 360.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
while (this.U - this.V < -180.0F) {
this.V -= 360.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
while (this.U - this.V >= 180.0F) {
this.V += 360.0F;
}
2011-01-29 22:50:29 +01:00
while (this.pitch - this.lastPitch < -180.0F) {
this.lastPitch -= 360.0F;
}
2011-01-29 22:50:29 +01:00
while (this.pitch - this.lastPitch >= 180.0F) {
this.lastPitch += 360.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.Y += f2;
}
2011-03-31 22:40:00 +02:00
protected void b(float f, float f1) {
super.b(f, f1);
}
// CraftBukkit start - delegate so we can handle providing a reason for health being regained
2011-09-15 02:23:52 +02:00
public void c(int i) {
c(i, RegainReason.CUSTOM);
}
2011-09-15 02:23:52 +02:00
public void c(int i, RegainReason regainReason) {
2011-01-29 22:50:29 +01:00
if (this.health > 0) {
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), i, regainReason);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.health += event.getAmount();
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
if (this.health > 20) {
this.health = 20;
}
this.noDamageTicks = this.maxNoDamageTicks / 2;
}
}
2011-09-15 02:23:52 +02:00
public boolean damageEntity(DamageSource damagesource, int i) {
2011-01-29 22:50:29 +01:00
if (this.world.isStatic) {
return false;
} else {
2011-09-15 02:23:52 +02:00
this.aO = 0;
2011-01-29 22:50:29 +01:00
if (this.health <= 0) {
return false;
} else {
2011-09-15 02:23:52 +02:00
this.aB = 1.5F;
2011-01-29 22:50:29 +01:00
boolean flag = true;
if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) {
if (i <= this.lastDamage) {
return false;
}
2011-09-15 02:23:52 +02:00
this.b(damagesource, i - this.lastDamage);
2011-01-29 22:50:29 +01:00
this.lastDamage = i;
flag = false;
} else {
this.lastDamage = i;
2011-09-15 02:23:52 +02:00
this.ao = this.health;
2011-01-29 22:50:29 +01:00
this.noDamageTicks = this.maxNoDamageTicks;
2011-09-15 02:23:52 +02:00
this.b(damagesource, i);
this.hurtTicks = this.aq = 10;
}
this.ar = 0.0F;
2011-09-15 18:36:27 +02:00
Entity entity = damagesource.getEntity();
2011-09-15 02:23:52 +02:00
if (entity != null) {
if (entity instanceof EntityHuman) {
this.c = 60;
this.b = (EntityHuman) entity;
} else if (entity instanceof EntityWolf) {
EntityWolf entitywolf = (EntityWolf) entity;
if (entitywolf.isTamed()) {
this.c = 60;
this.b = null;
}
}
}
2011-01-29 22:50:29 +01:00
if (flag) {
this.world.a(this, (byte) 2);
2011-09-15 02:23:52 +02:00
this.aq();
2011-01-29 22:50:29 +01:00
if (entity != null) {
double d0 = entity.locX - this.locX;
double d1;
for (d1 = entity.locZ - this.locZ; d0 * d0 + d1 * d1 < 1.0E-4D; d1 = (Math.random() - Math.random()) * 0.01D) {
d0 = (Math.random() - Math.random()) * 0.01D;
}
2011-09-15 02:23:52 +02:00
this.ar = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - this.yaw;
2011-01-29 22:50:29 +01:00
this.a(entity, i, d0, d1);
} else {
2011-09-15 02:23:52 +02:00
this.ar = (float) ((int) (Math.random() * 2.0D) * 180);
2011-01-29 22:50:29 +01:00
}
}
if (this.health <= 0) {
if (flag) {
2011-09-15 02:23:52 +02:00
this.world.makeSound(this, this.j(), this.l(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
this.die(damagesource);
2011-01-29 22:50:29 +01:00
} else if (flag) {
2011-09-15 02:23:52 +02:00
this.world.makeSound(this, this.i(), this.l(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
2011-01-29 22:50:29 +01:00
}
return true;
}
}
}
2011-09-15 02:23:52 +02:00
protected void b(DamageSource damagesource, int i) {
2011-01-29 22:50:29 +01:00
this.health -= i;
}
2011-09-15 02:23:52 +02:00
protected float l() {
return 1.0F;
}
2011-09-15 02:23:52 +02:00
protected String h() {
return null;
}
2011-09-15 02:23:52 +02:00
protected String i() {
return "random.hurt";
}
2011-09-15 02:23:52 +02:00
protected String j() {
return "random.hurt";
}
2011-01-29 22:50:29 +01:00
public void a(Entity entity, int i, double d0, double d1) {
2011-09-15 02:23:52 +02:00
this.ca = true;
2011-01-29 22:50:29 +01:00
float f = MathHelper.a(d0 * d0 + d1 * d1);
float f1 = 0.4F;
2011-01-29 22:50:29 +01:00
this.motX /= 2.0D;
this.motY /= 2.0D;
this.motZ /= 2.0D;
this.motX -= d0 / (double) f * (double) f1;
this.motY += 0.4000000059604645D;
this.motZ -= d1 / (double) f * (double) f1;
if (this.motY > 0.4000000059604645D) {
this.motY = 0.4000000059604645D;
}
}
2011-09-15 02:23:52 +02:00
public void die(DamageSource damagesource) {
2011-09-15 18:36:27 +02:00
Entity entity = damagesource.getEntity();
2011-09-15 02:23:52 +02:00
if (this.ag >= 0 && entity != null) {
entity.b(this, this.ag);
2011-04-20 22:47:26 +02:00
}
if (entity != null) {
entity.a(this);
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.aw = true;
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic) {
2011-09-15 02:23:52 +02:00
this.a(this.c > 0);
}
2011-01-29 22:50:29 +01:00
this.world.a(this, (byte) 3);
}
2011-09-15 02:23:52 +02:00
protected void a(boolean flag) {
int i = this.k();
2011-02-23 13:56:36 +01:00
// CraftBukkit start - whole method
List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int count = this.random.nextInt(3);
2011-02-23 13:56:36 +01:00
if ((i > 0) && (count > 0)) {
loot.add(new org.bukkit.inventory.ItemStack(i, count));
}
CraftEventFactory.callEntityDeathEvent(this, loot);
2011-02-23 13:56:36 +01:00
// CraftBukkit end
}
2011-09-15 02:23:52 +02:00
protected int k() {
return 0;
}
2011-01-29 22:50:29 +01:00
protected void a(float f) {
2011-05-26 14:48:22 +02:00
super.a(f);
2011-01-29 22:50:29 +01:00
int i = (int) Math.ceil((double) (f - 3.0F));
2011-01-29 22:50:29 +01:00
if (i > 0) {
2011-01-20 09:10:47 +01:00
// CraftBukkit start
EntityDamageEvent event = new EntityDamageEvent(this.getBukkitEntity(), EntityDamageEvent.DamageCause.FALL, i);
this.world.getServer().getPluginManager().callEvent(event);
2011-01-29 22:50:29 +01:00
2011-03-31 22:40:00 +02:00
if (!event.isCancelled() && event.getDamage() != 0) {
2011-09-15 18:36:27 +02:00
this.damageEntity(DamageSource.FALL, event.getDamage());
2011-01-20 09:10:47 +01:00
}
2011-01-20 09:11:08 +01:00
// CraftBukkit end
int j = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height), MathHelper.floor(this.locZ));
2011-01-29 22:50:29 +01:00
if (j > 0) {
StepSound stepsound = Block.byId[j].stepSound;
this.world.makeSound(this, stepsound.getName(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F);
}
}
}
2011-03-31 22:40:00 +02:00
public void a(float f, float f1) {
2011-01-29 22:50:29 +01:00
double d0;
2011-09-15 02:23:52 +02:00
if (this.ao()) {
2011-01-29 22:50:29 +01:00
d0 = this.locY;
this.a(f, f1, 0.02F);
this.move(this.motX, this.motY, this.motZ);
2011-01-29 22:50:29 +01:00
this.motX *= 0.800000011920929D;
this.motY *= 0.800000011920929D;
this.motZ *= 0.800000011920929D;
this.motY -= 0.02D;
2011-07-08 14:25:53 +02:00
if (this.positionChanged && this.d(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
2011-01-29 22:50:29 +01:00
this.motY = 0.30000001192092896D;
}
2011-09-15 02:23:52 +02:00
} else if (this.ap()) {
2011-01-29 22:50:29 +01:00
d0 = this.locY;
this.a(f, f1, 0.02F);
this.move(this.motX, this.motY, this.motZ);
2011-01-29 22:50:29 +01:00
this.motX *= 0.5D;
this.motY *= 0.5D;
this.motZ *= 0.5D;
this.motY -= 0.02D;
2011-07-08 14:25:53 +02:00
if (this.positionChanged && this.d(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
2011-01-29 22:50:29 +01:00
this.motY = 0.30000001192092896D;
}
} else {
2011-01-29 22:50:29 +01:00
float f2 = 0.91F;
2011-01-29 22:50:29 +01:00
if (this.onGround) {
f2 = 0.54600006F;
int i = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ));
2011-01-29 22:50:29 +01:00
if (i > 0) {
f2 = Block.byId[i].frictionFactor * 0.91F;
}
}
2011-01-29 22:50:29 +01:00
float f3 = 0.16277136F / (f2 * f2 * f2);
2011-09-15 02:23:52 +02:00
float f4 = this.onGround ? this.aj * f3 : this.ak;
2011-09-15 02:23:52 +02:00
this.a(f, f1, f4);
2011-01-29 22:50:29 +01:00
f2 = 0.91F;
if (this.onGround) {
f2 = 0.54600006F;
int j = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ));
2011-01-29 22:50:29 +01:00
if (j > 0) {
f2 = Block.byId[j].frictionFactor * 0.91F;
}
}
2011-01-29 22:50:29 +01:00
2011-04-20 22:47:26 +02:00
if (this.p()) {
2011-09-15 02:23:52 +02:00
float f5 = 0.15F;
2011-05-26 14:48:22 +02:00
2011-09-15 02:23:52 +02:00
if (this.motX < (double) (-f5)) {
this.motX = (double) (-f5);
2011-05-26 14:48:22 +02:00
}
2011-09-15 02:23:52 +02:00
if (this.motX > (double) f5) {
this.motX = (double) f5;
2011-05-26 14:48:22 +02:00
}
2011-09-15 02:23:52 +02:00
if (this.motZ < (double) (-f5)) {
this.motZ = (double) (-f5);
2011-05-26 14:48:22 +02:00
}
2011-09-15 02:23:52 +02:00
if (this.motZ > (double) f5) {
this.motZ = (double) f5;
2011-05-26 14:48:22 +02:00
}
2011-01-29 22:50:29 +01:00
this.fallDistance = 0.0F;
if (this.motY < -0.15D) {
this.motY = -0.15D;
}
2011-03-31 22:40:00 +02:00
if (this.isSneaking() && this.motY < 0.0D) {
2011-03-31 22:40:00 +02:00
this.motY = 0.0D;
}
}
2011-01-29 22:50:29 +01:00
this.move(this.motX, this.motY, this.motZ);
2011-04-20 22:47:26 +02:00
if (this.positionChanged && this.p()) {
2011-01-29 22:50:29 +01:00
this.motY = 0.2D;
}
2011-01-29 22:50:29 +01:00
this.motY -= 0.08D;
this.motY *= 0.9800000190734863D;
this.motX *= (double) f2;
this.motZ *= (double) f2;
}
2011-09-15 02:23:52 +02:00
this.aA = this.aB;
2011-01-29 22:50:29 +01:00
d0 = this.locX - this.lastX;
double d1 = this.locZ - this.lastZ;
2011-09-15 02:23:52 +02:00
float f6 = MathHelper.a(d0 * d0 + d1 * d1) * 4.0F;
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (f6 > 1.0F) {
f6 = 1.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.aB += (f6 - this.aB) * 0.4F;
this.aC += this.aB;
}
2011-04-20 22:47:26 +02:00
public boolean p() {
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.boundingBox.b);
int k = MathHelper.floor(this.locZ);
2011-04-20 22:47:26 +02:00
return this.world.getTypeId(i, j, k) == Block.LADDER.id;
}
2011-04-20 22:47:26 +02:00
public void b(NBTTagCompound nbttagcompound) {
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Health", (short) this.health);
nbttagcompound.a("HurtTime", (short) this.hurtTicks);
nbttagcompound.a("DeathTime", (short) this.deathTicks);
nbttagcompound.a("AttackTime", (short) this.attackTicks);
if (!this.effects.isEmpty()) {
2011-09-15 02:23:52 +02:00
NBTTagList nbttaglist = new NBTTagList();
Iterator iterator = this.effects.values().iterator();
2011-09-15 02:23:52 +02:00
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.a("Id", (byte) mobeffect.getEffectId());
nbttagcompound1.a("Amplifier", (byte) mobeffect.getAmplifier());
nbttagcompound1.a("Duration", mobeffect.getDuration());
2011-09-15 02:23:52 +02:00
nbttaglist.a((NBTBase) nbttagcompound1);
}
nbttagcompound.a("ActiveEffects", (NBTBase) nbttaglist);
}
}
2011-04-20 22:47:26 +02:00
public void a(NBTTagCompound nbttagcompound) {
2011-02-23 03:37:56 +01:00
this.health = nbttagcompound.d("Health");
if (!nbttagcompound.hasKey("Health")) {
2011-01-29 22:50:29 +01:00
this.health = 10;
}
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
this.hurtTicks = nbttagcompound.d("HurtTime");
this.deathTicks = nbttagcompound.d("DeathTime");
this.attackTicks = nbttagcompound.d("AttackTime");
2011-09-15 02:23:52 +02:00
if (nbttagcompound.hasKey("ActiveEffects")) {
NBTTagList nbttaglist = nbttagcompound.l("ActiveEffects");
for (int i = 0; i < nbttaglist.c(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
byte b0 = nbttagcompound1.c("Id");
byte b1 = nbttagcompound1.c("Amplifier");
int j = nbttagcompound1.e("Duration");
this.effects.put(Integer.valueOf(b0), new MobEffect(b0, j, b1));
2011-09-15 02:23:52 +02:00
}
}
}
2011-09-15 02:23:52 +02:00
public boolean ac() {
2011-01-29 22:50:29 +01:00
return !this.dead && this.health > 0;
}
2011-02-23 03:37:56 +01:00
public boolean b_() {
return false;
}
2011-09-15 02:23:52 +02:00
public void s() {
if (this.aG > 0) {
double d0 = this.locX + (this.aH - this.locX) / (double) this.aG;
double d1 = this.locY + (this.aI - this.locY) / (double) this.aG;
double d2 = this.locZ + (this.aJ - this.locZ) / (double) this.aG;
2011-01-29 22:50:29 +01:00
double d3;
2011-09-15 02:23:52 +02:00
for (d3 = this.aK - (double) this.yaw; d3 < -180.0D; d3 += 360.0D) {
;
}
2011-01-29 22:50:29 +01:00
while (d3 >= 180.0D) {
d3 -= 360.0D;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.yaw = (float) ((double) this.yaw + d3 / (double) this.aG);
this.pitch = (float) ((double) this.pitch + (this.aL - (double) this.pitch) / (double) this.aG);
--this.aG;
this.setPosition(d0, d1, d2);
2011-02-23 03:37:56 +01:00
this.c(this.yaw, this.pitch);
2011-05-28 22:50:08 +02:00
List list = this.world.getEntities(this, this.boundingBox.shrink(0.03125D, 0.0D, 0.03125D));
if (list.size() > 0) {
double d4 = 0.0D;
for (int i = 0; i < list.size(); ++i) {
AxisAlignedBB axisalignedbb = (AxisAlignedBB) list.get(i);
if (axisalignedbb.e > d4) {
d4 = axisalignedbb.e;
}
}
d1 += d4 - this.boundingBox.b;
this.setPosition(d0, d1, d2);
}
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
if (this.H()) {
this.aS = false;
this.aP = 0.0F;
this.aQ = 0.0F;
this.aR = 0.0F;
} else if (!this.ai) {
2011-02-23 03:37:56 +01:00
this.c_();
2011-01-29 22:50:29 +01:00
}
2011-09-15 02:23:52 +02:00
boolean flag = this.ao();
boolean flag1 = this.ap();
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.aS) {
if (flag) {
2011-01-29 22:50:29 +01:00
this.motY += 0.03999999910593033D;
} else if (flag1) {
2011-01-29 22:50:29 +01:00
this.motY += 0.03999999910593033D;
} else if (this.onGround) {
2011-09-15 02:23:52 +02:00
this.S();
}
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.aP *= 0.98F;
this.aQ *= 0.98F;
this.aR *= 0.9F;
float f = this.aj;
this.aj *= this.D();
this.a(this.aP, this.aQ);
this.aj = f;
2011-05-28 22:50:08 +02:00
List list1 = this.world.b((Entity) this, this.boundingBox.b(0.20000000298023224D, 0.0D, 0.20000000298023224D));
2011-05-28 22:50:08 +02:00
if (list1 != null && list1.size() > 0) {
for (int j = 0; j < list1.size(); ++j) {
Entity entity = (Entity) list1.get(j);
2011-09-15 02:23:52 +02:00
if (entity.g()) {
entity.collide(this);
}
}
}
}
2011-09-15 02:23:52 +02:00
protected boolean H() {
2011-02-23 03:37:56 +01:00
return this.health <= 0;
}
2011-09-15 02:23:52 +02:00
public boolean G() {
return false;
}
protected void S() {
2011-01-29 22:50:29 +01:00
this.motY = 0.41999998688697815D;
if (this.isSprinting()) {
2011-09-15 02:23:52 +02:00
float f = this.yaw * 0.017453292F;
this.motX -= (double) (MathHelper.sin(f) * 0.2F);
this.motZ += (double) (MathHelper.cos(f) * 0.2F);
}
this.ca = true;
}
2011-09-15 02:23:52 +02:00
protected boolean d_() {
2011-03-31 22:40:00 +02:00
return true;
}
2011-09-15 02:23:52 +02:00
protected void ad() {
EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
2011-09-15 02:23:52 +02:00
if (this.d_() && entityhuman != null) {
2011-01-29 22:50:29 +01:00
double d0 = entityhuman.locX - this.locX;
double d1 = entityhuman.locY - this.locY;
double d2 = entityhuman.locZ - this.locZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
2011-01-29 22:50:29 +01:00
if (d3 > 16384.0D) {
this.die();
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.aO > 600 && this.random.nextInt(800) == 0) {
2011-01-29 22:50:29 +01:00
if (d3 < 1024.0D) {
2011-09-15 02:23:52 +02:00
this.aO = 0;
} else {
this.die();
}
}
}
2011-04-20 22:47:26 +02:00
}
protected void c_() {
2011-09-15 02:23:52 +02:00
++this.aO;
EntityHuman entityhuman = this.world.findNearbyPlayer(this, -1.0D);
2011-09-15 02:23:52 +02:00
this.ad();
this.aP = 0.0F;
this.aQ = 0.0F;
2011-01-29 22:50:29 +01:00
float f = 8.0F;
2011-01-29 22:50:29 +01:00
if (this.random.nextFloat() < 0.02F) {
entityhuman = this.world.findNearbyPlayer(this, (double) f);
2011-01-29 22:50:29 +01:00
if (entityhuman != null) {
2011-09-15 02:23:52 +02:00
this.d = entityhuman;
this.aV = 10 + this.random.nextInt(20);
} else {
2011-09-15 02:23:52 +02:00
this.aR = (this.random.nextFloat() - 0.5F) * 20.0F;
}
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
if (this.d != null) {
this.a(this.d, 10.0F, (float) this.u());
if (this.aV-- <= 0 || this.d.dead || this.d.h(this) > (double) (f * f)) {
this.d = null;
}
} else {
2011-01-29 22:50:29 +01:00
if (this.random.nextFloat() < 0.05F) {
2011-09-15 02:23:52 +02:00
this.aR = (this.random.nextFloat() - 0.5F) * 20.0F;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
this.yaw += this.aR;
this.pitch = this.aT;
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
boolean flag = this.ao();
boolean flag1 = this.ap();
if (flag || flag1) {
2011-09-15 02:23:52 +02:00
this.aS = this.random.nextFloat() < 0.8F;
}
}
2011-06-30 00:02:25 +02:00
protected int u() {
2011-04-20 22:47:26 +02:00
return 40;
2011-03-31 22:40:00 +02:00
}
public void a(Entity entity, float f, float f1) {
2011-01-29 22:50:29 +01:00
double d0 = entity.locX - this.locX;
double d1 = entity.locZ - this.locZ;
double d2;
if (entity instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) entity;
2011-06-30 00:02:25 +02:00
d2 = this.locY + (double) this.t() - (entityliving.locY + (double) entityliving.t());
} else {
2011-06-30 00:02:25 +02:00
d2 = (entity.boundingBox.b + entity.boundingBox.e) / 2.0D - (this.locY + (double) this.t());
}
2011-01-29 22:50:29 +01:00
double d3 = (double) MathHelper.a(d0 * d0 + d1 * d1);
2011-03-31 22:40:00 +02:00
float f2 = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
2011-04-20 22:47:26 +02:00
float f3 = (float) (-(Math.atan2(d2, d3) * 180.0D / 3.1415927410125732D));
2011-03-31 22:40:00 +02:00
this.pitch = -this.b(this.pitch, f3, f1);
this.yaw = this.b(this.yaw, f2, f);
}
2011-09-15 02:23:52 +02:00
public boolean ae() {
return this.d != null;
2011-03-31 22:40:00 +02:00
}
2011-01-29 22:50:29 +01:00
2011-09-15 02:23:52 +02:00
public Entity af() {
return this.d;
}
2011-01-29 22:50:29 +01:00
private float b(float f, float f1, float f2) {
float f3;
2011-01-29 22:50:29 +01:00
for (f3 = f1 - f; f3 < -180.0F; f3 += 360.0F) {
;
}
2011-01-29 22:50:29 +01:00
while (f3 >= 180.0F) {
f3 -= 360.0F;
}
2011-01-29 22:50:29 +01:00
if (f3 > f2) {
f3 = f2;
}
2011-01-29 22:50:29 +01:00
if (f3 < -f2) {
f3 = -f2;
}
2011-01-29 22:50:29 +01:00
return f + f3;
}
2011-09-15 02:23:52 +02:00
public void ag() {}
2011-04-20 22:47:26 +02:00
public boolean d() {
return this.world.containsEntity(this.boundingBox) && this.world.getEntities(this, this.boundingBox).size() == 0 && !this.world.c(this.boundingBox);
}
2011-09-15 02:23:52 +02:00
protected void ah() {
2011-03-17 18:24:36 +01:00
// CraftBukkit start
EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, this.getBukkitEntity(), EntityDamageEvent.DamageCause.VOID, 4);
this.world.getServer().getPluginManager().callEvent(event);
2011-03-17 18:24:36 +01:00
2011-03-31 22:40:00 +02:00
if (event.isCancelled() || event.getDamage() == 0) {
2011-03-17 18:24:36 +01:00
return;
}
2011-05-14 16:29:42 +02:00
2011-09-15 18:36:27 +02:00
this.damageEntity(DamageSource.OUT_OF_WORLD, event.getDamage());
2011-03-17 18:24:36 +01:00
// CraftBukkit end
}
2011-09-15 02:23:52 +02:00
public Vec3D ai() {
return this.c(1.0F);
}
2011-09-15 02:23:52 +02:00
public Vec3D c(float f) {
2011-01-29 22:50:29 +01:00
float f1;
float f2;
float f3;
float f4;
2011-01-29 22:50:29 +01:00
if (f == 1.0F) {
f1 = MathHelper.cos(-this.yaw * 0.017453292F - 3.1415927F);
f2 = MathHelper.sin(-this.yaw * 0.017453292F - 3.1415927F);
f3 = -MathHelper.cos(-this.pitch * 0.017453292F);
f4 = MathHelper.sin(-this.pitch * 0.017453292F);
return Vec3D.create((double) (f2 * f3), (double) f4, (double) (f1 * f3));
} else {
2011-01-29 22:50:29 +01:00
f1 = this.lastPitch + (this.pitch - this.lastPitch) * f;
f2 = this.lastYaw + (this.yaw - this.lastYaw) * f;
f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
float f6 = MathHelper.sin(-f1 * 0.017453292F);
2011-01-29 22:50:29 +01:00
return Vec3D.create((double) (f4 * f5), (double) f6, (double) (f3 * f5));
}
}
2011-09-15 02:23:52 +02:00
public int m() {
return 4;
}
2011-02-23 03:37:56 +01:00
public boolean isSleeping() {
2011-02-23 03:37:56 +01:00
return false;
}
2011-09-15 02:23:52 +02:00
protected void aj() {
Iterator iterator = this.effects.keySet().iterator();
2011-09-15 02:23:52 +02:00
while (iterator.hasNext()) {
Integer integer = (Integer) iterator.next();
MobEffect mobeffect = (MobEffect) this.effects.get(integer);
2011-09-15 02:23:52 +02:00
if (!mobeffect.tick(this) && !this.world.isStatic) {
2011-09-15 02:23:52 +02:00
iterator.remove();
this.c(mobeffect);
}
}
}
public Collection getEffects() {
return this.effects.values();
2011-09-15 02:23:52 +02:00
}
public boolean hasEffect(MobEffectList mobeffectlist) {
return this.effects.containsKey(Integer.valueOf(mobeffectlist.id));
2011-09-15 02:23:52 +02:00
}
public MobEffect getEffect(MobEffectList mobeffectlist) {
return (MobEffect) this.effects.get(Integer.valueOf(mobeffectlist.id));
2011-09-15 02:23:52 +02:00
}
public void addEffect(MobEffect mobeffect) {
if (this.effects.containsKey(Integer.valueOf(mobeffect.getEffectId()))) {
((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId()))).a(mobeffect);
this.b((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId())));
2011-09-15 02:23:52 +02:00
} else {
this.effects.put(Integer.valueOf(mobeffect.getEffectId()), mobeffect);
2011-09-15 02:23:52 +02:00
this.a(mobeffect);
}
}
protected void a(MobEffect mobeffect) {}
protected void b(MobEffect mobeffect) {}
protected void c(MobEffect mobeffect) {}
protected float D() {
float f = 1.0F;
if (this.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
f *= 1.0F + 0.2F * (float) (this.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
2011-09-15 02:23:52 +02:00
}
if (this.hasEffect(MobEffectList.SLOWER_MOVEMENT)) {
f *= 1.0F - 0.15F * (float) (this.getEffect(MobEffectList.SLOWER_MOVEMENT).getAmplifier() + 1);
2011-09-15 02:23:52 +02:00
}
return f;
}
}