2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityLiving.java
+++ b/net/minecraft/server/EntityLiving.java
2016-11-17 02:41:03 +01:00
@@ -13,6 +13,24 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
+import java.util.ArrayList;
+import com.google.common.base.Function;
2015-02-12 15:00:40 +01:00
+import com.google.common.collect.Lists;
2016-04-08 11:06:31 +02:00
+import org.bukkit.Location;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
2016-11-17 02:41:03 +01:00
+import org.bukkit.entity.LivingEntity;
2016-02-29 22:32:46 +01:00
+import org.bukkit.entity.Player;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
2016-11-17 02:41:03 +01:00
+import org.bukkit.event.entity.EntityResurrectEvent;
2016-04-08 11:06:31 +02:00
+import org.bukkit.event.entity.EntityTeleportEvent;
2016-02-29 22:32:46 +01:00
+import org.bukkit.event.player.PlayerItemConsumeEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
public abstract class EntityLiving extends Entity {
2016-11-17 02:41:03 +01:00
private static final Logger a = LogManager.getLogger();
2017-05-14 04:00:00 +02:00
@@ -88,6 +106,14 @@
private BlockPosition bF;
private DamageSource bG;
private long bH;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ public int expToDrop;
+ public int maxAirTicks = 300;
2016-03-08 07:58:52 +01:00
+ boolean forceDrops;
2016-03-07 09:51:42 +01:00
+ ArrayList<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>();
+ public org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
2016-03-27 11:19:41 +02:00
+ public boolean collides = true;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
public void killEntity() {
2014-11-25 22:32:16 +01:00
this.damageEntity(DamageSource.OUT_OF_WORLD, Float.MAX_VALUE);
2017-05-14 04:00:00 +02:00
@@ -102,7 +128,8 @@
2016-11-17 02:41:03 +01:00
this.updateEffects = true;
this.activeItem = ItemStack.a;
2015-02-26 23:41:06 +01:00
this.initAttributes();
2014-11-25 22:32:16 +01:00
- this.setHealth(this.getMaxHealth());
+ // CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
2016-02-29 22:32:46 +01:00
+ this.datawatcher.set(EntityLiving.HEALTH, (float) this.getAttributeInstance(GenericAttributes.maxHealth).getValue());
this.i = true;
2016-11-17 02:41:03 +01:00
this.aM = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
2014-11-25 22:32:16 +01:00
this.setPosition(this.locX, this.locY, this.locZ);
2017-05-14 04:00:00 +02:00
@@ -140,7 +167,13 @@
2016-02-29 22:32:46 +01:00
double d1 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
2014-11-25 22:32:16 +01:00
int i = (int) (150.0D * d1);
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
- ((WorldServer) this.world).a(EnumParticle.BLOCK_DUST, this.locX, this.locY, this.locZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { Block.getCombinedId(iblockdata)});
+ // CraftBukkit start - visiblity api
+ if (this instanceof EntityPlayer) {
+ ((WorldServer) this.world).sendParticles((EntityPlayer) this, EnumParticle.BLOCK_DUST, false, this.locX, this.locY, this.locZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { Block.getCombinedId(iblockdata)});
+ } else {
2015-02-26 23:41:06 +01:00
+ ((WorldServer) this.world).a(EnumParticle.BLOCK_DUST, this.locX, this.locY, this.locZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { Block.getCombinedId(iblockdata)});
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
}
}
2017-05-14 04:00:00 +02:00
@@ -202,7 +235,11 @@
2016-02-29 22:32:46 +01:00
this.stopRiding();
2015-02-26 23:41:06 +01:00
}
} else {
- this.setAirTicks(300);
+ // CraftBukkit start - Only set if needed to work around a DataWatcher inefficiency
+ if (this.getAirTicks() != 300) {
+ this.setAirTicks(maxAirTicks);
+ }
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
if (!this.world.isClientSide) {
2017-05-14 04:00:00 +02:00
@@ -259,6 +296,18 @@
2014-11-25 22:32:16 +01:00
this.world.methodProfiler.b();
}
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ public int getExpReward() {
+ int exp = this.getExpValue(this.killer);
+
2016-02-29 22:32:46 +01:00
+ if (!this.world.isClientSide && (this.lastDamageByPlayerTime > 0 || this.alwaysGivesExp()) && this.isDropExperience() && this.world.getGameRules().getBoolean("doMobLoot")) {
2014-11-25 22:32:16 +01:00
+ return exp;
+ } else {
+ return 0;
+ }
+ }
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
protected void b(BlockPosition blockposition) {
int i = EnchantmentManager.a(Enchantments.j, this);
2014-11-25 22:32:16 +01:00
2017-05-14 04:00:00 +02:00
@@ -274,19 +323,19 @@
2016-02-29 22:32:46 +01:00
2017-06-08 10:00:00 +02:00
protected void bO() {
2014-11-25 22:32:16 +01:00
++this.deathTicks;
- if (this.deathTicks == 20) {
+ if (this.deathTicks >= 20 && !this.dead) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
int i;
2016-02-29 22:32:46 +01:00
- if (!this.world.isClientSide && (this.alwaysGivesExp() || this.lastDamageByPlayerTime > 0 && this.isDropExperience() && this.world.getGameRules().getBoolean("doMobLoot"))) {
2014-11-25 22:32:16 +01:00
- i = this.getExpValue(this.killer);
2017-05-14 04:00:00 +02:00
-
- while (i > 0) {
- int j = EntityExperienceOrb.getOrbValue(i);
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
+ i = this.expToDrop;
+ while (i > 0) {
+ int j = EntityExperienceOrb.getOrbValue(i);
2014-11-25 22:32:16 +01:00
- i -= j;
- this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
- }
+ i -= j;
+ this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
}
+ this.expToDrop = 0;
+ // CraftBukkit end
this.die();
2017-05-14 04:00:00 +02:00
@@ -442,6 +491,17 @@
2014-11-25 22:32:16 +01:00
}
}
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
+ NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
+ if (nbtbase.getTypeId() == 5) {
2016-11-17 02:41:03 +01:00
+ this.getAttributeInstance(GenericAttributes.maxHealth).setValue(((NBTTagFloat) nbtbase).asDouble());
2014-11-25 22:32:16 +01:00
+ } else if (nbtbase.getTypeId() == 3) {
2016-11-17 02:41:03 +01:00
+ this.getAttributeInstance(GenericAttributes.maxHealth).setValue(((NBTTagInt) nbtbase).asDouble());
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
if (nbttagcompound.hasKeyOfType("Health", 99)) {
this.setHealth(nbttagcompound.getFloat("Health"));
}
2017-05-14 04:00:00 +02:00
@@ -464,9 +524,15 @@
2016-02-29 22:32:46 +01:00
2015-02-12 15:00:40 +01:00
}
+ // CraftBukkit start
+ private boolean isTickingEffects = false;
+ private List<Object> effectsToProcess = Lists.newArrayList();
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
protected void tickPotionEffects() {
2015-02-12 15:00:40 +01:00
Iterator iterator = this.effects.keySet().iterator();
2015-02-26 23:41:06 +01:00
2015-02-12 15:00:40 +01:00
+ isTickingEffects = true; // CraftBukkit
2016-11-17 02:41:03 +01:00
try {
while (iterator.hasNext()) {
MobEffectList mobeffectlist = (MobEffectList) iterator.next();
2017-05-14 04:00:00 +02:00
@@ -484,6 +550,17 @@
2016-11-17 02:41:03 +01:00
} catch (ConcurrentModificationException concurrentmodificationexception) {
;
2015-02-12 15:00:40 +01:00
}
+ // CraftBukkit start
+ isTickingEffects = false;
+ for (Object e : effectsToProcess) {
+ if (e instanceof MobEffect) {
+ addEffect((MobEffect) e);
+ } else {
2016-02-29 22:32:46 +01:00
+ removeEffect((MobEffectList) e);
2015-02-12 15:00:40 +01:00
+ }
+ }
2017-01-02 03:51:16 +01:00
+ effectsToProcess.clear();
2015-02-12 15:00:40 +01:00
+ // CraftBukkit end
if (this.updateEffects) {
2015-02-26 23:41:06 +01:00
if (!this.world.isClientSide) {
2017-05-14 04:00:00 +02:00
@@ -585,6 +662,12 @@
2015-02-12 15:00:40 +01:00
}
public void addEffect(MobEffect mobeffect) {
+ // CraftBukkit start
+ if (isTickingEffects) {
+ effectsToProcess.add(mobeffect);
+ return;
+ }
+ // CraftBukkit end
if (this.d(mobeffect)) {
2016-02-29 22:32:46 +01:00
MobEffect mobeffect1 = (MobEffect) this.effects.get(mobeffect.getMobEffect());
2017-05-14 04:00:00 +02:00
@@ -617,6 +700,12 @@
2015-02-12 15:00:40 +01:00
2016-05-10 13:47:39 +02:00
@Nullable
public MobEffect c(@Nullable MobEffectList mobeffectlist) {
2015-02-12 15:00:40 +01:00
+ // CraftBukkit start
+ if (isTickingEffects) {
2016-02-29 22:32:46 +01:00
+ effectsToProcess.add(mobeffectlist);
+ return null;
2015-02-12 15:00:40 +01:00
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
return (MobEffect) this.effects.remove(mobeffectlist);
}
2015-02-12 15:00:40 +01:00
2017-05-14 04:00:00 +02:00
@@ -656,20 +745,52 @@
2014-11-25 22:32:16 +01: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);
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ public void heal(float f, EntityRegainHealthEvent.RegainReason regainReason) {
float f1 = this.getHealth();
if (f1 > 0.0F) {
- this.setHealth(f1 + f);
+ EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), f, regainReason);
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
+ }
+ // CraftBukkit end
}
}
public final float getHealth() {
+ // CraftBukkit start - Use unscaled health
+ if (this instanceof EntityPlayer) {
+ return (float) ((EntityPlayer) this).getBukkitEntity().getHealth();
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
return ((Float) this.datawatcher.get(EntityLiving.HEALTH)).floatValue();
2014-11-25 22:32:16 +01:00
}
public void setHealth(float f) {
+ // CraftBukkit start - Handle scaled health
+ if (this instanceof EntityPlayer) {
+ org.bukkit.craftbukkit.entity.CraftPlayer player = ((EntityPlayer) this).getBukkitEntity();
+ // Squeeze
+ if (f < 0.0F) {
+ player.setRealHealth(0.0D);
+ } else if (f > player.getMaxHealth()) {
+ player.setRealHealth(player.getMaxHealth());
+ } else {
+ player.setRealHealth(f);
+ }
+
2016-02-29 22:32:46 +01:00
+ this.datawatcher.set(EntityLiving.HEALTH, Float.valueOf(player.getScaledHealth()));
2014-11-25 22:32:16 +01:00
+ return;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.datawatcher.set(EntityLiving.HEALTH, Float.valueOf(MathHelper.a(f, 0.0F, this.getMaxHealth())));
2014-11-25 22:32:16 +01:00
}
2017-05-14 04:00:00 +02:00
@@ -687,14 +808,16 @@
2014-11-25 22:32:16 +01:00
} else {
2017-05-14 04:00:00 +02:00
float f1 = f;
2016-11-17 02:41:03 +01:00
- if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
2016-02-29 22:32:46 +01:00
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
2016-11-17 02:41:03 +01:00
+ if (false && (damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
2016-02-29 22:32:46 +01:00
this.getEquipment(EnumItemSlot.HEAD).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this);
2014-11-25 22:32:16 +01:00
f *= 0.75F;
}
2016-03-18 09:04:23 +01:00
2016-04-20 14:01:20 +02:00
- boolean flag = false;
2016-11-17 02:41:03 +01:00
+ boolean flag = f > 0.0F && this.applyBlockingModifier(damagesource); // Copied from below
2016-03-18 09:04:23 +01:00
2016-11-17 02:41:03 +01:00
- if (f > 0.0F && this.applyBlockingModifier(damagesource)) {
2016-03-18 09:04:23 +01:00
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
2016-11-17 02:41:03 +01:00
+ if (false && f > 0.0F && this.applyBlockingModifier(damagesource)) {
this.damageShield(f);
f = 0.0F;
if (!damagesource.a()) {
2017-05-14 04:00:00 +02:00
@@ -713,20 +836,39 @@
2015-08-31 10:06:13 +02:00
if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F) {
if (f <= this.lastDamage) {
+ this.forceExplosionKnockback = true; // CraftBukkit - SPIGOT-949 - for vanilla consistency, cooldown does not prevent explosion knockback
2014-11-25 22:32:16 +01:00
return false;
}
2016-02-29 22:32:46 +01:00
- this.damageEntity0(damagesource, f - this.lastDamage);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ if (!this.damageEntity0(damagesource, f - this.lastDamage)) {
2014-11-25 22:32:16 +01:00
+ return false;
+ }
+ // CraftBukkit end
this.lastDamage = f;
2016-02-29 22:32:46 +01:00
flag1 = false;
2014-11-25 22:32:16 +01:00
} else {
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ if (!this.damageEntity0(damagesource, f)) {
2014-11-25 22:32:16 +01:00
+ return false;
+ }
this.lastDamage = f;
this.noDamageTicks = this.maxNoDamageTicks;
2016-02-29 22:32:46 +01:00
- this.damageEntity0(damagesource, f);
+ // this.damageEntity0(damagesource, f);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
this.az = 10;
this.hurtTicks = this.az;
2014-11-25 22:32:16 +01:00
}
2014-12-09 15:40:38 +01:00
+ // CraftBukkit start
+ if(this instanceof EntityAnimal){
2016-02-29 22:32:46 +01:00
+ ((EntityAnimal)this).resetLove();
2014-12-09 15:40:38 +01:00
+ if(this instanceof EntityTameableAnimal){
+ ((EntityTameableAnimal)this).getGoalSit().setSitting(false);
+ }
+ }
+ // CraftBukkit end
+
2016-11-17 02:41:03 +01:00
this.aA = 0.0F;
Entity entity1 = damagesource.getEntity();
2017-05-14 04:00:00 +02:00
@@ -833,18 +975,26 @@
2016-12-10 02:16:14 +01:00
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
+ // CraftBukkit start
2017-05-14 04:00:00 +02:00
+ ItemStack itemstack1 = ItemStack.a;
2016-12-10 02:16:14 +01:00
for (int j = 0; j < i; ++j) {
EnumHand enumhand = aenumhand[j];
2017-05-14 04:00:00 +02:00
- ItemStack itemstack1 = this.b(enumhand);
+ itemstack1 = this.b(enumhand);
2016-12-10 02:16:14 +01:00
2017-05-14 04:00:00 +02:00
if (itemstack1.getItem() == Items.cY) {
itemstack = itemstack1.cloneItemStack();
- itemstack1.subtract(1);
+ // itemstack1.subtract(1); // CraftBukkit
2016-12-10 02:16:14 +01:00
break;
2016-11-17 02:41:03 +01:00
}
}
2014-12-09 15:40:38 +01:00
2017-05-14 04:00:00 +02:00
- if (itemstack != null) {
2016-11-17 02:41:03 +01:00
+ EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity());
2017-05-14 04:00:00 +02:00
+ event.setCancelled(itemstack == null);
2016-11-17 02:41:03 +01:00
+ this.world.getServer().getPluginManager().callEvent(event);
+
2017-06-23 04:47:29 +02:00
+ if (!event.isCancelled()) {
2017-05-14 04:00:00 +02:00
+ itemstack1.subtract(1);
2016-11-17 02:41:03 +01:00
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
if (this instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) this;
2017-06-23 04:47:29 +02:00
@@ -859,7 +1009,7 @@
this.world.broadcastEntityEffect(this, (byte) 35);
}
- return itemstack != null;
+ return !event.isCancelled();
}
}
2017-05-14 04:00:00 +02:00
@@ -944,6 +1094,12 @@
2016-02-29 22:32:46 +01:00
boolean flag = this.lastDamageByPlayerTime > 0;
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
this.a(flag, i, damagesource);
+ // CraftBukkit start - Call death event
+ CraftEventFactory.callEntityDeathEvent(this, this.drops);
2016-03-07 09:51:42 +01:00
+ this.drops = new ArrayList<org.bukkit.inventory.ItemStack>();
2016-02-29 22:32:46 +01:00
+ } else {
+ CraftEventFactory.callEntityDeathEvent(this);
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
}
2014-11-25 22:32:16 +01:00
}
2017-05-14 04:00:00 +02:00
@@ -1033,8 +1189,13 @@
2014-11-25 22:32:16 +01:00
int i = MathHelper.f((f - 3.0F - f2) * f1);
if (i > 0) {
+ // CraftBukkit start
+ if (!this.damageEntity(DamageSource.FALL, (float) i)) {
+ return;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.a(this.e(i), 1.0F, 1.0F);
2014-11-25 22:32:16 +01:00
- this.damageEntity(DamageSource.FALL, (float) i);
+ // this.damageEntity(DamageSource.FALL, (float) i); // CraftBukkit - moved up
int j = MathHelper.floor(this.locX);
int k = MathHelper.floor(this.locY - 0.20000000298023224D);
int l = MathHelper.floor(this.locZ);
2017-05-14 04:00:00 +02:00
@@ -1061,7 +1222,7 @@
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
protected float applyArmorModifier(DamageSource damagesource, float f) {
if (!damagesource.ignoresArmor()) {
2014-11-25 22:32:16 +01:00
- this.damageArmor(f);
2016-02-29 22:32:46 +01:00
+ // this.damageArmor(f); // CraftBukkit - Moved into damageEntity0(DamageSource, float)
2017-05-14 04:00:00 +02:00
f = CombatMath.a(f, (float) this.getArmorStrength(), (float) this.getAttributeInstance(GenericAttributes.i).getValue());
2014-11-25 22:32:16 +01:00
}
2017-05-14 04:00:00 +02:00
@@ -1074,7 +1235,8 @@
2016-02-29 22:32:46 +01:00
} else {
int i;
- if (this.hasEffect(MobEffects.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
+ // CraftBukkit - Moved to damageEntity0(DamageSource, float)
+ if (false && this.hasEffect(MobEffects.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
i = (this.getEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = f * (float) j;
2017-05-14 04:00:00 +02:00
@@ -1095,22 +1257,142 @@
2014-11-25 22:32:16 +01:00
}
}
2016-02-29 22:32:46 +01:00
- protected void damageEntity0(DamageSource damagesource, float f) {
2015-02-26 23:41:06 +01:00
- if (!this.isInvulnerable(damagesource)) {
2014-11-25 22:32:16 +01:00
- f = this.applyArmorModifier(damagesource, f);
- f = this.applyMagicModifier(damagesource, f);
- float f1 = f;
2016-03-20 00:54:23 +01:00
-
- f = Math.max(f - this.getAbsorptionHearts(), 0.0F);
- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f));
- if (f != 0.0F) {
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ protected boolean damageEntity0(final DamageSource damagesource, float f) { // void -> boolean, add final
2015-02-26 23:41:06 +01:00
+ if (!this.isInvulnerable(damagesource)) {
2014-11-25 22:32:16 +01:00
+ final boolean human = this instanceof EntityHuman;
+ float originalDamage = f;
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
2016-11-17 02:41:03 +01:00
+ if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !EntityLiving.this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
2014-11-25 22:32:16 +01:00
+ return -(f - (f * 0.75F));
2016-03-20 00:54:23 +01:00
+
2014-11-25 22:32:16 +01:00
+ }
+ return -0.0;
+ }
+ };
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
+
+ Function<Double, Double> blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
2016-11-17 02:41:03 +01:00
+ return -((EntityLiving.this.applyBlockingModifier(damagesource)) ? f : 0.0);
2014-11-25 22:32:16 +01:00
+ }
+ };
+ float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier;
+
+ Function<Double, Double> armor = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.applyArmorModifier(damagesource, f.floatValue()));
+ }
+ };
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+
+ Function<Double, Double> resistance = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
2016-02-29 22:32:46 +01:00
+ if (!damagesource.isStarvation() && EntityLiving.this.hasEffect(MobEffects.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
+ int i = (EntityLiving.this.getEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
2014-11-25 22:32:16 +01:00
+ int j = 25 - i;
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ }
+ return -0.0;
+ }
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
+ Function<Double, Double> magic = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.applyMagicModifier(damagesource, f.floatValue()));
+ }
+ };
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
+ Function<Double, Double> absorption = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionHearts(), 0.0F), 0.0F));
+ }
+ };
+ float absorptionModifier = absorption.apply((double) f).floatValue();
2015-04-09 02:18:21 +02:00
+
2014-11-25 22:32:16 +01:00
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
+ if (event.isCancelled()) {
+ return false;
+ }
+
+ f = (float) event.getFinalDamage();
2015-01-16 04:48:42 +01:00
+
2014-11-25 22:32:16 +01:00
+ // Apply damage to helmet
2016-02-29 22:32:46 +01:00
+ if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(EnumItemSlot.HEAD) != null) {
+ this.getEquipment(EnumItemSlot.HEAD).damage((int) (event.getDamage() * 4.0F + this.random.nextFloat() * event.getDamage() * 2.0F), this);
2014-11-25 22:32:16 +01:00
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ // Apply damage to armor
+ if (!damagesource.ignoresArmor()) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ this.damageArmor(armorDamage);
+ }
2016-02-29 22:32:46 +01:00
+
2016-11-17 02:41:03 +01:00
+ // Apply blocking code // PAIL: steal from above
2016-03-20 00:54:23 +01:00
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
2016-11-17 02:41:03 +01:00
+ this.damageShield((float) -event.getDamage(DamageModifier.BLOCKING));
+ Entity entity = damagesource.i();
+
+ if (entity instanceof EntityLiving) {
+ this.c((EntityLiving) entity);
2016-03-26 04:10:29 +01:00
+ }
2016-03-18 09:04:23 +01:00
+ }
+
2014-11-25 22:32:16 +01:00
+ absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
+ this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F));
2016-11-18 00:57:53 +01:00
+ if (f > 0 || !human) {
2014-11-25 22:32:16 +01:00
+ if (human) {
2015-04-09 02:18:21 +02:00
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
2014-11-25 22:32:16 +01:00
+ ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost());
2015-04-09 02:18:21 +02:00
+ if (f < 3.4028235E37F) {
2016-02-29 22:32:46 +01:00
+ ((EntityHuman) this).a(StatisticList.z, Math.round(f * 10.0F));
2015-04-09 02:18:21 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
float f2 = this.getHealth();
this.setHealth(f2 - f);
2016-02-29 22:32:46 +01:00
this.getCombatTracker().trackDamage(damagesource, f2, f);
2016-03-20 00:54:23 +01:00
- this.setAbsorptionHearts(this.getAbsorptionHearts() - f);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2016-03-20 03:40:12 +01:00
+ if (!human) {
+ this.setAbsorptionHearts(this.getAbsorptionHearts() - f);
2014-11-25 22:32:16 +01:00
+ }
2016-11-17 02:41:03 +01:00
+
+ return true;
+ } else {
2017-05-14 04:00:00 +02:00
+ // Duplicate triggers if blocking
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ if (this instanceof EntityPlayer) {
+ CriterionTriggers.h.a((EntityPlayer) this, damagesource, f, originalDamage, true);
+ }
+
+ if (damagesource.getEntity() instanceof EntityPlayer) {
+ CriterionTriggers.g.a((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
+ }
+
+ return false;
+ } else {
+ return originalDamage > 0;
+ }
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
}
+ return false; // CraftBukkit
}
2016-02-29 22:32:46 +01:00
public CombatTracker getCombatTracker() {
2017-05-14 04:00:00 +02:00
@@ -1177,6 +1459,7 @@
2016-02-29 22:32:46 +01:00
public AttributeMapBase getAttributeMap() {
2016-11-17 02:41:03 +01:00
if (this.attributeMap == null) {
this.attributeMap = new AttributeMapServer();
+ this.craftAttributes = new CraftAttributeMap(attributeMap); // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2016-11-17 02:41:03 +01:00
return this.attributeMap;
2017-05-14 04:00:00 +02:00
@@ -1469,6 +1752,7 @@
2016-03-12 10:57:32 +01:00
}
if (this.onGround && !this.world.isClientSide) {
+ if (getFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setFlag(7, false);
}
} else {
2017-05-14 04:00:00 +02:00
@@ -1838,6 +2122,7 @@
2016-03-12 10:57:32 +01:00
}
if (!this.world.isClientSide) {
2016-03-15 03:15:54 +01:00
+ if (flag != this.getFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
2016-03-12 10:57:32 +01:00
this.setFlag(7, flag);
}
2017-05-14 04:00:00 +02:00
@@ -1931,11 +2216,11 @@
2016-03-27 11:58:45 +02:00
}
public boolean isInteractable() {
- return !this.dead;
+ return !this.dead && this.collides; // CraftBukkit
2016-03-27 11:19:41 +02:00
}
public boolean isCollidable() {
2016-11-17 02:41:03 +01:00
- return this.isAlive() && !this.m_();
+ return this.isAlive() && !this.m_() && this.collides; // CraftBukkit
2016-03-27 11:19:41 +02:00
}
2017-06-08 10:00:00 +02:00
protected void ax() {
2017-05-14 04:00:00 +02:00
@@ -2072,7 +2357,27 @@
2016-02-29 22:32:46 +01:00
protected void v() {
2016-11-17 02:41:03 +01:00
if (!this.activeItem.isEmpty() && this.isHandRaised()) {
2017-05-14 04:00:00 +02:00
this.b(this.activeItem, 16);
2017-06-08 10:00:00 +02:00
- this.a(this.cH(), this.activeItem.a(this.world, this));
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start - fire PlayerItemConsumeEvent
2017-01-09 04:28:49 +01:00
+ ItemStack itemstack;
+ if (this instanceof EntityPlayer) {
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.activeItem);
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
+ world.getServer().getPluginManager().callEvent(event);
2015-01-16 04:48:42 +01:00
+
2017-01-09 04:28:49 +01:00
+ if (event.isCancelled()) {
+ // Update client
2016-02-29 22:32:46 +01:00
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
2017-01-09 04:28:49 +01:00
+ return;
2015-01-16 04:48:42 +01:00
+ }
2017-01-09 04:28:49 +01:00
+
+ itemstack = (craftItem.equals(event.getItem())) ? this.activeItem.a(this.world, this) : CraftItemStack.asNMSCopy(event.getItem()).a(world, this);
+ } else {
+ itemstack = this.activeItem.a(this.world, this);
2015-01-16 04:48:42 +01:00
+ }
2016-02-29 22:32:46 +01:00
+
2017-06-08 10:00:00 +02:00
+ this.a(this.cH(), itemstack);
2015-01-16 04:48:42 +01:00
+ // CraftBukkit end
2017-06-08 10:00:00 +02:00
this.cN();
2016-11-17 02:41:03 +01:00
}
2016-02-29 22:32:46 +01:00
2017-05-14 04:00:00 +02:00
@@ -2151,10 +2456,18 @@
2016-04-08 11:06:31 +02:00
}
if (flag1) {
- this.enderTeleportTo(this.locX, this.locY, this.locZ);
2016-06-12 04:51:53 +02:00
- if (world.getCubes(this, this.getBoundingBox()).isEmpty() && !world.containsLiquid(this.getBoundingBox())) {
- flag = true;
2016-04-08 11:06:31 +02:00
+ // CraftBukkit start - Teleport event
+ // this.enderTeleportTo(this.locX, this.locY, this.locZ);
+ EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), new Location(this.world.getWorld(), d3, d4, d5), new Location(this.world.getWorld(), this.locX, this.locY, this.locZ));
+ this.world.getServer().getPluginManager().callEvent(teleport);
2016-06-12 04:51:53 +02:00
+ if (!teleport.isCancelled()) {
+ Location to = teleport.getTo();
+ this.enderTeleportTo(to.getX(), to.getY(), to.getZ());
+ if (world.getCubes(this, this.getBoundingBox()).isEmpty() && !world.containsLiquid(this.getBoundingBox())) {
+ flag = true;
+ }
2016-04-08 11:06:31 +02:00
}
2016-06-12 04:51:53 +02:00
+ // CraftBukkit end
}
}