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

1573 lines
49 KiB
Java
Raw Normal View History

package net.minecraft.server;
2011-09-15 01:23:52 +01:00
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
2012-01-12 23:10:13 +01:00
import java.util.Random;
2013-07-01 06:03:00 -05:00
import java.util.UUID;
// CraftBukkit start
import org.bukkit.craftbukkit.event.CraftEventFactory;
2011-01-20 00:10:47 -08:00
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
// CraftBukkit end
public abstract class EntityLiving extends Entity {
2013-07-01 06:03:00 -05:00
private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
private static final AttributeModifier c = (new AttributeModifier(b, "Sprinting speed boost", 0.30000001192092896D, 2)).a(false);
private AttributeMapBase d;
public CombatTracker combatTracker = new CombatTracker(this); // CraftBukkit - private -> public, remove final
public final HashMap effects = new HashMap(); // CraftBukkit - protected -> public
private final ItemStack[] g = new ItemStack[5];
public boolean au;
public int av;
public int aw;
2013-03-13 17:33:27 -05:00
public float ax;
2011-01-29 22:50:29 +01:00
public int hurtTicks;
2013-07-01 06:03:00 -05:00
public int az;
public float aA;
public int deathTicks;
public int attackTicks;
public float aD;
public float aE;
public float aF;
public float aG;
public float aH;
public int maxNoDamageTicks = 20;
public float aJ;
public float aK;
public float aL;
public float aM;
public float aN;
public float aO;
public float aP;
public float aQ;
public float aR = 0.02F;
public EntityHuman killer; // CraftBukkit - protected -> public
protected int lastDamageByPlayerTime;
protected boolean aU;
protected int aV;
protected float aW;
protected float aX;
protected float aY;
protected float aZ;
protected float ba;
protected int bb;
public float lastDamage; // CraftBukkit - protected -> public
protected boolean bd;
public float be;
public float bf;
protected float bg;
protected int bh;
protected double bi;
protected double bj;
protected double bk;
protected double bl;
protected double bm;
2012-07-29 02:33:13 -05:00
public boolean updateEffects = true; // CraftBukkit - private -> public
2013-07-01 06:03:00 -05:00
public EntityLiving lastDamager; // CraftBukkit - private -> public
private int j;
private EntityLiving bn;
2013-07-08 19:43:37 -04:00
private int bo;
private float bp;
private int bq;
private float br;
// CraftBukkit start
2013-07-01 06:03:00 -05:00
public int expToDrop;
public int maxAirTicks = 300;
// CraftBukkit end
public EntityLiving(World world) {
super(world);
2013-07-08 19:43:37 -04:00
this.ay();
2013-07-01 06:03:00 -05:00
this.setHealth(this.getMaxHealth());
2012-07-29 02:33:13 -05:00
this.m = true;
2013-07-01 06:03:00 -05:00
this.aM = (float) (Math.random() + 1.0D) * 0.01F;
this.setPosition(this.locX, this.locY, this.locZ);
2013-07-01 06:03:00 -05:00
this.aL = (float) Math.random() * 12398.0F;
2011-01-29 22:50:29 +01:00
this.yaw = (float) (Math.random() * 3.1415927410125732D * 2.0D);
2013-07-01 06:03:00 -05:00
this.aP = this.yaw;
2013-03-13 17:33:27 -05:00
this.Y = 0.5F;
}
2013-07-01 06:03:00 -05:00
protected void a() {
this.datawatcher.a(7, Integer.valueOf(0));
this.datawatcher.a(8, Byte.valueOf((byte) 0));
this.datawatcher.a(9, Byte.valueOf((byte) 0));
this.datawatcher.a(6, Float.valueOf(1.0F));
2012-03-01 10:49:23 +00:00
}
2013-07-08 19:43:37 -04:00
protected void ay() {
this.aW().b(GenericAttributes.a);
this.aW().b(GenericAttributes.c);
this.aW().b(GenericAttributes.d);
if (!this.be()) {
this.getAttributeInstance(GenericAttributes.d).setValue(0.10000000149011612D);
2012-03-01 10:49:23 +00:00
}
}
protected void a(double d0, boolean flag) {
2013-03-13 17:33:27 -05:00
if (!this.G()) {
this.H();
2012-11-06 06:05:28 -06:00
}
if (flag && this.fallDistance > 0.0F) {
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
int k = MathHelper.floor(this.locZ);
int l = this.world.getTypeId(i, j, k);
2012-11-06 06:05:28 -06:00
if (l == 0) {
int i1 = this.world.e(i, j - 1, k);
if (i1 == 11 || i1 == 32 || i1 == 21) {
l = this.world.getTypeId(i, j - 1, k);
}
}
if (l > 0) {
Block.byId[l].a(this.world, i, j, k, this, this.fallDistance);
}
}
super.a(d0, flag);
}
2012-03-01 10:49:23 +00:00
2013-07-08 19:43:37 -04:00
public boolean az() {
2013-07-01 06:03:00 -05:00
return false;
2011-02-23 02:37:56 +00:00
}
2013-03-13 17:33:27 -05:00
public void x() {
2013-07-01 06:03:00 -05:00
this.aD = this.aE;
2013-03-13 17:33:27 -05:00
super.x();
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.a("livingEntityBaseTick");
if (this.isAlive() && this.inBlock()) {
2013-07-01 06:03:00 -05:00
this.damageEntity(DamageSource.STUCK, 1.0F);
}
2011-01-29 22:50:29 +01:00
if (this.isFireproof() || this.world.isStatic) {
this.extinguish();
}
2012-12-19 22:03:52 -06:00
boolean flag = this instanceof EntityHuman && ((EntityHuman) this).abilities.isInvulnerable;
2013-07-01 06:03:00 -05:00
if (this.isAlive() && this.a(Material.WATER)) {
2013-07-08 19:43:37 -04:00
if (!this.az() && !this.hasEffect(MobEffectList.WATER_BREATHING.id) && !flag) {
2013-07-01 06:03:00 -05:00
this.setAirTicks(this.h(this.getAirTicks()));
if (this.getAirTicks() == -20) {
this.setAirTicks(0);
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
for (int 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();
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.world.addParticle("bubble", this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, this.motX, this.motY, this.motZ);
}
2013-07-01 06:03:00 -05:00
this.damageEntity(DamageSource.DROWN, 2.0F);
}
}
2011-01-29 22:50:29 +01:00
this.extinguish();
2013-07-08 19:43:37 -04:00
if (!this.world.isStatic && this.af() && this.vehicle instanceof EntityLiving) {
2013-07-01 06:03:00 -05:00
this.mount((Entity) null);
}
} else {
2013-03-24 23:22:32 -05:00
// CraftBukkit start - Only set if needed to work around a DataWatcher inefficiency
2012-02-10 00:43:12 -05:00
if (this.getAirTicks() != 300) {
this.setAirTicks(maxAirTicks);
}
2012-02-10 00:43:12 -05:00
// CraftBukkit end
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.aJ = this.aK;
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;
}
2013-07-01 06:03:00 -05:00
if (this.getHealth() <= 0.0F) {
2013-07-08 19:43:37 -04:00
this.aA();
}
2011-01-29 22:50:29 +01:00
if (this.lastDamageByPlayerTime > 0) {
--this.lastDamageByPlayerTime;
2011-09-15 01:23:52 +01:00
} else {
2012-01-12 15:27:39 +00:00
this.killer = null;
2011-09-15 01:23:52 +01:00
}
2013-07-01 06:03:00 -05:00
if (this.bn != null && !this.bn.isAlive()) {
this.bn = null;
2012-03-01 10:49:23 +00:00
}
2013-07-08 19:43:37 -04:00
if (this.lastDamager != null && !this.lastDamager.isAlive()) {
this.b((EntityLiving) null);
2012-03-01 10:49:23 +00:00
}
2013-07-08 19:43:37 -04:00
this.aI();
2013-07-01 06:03:00 -05:00
this.aZ = this.aY;
this.aO = this.aN;
this.aQ = this.aP;
2011-01-29 22:50:29 +01:00
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
2012-09-09 23:19:28 -05:00
this.world.methodProfiler.b();
2011-09-15 01:23:52 +01:00
}
// CraftBukkit start
public int getExpReward() {
int exp = this.getExpValue(this.killer);
2013-03-24 23:22:32 -05:00
if (!this.world.isStatic && (this.lastDamageByPlayerTime > 0 || this.alwaysGivesExp()) && !this.isBaby()) {
return exp;
} else {
return 0;
}
}
// CraftBukkit end
2013-07-01 06:03:00 -05:00
public boolean isBaby() {
return false;
}
2013-07-08 19:43:37 -04:00
protected void aA() {
2011-11-20 00:01:14 -08:00
++this.deathTicks;
2012-07-29 02:33:13 -05:00
if (this.deathTicks >= 20 && !this.dead) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
2011-11-20 00:01:14 -08:00
int i;
2013-03-24 23:22:32 -05:00
// CraftBukkit start - Update getExpReward() above if the removed if() changes!
2012-11-06 06:05:28 -06:00
i = this.expToDrop;
2011-11-20 00:01:14 -08:00
while (i > 0) {
int j = EntityExperienceOrb.getOrbValue(i);
2011-11-20 00:01:14 -08:00
i -= j;
this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
}
2012-11-06 06:05:28 -06:00
this.expToDrop = 0;
2011-11-20 00:01:14 -08:00
// CraftBukkit end
this.die();
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.addParticle("explode", this.locX + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width, this.locY + (double) (this.random.nextFloat() * this.length), this.locZ + (double) (this.random.nextFloat() * this.width * 2.0F) - (double) this.width, d0, d1, d2);
2011-11-20 00:01:14 -08:00
}
}
}
2013-03-13 17:33:27 -05:00
protected int h(int i) {
int j = EnchantmentManager.getOxygenEnchantmentLevel(this);
return j > 0 && this.random.nextInt(j + 1) > 0 ? i : i - 1;
2011-11-20 00:01:14 -08:00
}
protected int getExpValue(EntityHuman entityhuman) {
2013-07-01 06:03:00 -05:00
return 0;
2011-11-20 00:01:14 -08:00
}
protected boolean alwaysGivesExp() {
2011-09-15 01:23:52 +01:00
return false;
}
2013-07-08 19:43:37 -04:00
public Random aC() {
2013-07-01 06:03:00 -05:00
return this.random;
}
public EntityLiving getLastDamager() {
return this.lastDamager;
}
2013-07-08 19:43:37 -04:00
public int aE() {
return this.j;
}
2013-07-01 06:03:00 -05:00
public void b(EntityLiving entityliving) {
this.lastDamager = entityliving;
2013-07-08 19:43:37 -04:00
this.j = this.ticksLived;
2013-07-01 06:03:00 -05:00
}
2013-07-08 19:43:37 -04:00
public EntityLiving aF() {
2013-07-01 06:03:00 -05:00
return this.bn;
}
2013-07-08 19:43:37 -04:00
public int aG() {
return this.bo;
}
2013-07-01 06:03:00 -05:00
public void k(Entity entity) {
if (entity instanceof EntityLiving) {
this.bn = (EntityLiving) entity;
2013-07-08 19:43:37 -04:00
} else {
this.bn = null;
}
2013-07-08 19:43:37 -04:00
this.bo = this.ticksLived;
}
2013-07-08 19:43:37 -04:00
public int aH() {
2013-07-01 06:03:00 -05:00
return this.aV;
}
2013-07-01 06:03:00 -05:00
public void b(NBTTagCompound nbttagcompound) {
nbttagcompound.setFloat("HealF", this.getHealth());
nbttagcompound.setShort("Health", (short) ((int) Math.ceil((double) this.getHealth())));
nbttagcompound.setShort("HurtTime", (short) this.hurtTicks);
nbttagcompound.setShort("DeathTime", (short) this.deathTicks);
nbttagcompound.setShort("AttackTime", (short) this.attackTicks);
2013-07-08 19:43:37 -04:00
nbttagcompound.setFloat("AbsorptionAmount", this.bm());
2013-07-01 06:03:00 -05:00
ItemStack[] aitemstack = this.getEquipment();
int i = aitemstack.length;
2012-11-06 06:05:28 -06:00
2013-07-01 06:03:00 -05:00
int j;
ItemStack itemstack;
2013-07-01 06:03:00 -05:00
for (j = 0; j < i; ++j) {
itemstack = aitemstack[j];
if (itemstack != null) {
this.d.a(itemstack.D());
}
2013-07-01 06:03:00 -05:00
}
2013-07-08 19:43:37 -04:00
nbttagcompound.set("Attributes", GenericAttributes.a(this.aW()));
2013-07-01 06:03:00 -05:00
aitemstack = this.getEquipment();
i = aitemstack.length;
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
for (j = 0; j < i; ++j) {
itemstack = aitemstack[j];
if (itemstack != null) {
this.d.b(itemstack.D());
2011-09-15 01:23:52 +01:00
}
}
2013-07-01 06:03:00 -05:00
if (!this.effects.isEmpty()) {
NBTTagList nbttaglist = new NBTTagList();
Iterator iterator = this.effects.values().iterator();
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
2013-07-01 06:03:00 -05:00
nbttaglist.add(mobeffect.a(new NBTTagCompound()));
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
nbttagcompound.set("ActiveEffects", nbttaglist);
}
2013-07-01 06:03:00 -05:00
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
public void a(NBTTagCompound nbttagcompound) {
this.m(nbttagcompound.getFloat("AbsorptionAmount"));
if (nbttagcompound.hasKey("Attributes") && this.world != null && !this.world.isStatic) {
2013-07-08 19:43:37 -04:00
GenericAttributes.a(this.aW(), nbttagcompound.getList("Attributes"), this.world == null ? null : this.world.getLogger());
}
2013-07-01 06:03:00 -05:00
if (nbttagcompound.hasKey("ActiveEffects")) {
NBTTagList nbttaglist = nbttagcompound.getList("ActiveEffects");
2013-07-01 06:03:00 -05:00
for (int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.get(i);
MobEffect mobeffect = MobEffect.b(nbttagcompound1);
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.effects.put(Integer.valueOf(mobeffect.getEffectId()), mobeffect);
2012-03-01 10:49:23 +00:00
}
2013-07-01 06:03:00 -05:00
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
// CraftBukkit start
if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
if (nbtbase.getTypeId() == 5) {
2013-07-08 19:43:37 -04:00
this.getAttributeInstance(GenericAttributes.a).setValue((double) ((NBTTagFloat) nbtbase).data);
2013-07-01 06:03:00 -05:00
} else if (nbtbase.getTypeId() == 3) {
2013-07-08 19:43:37 -04:00
this.getAttributeInstance(GenericAttributes.a).setValue((double) ((NBTTagInt) nbtbase).data);
2012-03-01 10:49:23 +00:00
}
2013-07-01 06:03:00 -05:00
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (nbttagcompound.hasKey("HealF")) {
this.setHealth(nbttagcompound.getFloat("HealF"));
} else {
NBTBase nbtbase = nbttagcompound.get("Health");
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (nbtbase == null) {
this.setHealth(this.getMaxHealth());
2013-07-01 06:03:00 -05:00
} else if (nbtbase.getTypeId() == 5) {
this.setHealth(((NBTTagFloat) nbtbase).data);
} else if (nbtbase.getTypeId() == 2) {
this.setHealth((float) ((NBTTagShort) nbtbase).data);
2012-03-01 10:49:23 +00:00
}
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.hurtTicks = nbttagcompound.getShort("HurtTime");
this.deathTicks = nbttagcompound.getShort("DeathTime");
this.attackTicks = nbttagcompound.getShort("AttackTime");
}
2012-07-29 02:33:13 -05:00
2013-07-08 19:43:37 -04:00
protected void aI() {
2013-07-01 06:03:00 -05:00
Iterator iterator = this.effects.keySet().iterator();
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
while (iterator.hasNext()) {
Integer integer = (Integer) iterator.next();
MobEffect mobeffect = (MobEffect) this.effects.get(integer);
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (!mobeffect.tick(this)) {
if (!this.world.isStatic) {
iterator.remove();
2013-07-08 19:43:37 -04:00
this.b(mobeffect);
2013-07-01 06:03:00 -05:00
}
} else if (mobeffect.getDuration() % 600 == 0) {
2013-07-08 19:43:37 -04:00
this.a(mobeffect, false);
2013-07-01 06:03:00 -05:00
}
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
int i;
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (this.updateEffects) {
if (!this.world.isStatic) {
if (this.effects.isEmpty()) {
this.datawatcher.watch(8, Byte.valueOf((byte) 0));
this.datawatcher.watch(7, Integer.valueOf(0));
this.setInvisible(false);
} else {
i = PotionBrewer.a(this.effects.values());
this.datawatcher.watch(8, Byte.valueOf((byte) (PotionBrewer.b(this.effects.values()) ? 1 : 0)));
this.datawatcher.watch(7, Integer.valueOf(i));
this.setInvisible(this.hasEffect(MobEffectList.INVISIBILITY.id));
}
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.updateEffects = false;
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
i = this.datawatcher.getInt(7);
boolean flag = this.datawatcher.getByte(8) > 0;
2012-03-01 10:49:23 +00:00
2013-07-01 06:03:00 -05:00
if (i > 0) {
boolean flag1 = false;
2012-03-01 10:49:23 +00:00
2013-07-01 06:03:00 -05:00
if (!this.isInvisible()) {
flag1 = this.random.nextBoolean();
} else {
flag1 = this.random.nextInt(15) == 0;
}
2013-07-01 06:03:00 -05:00
if (flag) {
flag1 &= this.random.nextInt(5) == 0;
}
2013-07-01 06:03:00 -05:00
if (flag1 && i > 0) {
double d0 = (double) (i >> 16 & 255) / 255.0D;
double d1 = (double) (i >> 8 & 255) / 255.0D;
double d2 = (double) (i >> 0 & 255) / 255.0D;
2013-07-01 06:03:00 -05:00
this.world.addParticle(flag ? "mobSpellAmbient" : "mobSpell", this.locX + (this.random.nextDouble() - 0.5D) * (double) this.width, this.locY + this.random.nextDouble() * (double) this.length - (double) this.height, this.locZ + (this.random.nextDouble() - 0.5D) * (double) this.width, d0, d1, d2);
}
2013-07-01 06:03:00 -05:00
}
}
2011-11-20 00:01:14 -08:00
2013-07-08 19:43:37 -04:00
public void aJ() {
2013-07-01 06:03:00 -05:00
Iterator iterator = this.effects.keySet().iterator();
while (iterator.hasNext()) {
Integer integer = (Integer) iterator.next();
MobEffect mobeffect = (MobEffect) this.effects.get(integer);
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (!this.world.isStatic) {
iterator.remove();
2013-07-08 19:43:37 -04:00
this.b(mobeffect);
2013-07-01 06:03:00 -05:00
}
}
}
2013-07-01 06:03:00 -05:00
public Collection getEffects() {
return this.effects.values();
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
public boolean hasEffect(int i) {
// CraftBukkit - Add size check for efficiency
return this.effects.size() != 0 && this.effects.containsKey(Integer.valueOf(i));
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
public boolean hasEffect(MobEffectList mobeffectlist) {
// CraftBukkit - Add size check for efficiency
return this.effects.size() != 0 && this.effects.containsKey(Integer.valueOf(mobeffectlist.id));
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
public MobEffect getEffect(MobEffectList mobeffectlist) {
return (MobEffect) this.effects.get(Integer.valueOf(mobeffectlist.id));
}
public void addEffect(MobEffect mobeffect) {
2013-07-08 19:43:37 -04:00
if (this.d(mobeffect)) {
2013-07-01 06:03:00 -05:00
if (this.effects.containsKey(Integer.valueOf(mobeffect.getEffectId()))) {
((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId()))).a(mobeffect);
2013-07-08 19:43:37 -04:00
this.a((MobEffect) this.effects.get(Integer.valueOf(mobeffect.getEffectId())), true);
2013-07-01 06:03:00 -05:00
} else {
this.effects.put(Integer.valueOf(mobeffect.getEffectId()), mobeffect);
this.a(mobeffect);
}
}
}
2013-07-08 19:43:37 -04:00
public boolean d(MobEffect mobeffect) {
2013-07-01 06:03:00 -05:00
if (this.getMonsterType() == EnumMonsterType.UNDEAD) {
int i = mobeffect.getEffectId();
if (i == MobEffectList.REGENERATION.id || i == MobEffectList.POISON.id) {
return false;
}
}
return true;
}
2013-07-08 19:43:37 -04:00
public boolean aL() {
2013-07-01 06:03:00 -05:00
return this.getMonsterType() == EnumMonsterType.UNDEAD;
}
public void k(int i) {
MobEffect mobeffect = (MobEffect) this.effects.remove(Integer.valueOf(i));
if (mobeffect != null) {
2013-07-08 19:43:37 -04:00
this.b(mobeffect);
2013-07-01 06:03:00 -05:00
}
}
protected void a(MobEffect mobeffect) {
this.updateEffects = true;
if (!this.world.isStatic) {
2013-07-08 19:43:37 -04:00
MobEffectList.byId[mobeffect.getEffectId()].b(this, this.aW(), mobeffect.getAmplifier());
2013-07-01 06:03:00 -05:00
}
}
2013-07-08 19:43:37 -04:00
protected void a(MobEffect mobeffect, boolean flag) {
2013-07-01 06:03:00 -05:00
this.updateEffects = true;
2013-07-08 19:43:37 -04:00
if (flag && !this.world.isStatic) {
MobEffectList.byId[mobeffect.getEffectId()].a(this, this.aW(), mobeffect.getAmplifier());
MobEffectList.byId[mobeffect.getEffectId()].b(this, this.aW(), mobeffect.getAmplifier());
2013-07-01 06:03:00 -05:00
}
}
2013-07-08 19:43:37 -04:00
protected void b(MobEffect mobeffect) {
2013-07-01 06:03:00 -05:00
this.updateEffects = true;
if (!this.world.isStatic) {
2013-07-08 19:43:37 -04:00
MobEffectList.byId[mobeffect.getEffectId()].a(this, this.aW(), mobeffect.getAmplifier());
2013-07-01 06:03:00 -05:00
}
}
// CraftBukkit start - Delegate so we can handle providing a reason for health being regained
public void heal(float f) {
heal(f, EntityRegainHealthEvent.RegainReason.CUSTOM);
}
public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
float f1 = this.getHealth();
if (f1 > 0.0F) {
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.setHealth((float) (this.getHealth() + event.getAmount()));
}
}
}
public final float getHealth() {
return this.datawatcher.getFloat(6);
}
public void setHealth(float f) {
this.datawatcher.watch(6, Float.valueOf(MathHelper.a(f, 0.0F, this.getMaxHealth())));
}
public boolean damageEntity(DamageSource damagesource, float f) {
2012-11-06 06:05:28 -06:00
if (this.isInvulnerable()) {
return false;
} else if (this.world.isStatic) {
return false;
} else {
2013-07-01 06:03:00 -05:00
this.aV = 0;
if (this.getHealth() <= 0.0F) {
2011-01-29 22:50:29 +01:00
return false;
2013-03-13 17:33:27 -05:00
} else if (damagesource.m() && this.hasEffect(MobEffectList.FIRE_RESISTANCE)) {
2011-11-20 00:01:14 -08:00
return false;
2011-01-29 22:50:29 +01:00
} else {
if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(4) != null) {
2013-07-01 06:03:00 -05:00
this.getEquipment(4).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this);
f *= 0.75F;
}
2013-07-01 06:03:00 -05:00
this.aG = 1.5F;
2011-01-29 22:50:29 +01:00
boolean flag = true;
// CraftBukkit start
2013-07-01 06:03:00 -05:00
EntityDamageEvent event = CraftEventFactory.handleEntityDamageEvent(this, damagesource, f);
if (event != null) {
if (event.isCancelled()) {
return false;
}
2013-07-01 06:03:00 -05:00
f = (float) event.getDamage();
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) {
2013-07-01 06:03:00 -05:00
if (f <= this.lastDamage) {
2011-01-29 22:50:29 +01:00
return false;
}
2013-07-01 06:03:00 -05:00
this.d(damagesource, f - this.lastDamage);
this.lastDamage = f;
2011-01-29 22:50:29 +01:00
flag = false;
} else {
2013-07-01 06:03:00 -05:00
this.lastDamage = f;
this.ax = this.getHealth();
2011-01-29 22:50:29 +01:00
this.noDamageTicks = this.maxNoDamageTicks;
2013-07-01 06:03:00 -05:00
this.d(damagesource, f);
this.hurtTicks = this.az = 10;
2011-09-15 01:23:52 +01:00
}
2013-07-01 06:03:00 -05:00
this.aA = 0.0F;
2011-09-15 17:36:27 +01:00
Entity entity = damagesource.getEntity();
2011-09-15 01:23:52 +01:00
if (entity != null) {
2012-03-01 10:49:23 +00:00
if (entity instanceof EntityLiving) {
2013-07-01 06:03:00 -05:00
this.b((EntityLiving) entity);
2012-03-01 10:49:23 +00:00
}
2011-09-15 01:23:52 +01:00
if (entity instanceof EntityHuman) {
2013-03-13 17:33:27 -05:00
this.lastDamageByPlayerTime = 100;
2012-01-12 15:27:39 +00:00
this.killer = (EntityHuman) entity;
2011-09-15 01:23:52 +01:00
} else if (entity instanceof EntityWolf) {
EntityWolf entitywolf = (EntityWolf) entity;
if (entitywolf.isTamed()) {
2013-03-13 17:33:27 -05:00
this.lastDamageByPlayerTime = 100;
2012-01-12 15:27:39 +00:00
this.killer = null;
2011-09-15 01:23:52 +01:00
}
}
}
2011-01-29 22:50:29 +01:00
if (flag) {
2012-02-29 22:31:04 +01:00
this.world.broadcastEntityEffect(this, (byte) 2);
2013-03-13 17:33:27 -05:00
if (damagesource != DamageSource.DROWN) {
this.J();
2012-07-29 02:33:13 -05:00
}
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;
}
2013-07-01 06:03:00 -05:00
this.aA = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - this.yaw;
this.a(entity, f, d0, d1);
2011-01-29 22:50:29 +01:00
} else {
2013-07-01 06:03:00 -05:00
this.aA = (float) ((int) (Math.random() * 2.0D) * 180);
2011-01-29 22:50:29 +01:00
}
}
2013-07-01 06:03:00 -05:00
if (this.getHealth() <= 0.0F) {
2011-01-29 22:50:29 +01:00
if (flag) {
2013-07-08 19:43:37 -04:00
this.makeSound(this.aO(), this.aZ(), this.ba());
2011-01-29 22:50:29 +01:00
}
2011-09-15 01:23:52 +01:00
this.die(damagesource);
2011-01-29 22:50:29 +01:00
} else if (flag) {
2013-07-08 19:43:37 -04:00
this.makeSound(this.aN(), this.aZ(), this.ba());
2011-01-29 22:50:29 +01:00
}
return true;
}
}
}
2013-07-01 06:03:00 -05:00
public void a(ItemStack itemstack) {
this.makeSound("random.break", 0.8F, 0.8F + this.world.random.nextFloat() * 0.4F);
2013-07-01 06:03:00 -05:00
for (int i = 0; i < 5; ++i) {
Vec3D vec3d = this.world.getVec3DPool().create(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
2013-07-01 06:03:00 -05:00
vec3d.a(-this.pitch * 3.1415927F / 180.0F);
vec3d.b(-this.yaw * 3.1415927F / 180.0F);
Vec3D vec3d1 = this.world.getVec3DPool().create(((double) this.random.nextFloat() - 0.5D) * 0.3D, (double) (-this.random.nextFloat()) * 0.6D - 0.3D, 0.6D);
2013-07-01 06:03:00 -05:00
vec3d1.a(-this.pitch * 3.1415927F / 180.0F);
vec3d1.b(-this.yaw * 3.1415927F / 180.0F);
vec3d1 = vec3d1.add(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
this.world.addParticle("iconcrack_" + itemstack.getItem().id, vec3d1.c, vec3d1.d, vec3d1.e, vec3d.c, vec3d.d + 0.05D, vec3d.e);
}
}
2011-09-15 01:23:52 +01:00
public void die(DamageSource damagesource) {
2011-09-15 17:36:27 +01:00
Entity entity = damagesource.getEntity();
2013-07-08 19:43:37 -04:00
EntityLiving entityliving = this.aR();
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
if (this.bb >= 0 && entityliving != null) {
entityliving.b(this, this.bb);
2011-04-20 22:47:26 +02:00
}
if (entity != null) {
2012-07-29 02:33:13 -05:00
entity.a(this);
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.aU = true;
2011-01-29 22:50:29 +01:00
if (!this.world.isStatic) {
2011-11-20 00:01:14 -08:00
int i = 0;
if (entity instanceof EntityHuman) {
i = EnchantmentManager.getBonusMonsterLootEnchantmentLevel((EntityLiving) entity);
2011-11-20 00:01:14 -08:00
}
if (!this.isBaby() && this.world.getGameRules().getBoolean("doMobLoot")) {
this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
this.dropEquipment(this.lastDamageByPlayerTime > 0, i);
if (false && this.lastDamageByPlayerTime > 0) { // CraftBukkit - move rare item drop call to dropDeathLoot
int j = this.random.nextInt(200) - i;
if (j < 5) {
2012-07-29 02:33:13 -05:00
this.l(j <= 0 ? 1 : 0);
}
}
} else { // CraftBukkit
CraftEventFactory.callEntityDeathEvent(this); // CraftBukkit
2011-11-20 00:01:14 -08:00
}
}
2011-01-29 22:50:29 +01:00
2012-02-29 22:31:04 +01:00
this.world.broadcastEntityEffect(this, (byte) 3);
}
2013-07-01 06:03:00 -05:00
protected void dropEquipment(boolean flag, int i) {}
2013-07-01 06:03:00 -05:00
public void a(Entity entity, float f, double d0, double d1) {
2013-07-08 19:43:37 -04:00
if (this.random.nextDouble() >= this.getAttributeInstance(GenericAttributes.c).getValue()) {
2013-07-01 06:03:00 -05:00
this.an = true;
float f1 = MathHelper.sqrt(d0 * d0 + d1 * d1);
float f2 = 0.4F;
2013-07-01 06:03:00 -05:00
this.motX /= 2.0D;
this.motY /= 2.0D;
this.motZ /= 2.0D;
this.motX -= d0 / (double) f1 * (double) f2;
this.motY += (double) f2;
this.motZ -= d1 / (double) f1 * (double) f2;
if (this.motY > 0.4000000059604645D) {
this.motY = 0.4000000059604645D;
2011-11-20 00:01:14 -08:00
}
}
2013-07-01 06:03:00 -05:00
}
2013-07-08 19:43:37 -04:00
protected String aN() {
2013-07-01 06:03:00 -05:00
return "damage.hit";
}
2013-07-08 19:43:37 -04:00
protected String aO() {
2013-07-01 06:03:00 -05:00
return "damage.hit";
}
2013-07-01 06:03:00 -05:00
// CraftBukkit start - Change return type to ItemStack
protected ItemStack l(int i) {
return null;
}
2013-07-01 06:03:00 -05:00
// CraftBukkit end
2013-07-01 06:03:00 -05:00
protected void dropDeathLoot(boolean flag, int i) {}
public boolean e() {
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.boundingBox.b);
int k = MathHelper.floor(this.locZ);
int l = this.world.getTypeId(i, j, k);
return l == Block.LADDER.id || l == Block.VINE.id;
}
2013-07-01 06:03:00 -05:00
public boolean isAlive() {
return !this.dead && this.getHealth() > 0.0F;
}
2013-07-01 06:03:00 -05:00
protected void b(float f) {
super.b(f);
MobEffect mobeffect = this.getEffect(MobEffectList.JUMP);
float f1 = mobeffect != null ? (float) (mobeffect.getAmplifier() + 1) : 0.0F;
// CraftBukkit start
2013-07-01 06:03:00 -05:00
float i = MathHelper.f(f - 3.0F - f1);
2011-01-29 22:50:29 +01:00
if (i > 0) {
EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, this, EntityDamageEvent.DamageCause.FALL, i);
if (event.isCancelled()) {
return;
}
2013-07-01 06:03:00 -05:00
i = (float) event.getDamage();
if (i > 0) {
this.getBukkitEntity().setLastDamageCause(event);
}
}
// CraftBukkit end
2012-07-29 02:33:13 -05:00
if (i > 0) {
if (i > 4) {
this.makeSound("damage.fallbig", 1.0F, 1.0F);
} else {
this.makeSound("damage.fallsmall", 1.0F, 1.0F);
2011-01-20 00:10:47 -08:00
}
2012-07-29 02:33:13 -05:00
2013-07-01 06:03:00 -05:00
this.damageEntity(DamageSource.FALL, (float) i);
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;
2012-11-06 06:05:28 -06:00
this.makeSound(stepsound.getStepSound(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F);
}
}
}
2013-07-08 19:43:37 -04:00
public int aP() {
2013-07-01 06:03:00 -05:00
int i = 0;
ItemStack[] aitemstack = this.getEquipment();
int j = aitemstack.length;
2013-07-01 06:03:00 -05:00
for (int k = 0; k < j; ++k) {
ItemStack itemstack = aitemstack[k];
2013-07-01 06:03:00 -05:00
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
int l = ((ItemArmor) itemstack.getItem()).c;
2013-07-01 06:03:00 -05:00
i += l;
}
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
return i;
}
2012-03-01 10:49:23 +00:00
2013-07-01 06:03:00 -05:00
protected void h(float f) {}
2012-03-01 10:49:23 +00:00
2013-07-01 06:03:00 -05:00
protected float b(DamageSource damagesource, float f) {
if (!damagesource.ignoresArmor()) {
2013-07-08 19:43:37 -04:00
int i = 25 - this.aP();
2013-07-01 06:03:00 -05:00
float f1 = f * (float) i;
2013-07-01 06:03:00 -05:00
this.h(f);
f = f1 / 25.0F;
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
return f;
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
protected float c(DamageSource damagesource, float f) {
if (this instanceof EntityZombie) {
f = f;
}
2011-05-26 13:48:22 +01:00
2013-07-01 06:03:00 -05:00
int i;
int j;
float f1;
2011-05-26 13:48:22 +01:00
2013-07-01 06:03:00 -05:00
if (this.hasEffect(MobEffectList.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
i = (this.getEffect(MobEffectList.RESISTANCE).getAmplifier() + 1) * 5;
j = 25 - i;
f1 = f * (float) j;
f = f1 / 25.0F;
}
2011-05-26 13:48:22 +01:00
2013-07-01 06:03:00 -05:00
if (f <= 0.0F) {
return 0.0F;
} else {
i = EnchantmentManager.a(this.getEquipment(), damagesource);
if (i > 20) {
i = 20;
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (i > 0 && i <= 20) {
j = 25 - i;
f1 = f * (float) j;
f = f1 / 25.0F;
2012-11-06 06:05:28 -06:00
}
2013-07-01 06:03:00 -05:00
return f;
}
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
protected void d(DamageSource damagesource, float f) {
if (!this.isInvulnerable()) {
f = this.b(damagesource, f);
f = this.c(damagesource, f);
float f1 = f;
2011-01-29 22:50:29 +01:00
2013-07-08 19:43:37 -04:00
f = Math.max(f - this.bm(), 0.0F);
this.m(this.bm() - (f1 - f));
2013-07-01 06:03:00 -05:00
if (f != 0.0F) {
float f2 = this.getHealth();
this.setHealth(f2 - f);
2013-07-08 19:43:37 -04:00
this.aQ().a(damagesource, f2, f);
this.m(this.bm() - f);
2013-07-01 06:03:00 -05:00
}
}
2013-07-01 06:03:00 -05:00
}
2011-01-29 22:50:29 +01:00
2013-07-08 19:43:37 -04:00
public CombatTracker aQ() {
2013-07-01 06:03:00 -05:00
return this.combatTracker;
}
2013-07-08 19:43:37 -04:00
public EntityLiving aR() {
2013-07-01 06:03:00 -05:00
return (EntityLiving) (this.combatTracker.c() != null ? this.combatTracker.c() : (this.killer != null ? this.killer : (this.lastDamager != null ? this.lastDamager : null)));
}
2013-07-01 06:03:00 -05:00
public final float getMaxHealth() {
2013-07-08 19:43:37 -04:00
return (float) this.getAttributeInstance(GenericAttributes.a).getValue();
}
2013-07-08 19:43:37 -04:00
public final int aT() {
2013-07-01 06:03:00 -05:00
return this.datawatcher.getByte(9);
}
2012-10-28 23:55:40 -04:00
2013-07-01 06:03:00 -05:00
public final void m(int i) {
this.datawatcher.watch(9, Byte.valueOf((byte) i));
}
2013-07-01 06:03:00 -05:00
private int h() {
return this.hasEffect(MobEffectList.FASTER_DIG) ? 6 - (1 + this.getEffect(MobEffectList.FASTER_DIG).getAmplifier()) * 1 : (this.hasEffect(MobEffectList.SLOWER_DIG) ? 6 + (1 + this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier()) * 2 : 6);
}
2013-07-08 19:43:37 -04:00
public void aU() {
2013-07-01 06:03:00 -05:00
if (!this.au || this.av >= this.h() / 2 || this.av < 0) {
this.av = -1;
this.au = true;
if (this.world instanceof WorldServer) {
((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new Packet18ArmAnimation(this, 1)));
}
}
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
protected void B() {
this.damageEntity(DamageSource.OUT_OF_WORLD, 4.0F);
}
2011-09-15 01:23:52 +01:00
2013-07-08 19:43:37 -04:00
protected void aV() {
2013-07-01 06:03:00 -05:00
int i = this.h();
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
if (this.au) {
++this.av;
if (this.av >= i) {
this.av = 0;
this.au = false;
2011-09-15 01:23:52 +01:00
}
2013-07-01 06:03:00 -05:00
} else {
this.av = 0;
}
2013-07-01 06:03:00 -05:00
this.aE = (float) this.av / (float) i;
}
2013-07-08 19:43:37 -04:00
public AttributeInstance getAttributeInstance(IAttribute iattribute) {
return this.aW().a(iattribute);
2013-07-01 06:03:00 -05:00
}
2013-07-08 19:43:37 -04:00
public AttributeMapBase aW() {
2013-07-01 06:03:00 -05:00
if (this.d == null) {
2013-07-08 19:43:37 -04:00
this.d = new AttributeMapServer();
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
return this.d;
}
2013-07-01 06:03:00 -05:00
public EnumMonsterType getMonsterType() {
return EnumMonsterType.UNDEFINED;
}
2013-07-08 19:43:37 -04:00
public abstract ItemStack aY();
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
public abstract ItemStack getEquipment(int i);
2013-07-01 06:03:00 -05:00
public abstract void setEquipment(int i, ItemStack itemstack);
2013-07-01 06:03:00 -05:00
public void setSprinting(boolean flag) {
super.setSprinting(flag);
2013-07-08 19:43:37 -04:00
AttributeInstance attributeinstance = this.getAttributeInstance(GenericAttributes.d);
2011-09-15 01:23:52 +01:00
2013-07-08 19:43:37 -04:00
if (attributeinstance.a(b) != null) {
2013-07-01 06:03:00 -05:00
attributeinstance.b(c);
2013-07-08 19:43:37 -04:00
}
if (flag) {
attributeinstance.a(c);
2011-09-15 01:23:52 +01:00
}
}
2013-07-01 06:03:00 -05:00
public abstract ItemStack[] getEquipment();
2013-07-08 19:43:37 -04:00
protected float aZ() {
2013-07-01 06:03:00 -05:00
return 1.0F;
}
2013-07-08 19:43:37 -04:00
protected float ba() {
2013-07-01 06:03:00 -05:00
return this.isBaby() ? (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.5F : (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F;
2012-01-12 23:10:13 +01:00
}
2013-07-08 19:43:37 -04:00
protected boolean bb() {
2013-07-01 06:03:00 -05:00
return this.getHealth() <= 0.0F;
2012-01-12 23:10:13 +01:00
}
2013-07-01 06:03:00 -05:00
public void enderTeleportTo(double d0, double d1, double d2) {
this.setPositionRotation(d0, d1, d2, this.yaw, this.pitch);
}
2013-07-01 06:03:00 -05:00
public void l(Entity entity) {
double d0 = entity.locX;
double d1 = entity.boundingBox.b + (double) entity.length;
double d2 = entity.locZ;
for (double d3 = -1.5D; d3 < 2.0D; ++d3) {
for (double d4 = -1.5D; d4 < 2.0D; ++d4) {
if (d3 != 0.0D || d4 != 0.0D) {
int i = (int) (this.locX + d3);
int j = (int) (this.locZ + d4);
AxisAlignedBB axisalignedbb = this.boundingBox.c(d3, 1.0D, d4);
if (this.world.a(axisalignedbb).isEmpty()) {
if (this.world.w(i, (int) this.locY, j)) {
this.enderTeleportTo(this.locX + d3, this.locY + 1.0D, this.locZ + d4);
return;
}
2013-07-01 06:03:00 -05:00
if (this.world.w(i, (int) this.locY - 1, j) || this.world.getMaterial(i, (int) this.locY - 1, j) == Material.WATER) {
d0 = this.locX + d3;
d1 = this.locY + 1.0D;
d2 = this.locZ + d4;
}
2012-07-29 02:33:13 -05:00
}
}
}
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
this.enderTeleportTo(d0, d1, d2);
2011-02-23 02:37:56 +00:00
}
2013-07-08 19:43:37 -04:00
protected void bd() {
2011-01-29 22:50:29 +01:00
this.motY = 0.41999998688697815D;
2011-11-20 00:01:14 -08:00
if (this.hasEffect(MobEffectList.JUMP)) {
this.motY += (double) ((float) (this.getEffect(MobEffectList.JUMP).getAmplifier() + 1) * 0.1F);
}
if (this.isSprinting()) {
2011-09-15 01:23:52 +01:00
float f = this.yaw * 0.017453292F;
this.motX -= (double) (MathHelper.sin(f) * 0.2F);
this.motZ += (double) (MathHelper.cos(f) * 0.2F);
}
2013-03-13 17:33:27 -05:00
this.an = true;
}
2013-07-01 06:03:00 -05:00
public void e(float f, float f1) {
double d0;
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (this.G() && (!(this instanceof EntityHuman) || !((EntityHuman) this).abilities.isFlying)) {
d0 = this.locY;
2013-07-08 19:43:37 -04:00
this.a(f, f1, this.be() ? 0.04F : 0.02F);
2013-07-01 06:03:00 -05:00
this.move(this.motX, this.motY, this.motZ);
this.motX *= 0.800000011920929D;
this.motY *= 0.800000011920929D;
this.motZ *= 0.800000011920929D;
this.motY -= 0.02D;
if (this.positionChanged && this.c(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
this.motY = 0.30000001192092896D;
}
} else if (this.I() && (!(this instanceof EntityHuman) || !((EntityHuman) this).abilities.isFlying)) {
d0 = this.locY;
this.a(f, f1, 0.02F);
this.move(this.motX, this.motY, this.motZ);
this.motX *= 0.5D;
this.motY *= 0.5D;
this.motZ *= 0.5D;
this.motY -= 0.02D;
if (this.positionChanged && this.c(this.motX, this.motY + 0.6000000238418579D - this.locY + d0, this.motZ)) {
this.motY = 0.30000001192092896D;
}
} else {
2013-07-01 06:03:00 -05:00
float f2 = 0.91F;
2012-01-12 23:10:13 +01:00
2013-07-01 06:03:00 -05: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));
2012-03-01 10:49:23 +00:00
2013-07-01 06:03:00 -05:00
if (i > 0) {
f2 = Block.byId[i].frictionFactor * 0.91F;
}
}
2013-07-01 06:03:00 -05:00
float f3 = 0.16277136F / (f2 * f2 * f2);
float f4;
2013-07-01 06:03:00 -05:00
if (this.onGround) {
2013-07-08 19:43:37 -04:00
f4 = this.bf() * f3;
} else {
2013-07-01 06:03:00 -05:00
f4 = this.aR;
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
this.a(f, f1, f4);
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));
2013-07-01 06:03:00 -05:00
if (j > 0) {
f2 = Block.byId[j].frictionFactor * 0.91F;
}
}
2013-07-01 06:03:00 -05:00
if (this.e()) {
float f5 = 0.15F;
2013-07-01 06:03:00 -05:00
if (this.motX < (double) (-f5)) {
this.motX = (double) (-f5);
}
2011-01-29 22:50:29 +01:00
2013-07-01 06:03:00 -05:00
if (this.motX > (double) f5) {
this.motX = (double) f5;
}
2013-07-01 06:03:00 -05:00
if (this.motZ < (double) (-f5)) {
this.motZ = (double) (-f5);
}
2011-02-23 02:37:56 +00:00
2013-07-01 06:03:00 -05:00
if (this.motZ > (double) f5) {
this.motZ = (double) f5;
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
this.fallDistance = 0.0F;
if (this.motY < -0.15D) {
this.motY = -0.15D;
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
boolean flag = this.isSneaking() && this instanceof EntityHuman;
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
if (flag && this.motY < 0.0D) {
this.motY = 0.0D;
2012-11-06 06:05:28 -06:00
}
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
this.move(this.motX, this.motY, this.motZ);
if (this.positionChanged && this.e()) {
this.motY = 0.2D;
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
if (this.world.isStatic && (!this.world.isLoaded((int) this.locX, 0, (int) this.locZ) || !this.world.getChunkAtWorldCoords((int) this.locX, (int) this.locZ).d)) {
if (this.locY > 0.0D) {
this.motY = -0.1D;
2012-07-29 02:33:13 -05:00
} else {
2013-07-01 06:03:00 -05:00
this.motY = 0.0D;
2011-11-20 00:01:14 -08:00
}
} else {
2013-07-01 06:03:00 -05:00
this.motY -= 0.08D;
2011-09-15 01:23:52 +01:00
}
2013-07-01 06:03:00 -05:00
this.motY *= 0.9800000190734863D;
this.motX *= (double) f2;
this.motZ *= (double) f2;
2011-09-15 01:23:52 +01:00
}
2013-07-01 06:03:00 -05:00
this.aF = this.aG;
d0 = this.locX - this.lastX;
double d1 = this.locZ - this.lastZ;
float f6 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
if (f6 > 1.0F) {
f6 = 1.0F;
2011-11-20 00:01:14 -08:00
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
this.aG += (f6 - this.aG) * 0.4F;
this.aH += this.aG;
2011-11-20 00:01:14 -08:00
}
2013-07-08 19:43:37 -04:00
protected boolean be() {
2013-07-01 06:03:00 -05:00
return false;
2011-11-20 00:01:14 -08:00
}
2013-07-08 19:43:37 -04:00
public float bf() {
return this.be() ? this.bp : 0.1F;
}
2013-07-01 06:03:00 -05:00
public void i(float f) {
2013-07-08 19:43:37 -04:00
this.bp = f;
2011-11-20 00:01:14 -08:00
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
public boolean m(Entity entity) {
this.k(entity);
return false;
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
public boolean isSleeping() {
return false;
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
public void l_() {
super.l_();
if (!this.world.isStatic) {
2013-07-08 19:43:37 -04:00
int i = this.aT();
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
if (i > 0) {
if (this.aw <= 0) {
this.aw = 20 * (30 - i);
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
--this.aw;
if (this.aw <= 0) {
this.m(i - 1);
}
}
2011-09-15 01:23:52 +01:00
2013-07-01 06:03:00 -05:00
for (int j = 0; j < 5; ++j) {
ItemStack itemstack = this.g[j];
ItemStack itemstack1 = this.getEquipment(j);
2013-03-13 17:33:27 -05:00
2013-07-01 06:03:00 -05:00
if (!ItemStack.matches(itemstack1, itemstack)) {
((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (new Packet5EntityEquipment(this.id, j, itemstack1)));
if (itemstack != null) {
this.d.a(itemstack.D());
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
if (itemstack1 != null) {
this.d.b(itemstack1.D());
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
this.g[j] = itemstack1 == null ? null : itemstack1.cloneItemStack();
}
}
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
this.c();
double d0 = this.locX - this.lastX;
double d1 = this.locZ - this.lastZ;
float f = (float) (d0 * d0 + d1 * d1);
float f1 = this.aN;
float f2 = 0.0F;
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
this.aW = this.aX;
float f3 = 0.0F;
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
if (f > 0.0025000002F) {
f3 = 1.0F;
f2 = (float) Math.sqrt((double) f) * 3.0F;
// CraftBukkit - Math -> TrigMath
f1 = (float) org.bukkit.craftbukkit.TrigMath.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
if (this.aE > 0.0F) {
f1 = this.yaw;
}
2011-11-20 00:01:14 -08:00
2013-07-01 06:03:00 -05:00
if (!this.onGround) {
f3 = 0.0F;
}
2013-07-01 06:03:00 -05:00
this.aX += (f3 - this.aX) * 0.3F;
this.world.methodProfiler.a("headTurn");
f2 = this.f(f1, f2);
this.world.methodProfiler.b();
this.world.methodProfiler.a("rangeChecks");
2013-07-01 06:03:00 -05:00
while (this.yaw - this.lastYaw < -180.0F) {
this.lastYaw -= 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.yaw - this.lastYaw >= 180.0F) {
this.lastYaw += 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.aN - this.aO < -180.0F) {
this.aO -= 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.aN - this.aO >= 180.0F) {
this.aO += 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.pitch - this.lastPitch < -180.0F) {
this.lastPitch -= 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.pitch - this.lastPitch >= 180.0F) {
this.lastPitch += 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.aP - this.aQ < -180.0F) {
this.aQ -= 360.0F;
}
2013-07-01 06:03:00 -05:00
while (this.aP - this.aQ >= 180.0F) {
this.aQ += 360.0F;
}
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
this.aY += f2;
}
2013-07-01 06:03:00 -05:00
protected float f(float f, float f1) {
float f2 = MathHelper.g(f - this.aN);
2013-07-01 06:03:00 -05:00
this.aN += f2 * 0.3F;
float f3 = MathHelper.g(this.yaw - this.aN);
boolean flag = f3 < -90.0F || f3 >= 90.0F;
2013-07-01 06:03:00 -05:00
if (f3 < -75.0F) {
f3 = -75.0F;
}
2013-07-01 06:03:00 -05:00
if (f3 >= 75.0F) {
f3 = 75.0F;
2011-11-20 00:01:14 -08:00
}
2013-07-01 06:03:00 -05:00
this.aN = this.yaw - f3;
if (f3 * f3 > 2500.0F) {
this.aN += f3 * 0.2F;
}
2013-07-01 06:03:00 -05:00
if (flag) {
f1 *= -1.0F;
}
2013-07-01 06:03:00 -05:00
return f1;
}
2013-07-01 06:03:00 -05:00
public void c() {
2013-07-08 19:43:37 -04:00
if (this.bq > 0) {
--this.bq;
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
if (this.bh > 0) {
double d0 = this.locX + (this.bi - this.locX) / (double) this.bh;
double d1 = this.locY + (this.bj - this.locY) / (double) this.bh;
double d2 = this.locZ + (this.bk - this.locZ) / (double) this.bh;
double d3 = MathHelper.g(this.bl - (double) this.yaw);
2013-07-01 06:03:00 -05:00
this.yaw = (float) ((double) this.yaw + d3 / (double) this.bh);
this.pitch = (float) ((double) this.pitch + (this.bm - (double) this.pitch) / (double) this.bh);
--this.bh;
this.setPosition(d0, d1, d2);
this.b(this.yaw, this.pitch);
2013-07-08 19:43:37 -04:00
} else if (!this.bl()) {
2013-07-01 06:03:00 -05:00
this.motX *= 0.98D;
this.motY *= 0.98D;
this.motZ *= 0.98D;
}
2013-07-01 06:03:00 -05:00
if (Math.abs(this.motX) < 0.005D) {
this.motX = 0.0D;
}
2013-07-01 06:03:00 -05:00
if (Math.abs(this.motY) < 0.005D) {
this.motY = 0.0D;
}
2013-07-01 06:03:00 -05:00
if (Math.abs(this.motZ) < 0.005D) {
this.motZ = 0.0D;
}
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.a("ai");
2013-07-08 19:43:37 -04:00
if (this.bb()) {
2013-07-01 06:03:00 -05:00
this.bd = false;
this.be = 0.0F;
this.bf = 0.0F;
this.bg = 0.0F;
2013-07-08 19:43:37 -04:00
} else if (this.bl()) {
if (this.be()) {
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.a("newAi");
2013-07-08 19:43:37 -04:00
this.bh();
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
} else {
this.world.methodProfiler.a("oldAi");
2013-07-08 19:43:37 -04:00
this.bk();
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
this.aP = this.yaw;
}
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
this.world.methodProfiler.a("jump");
if (this.bd) {
if (!this.G() && !this.I()) {
2013-07-08 19:43:37 -04:00
if (this.onGround && this.bq == 0) {
this.bd();
this.bq = 10;
2013-07-01 06:03:00 -05:00
}
} else {
this.motY += 0.03999999910593033D;
}
2013-07-01 06:03:00 -05:00
} else {
2013-07-08 19:43:37 -04:00
this.bq = 0;
2013-07-01 06:03:00 -05:00
}
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
this.world.methodProfiler.a("travel");
this.be *= 0.98F;
this.bf *= 0.98F;
this.bg *= 0.9F;
this.e(this.be, this.bf);
this.world.methodProfiler.b();
this.world.methodProfiler.a("push");
if (!this.world.isStatic) {
2013-07-08 19:43:37 -04:00
this.bi();
}
2013-07-01 06:03:00 -05:00
this.world.methodProfiler.b();
}
2013-07-08 19:43:37 -04:00
protected void bh() {}
2013-07-08 19:43:37 -04:00
protected void bi() {
2013-07-01 06:03:00 -05:00
List list = this.world.getEntities(this, this.boundingBox.grow(0.20000000298023224D, 0.0D, 0.20000000298023224D));
2013-07-01 06:03:00 -05:00
if (list != null && !list.isEmpty()) {
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
2013-07-01 06:03:00 -05:00
// TODO better check now?
// CraftBukkit start - Only handle mob (non-player) collisions every other tick
if (entity instanceof EntityLiving && !(this instanceof EntityPlayer) && this.ticksLived % 2 == 0) {
continue;
}
2013-07-01 06:03:00 -05:00
// CraftBukkit end
2013-07-01 06:03:00 -05:00
if (entity.L()) {
this.n(entity);
}
}
2013-07-01 06:03:00 -05:00
}
}
2013-07-01 06:03:00 -05:00
protected void n(Entity entity) {
entity.collide(this);
}
2013-07-08 19:43:37 -04:00
public void U() {
super.U();
2013-07-01 06:03:00 -05:00
this.aW = this.aX;
this.aX = 0.0F;
this.fallDistance = 0.0F;
}
2013-07-08 19:43:37 -04:00
protected void bj() {}
2013-07-08 19:43:37 -04:00
protected void bk() {
2013-07-01 06:03:00 -05:00
++this.aV;
}
2013-07-01 06:03:00 -05:00
public void f(boolean flag) {
this.bd = flag;
}
2013-07-01 06:03:00 -05:00
public void receive(Entity entity, int i) {
if (!entity.dead && !this.world.isStatic) {
EntityTracker entitytracker = ((WorldServer) this.world).getTracker();
2013-07-01 06:03:00 -05:00
if (entity instanceof EntityItem) {
entitytracker.a(entity, (Packet) (new Packet22Collect(entity.id, this.id)));
}
2013-07-01 06:03:00 -05:00
if (entity instanceof EntityArrow) {
entitytracker.a(entity, (Packet) (new Packet22Collect(entity.id, this.id)));
}
2013-07-01 06:03:00 -05:00
if (entity instanceof EntityExperienceOrb) {
entitytracker.a(entity, (Packet) (new Packet22Collect(entity.id, this.id)));
}
}
}
2013-07-01 06:03:00 -05:00
public boolean o(Entity entity) {
return this.world.a(this.world.getVec3DPool().create(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ), this.world.getVec3DPool().create(entity.locX, entity.locY + (double) entity.getHeadHeight(), entity.locZ)) == null;
}
2012-11-06 06:05:28 -06:00
2013-07-08 19:43:37 -04:00
public Vec3D Z() {
2013-07-01 06:03:00 -05:00
return this.j(1.0F);
2012-11-06 06:05:28 -06:00
}
2013-07-01 06:03:00 -05:00
public Vec3D j(float f) {
float f1;
float f2;
float f3;
float f4;
2013-03-13 17:33:27 -05:00
2013-07-01 06:03:00 -05: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 this.world.getVec3DPool().create((double) (f2 * f3), (double) f4, (double) (f1 * f3));
} else {
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);
2013-03-13 17:33:27 -05:00
2013-07-01 06:03:00 -05:00
return this.world.getVec3DPool().create((double) (f4 * f5), (double) f6, (double) (f3 * f5));
}
2013-03-13 17:33:27 -05:00
}
2013-07-08 19:43:37 -04:00
public boolean bl() {
2013-07-01 06:03:00 -05:00
return !this.world.isStatic;
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
public boolean K() {
return !this.dead;
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
public boolean L() {
return !this.dead;
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
public float getHeadHeight() {
return this.length * 0.85F;
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
protected void J() {
2013-07-08 19:43:37 -04:00
this.velocityChanged = this.random.nextDouble() >= this.getAttributeInstance(GenericAttributes.c).getValue();
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
public float getHeadRotation() {
return this.aP;
2013-03-13 17:33:27 -05:00
}
2013-07-08 19:43:37 -04:00
public float bm() {
return this.br;
2013-03-13 17:33:27 -05:00
}
2013-07-01 06:03:00 -05:00
public void m(float f) {
if (f < 0.0F) {
f = 0.0F;
}
2013-04-27 04:40:05 -05:00
2013-07-08 19:43:37 -04:00
this.br = f;
}
public ScoreboardTeamBase getScoreboardTeam() {
return null;
}
public boolean c(EntityLiving entityliving) {
return this.a(entityliving.getScoreboardTeam());
}
public boolean a(ScoreboardTeamBase scoreboardteambase) {
return this.getScoreboardTeam() != null ? this.getScoreboardTeam().isAlly(scoreboardteambase) : false;
2013-04-27 04:40:05 -05:00
}
}