3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-25 07:40:06 +01:00
Paper/nms-patches/EntityLiving.patch

580 Zeilen
24 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityLiving.java
+++ b/net/minecraft/server/EntityLiving.java
2016-03-12 10:57:32 +01:00
@@ -9,6 +9,21 @@
import java.util.Random;
import java.util.UUID;
+// CraftBukkit start
+import java.util.ArrayList;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2016-02-29 22:32:46 +01:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
2016-03-12 10:57:32 +01:00
+import org.bukkit.entity.LivingEntity;
2016-02-29 22:32:46 +01:00
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
2016-02-29 22:32:46 +01:00
+import org.bukkit.event.player.PlayerItemConsumeEvent;
+// CraftBukkit end
+
public abstract class EntityLiving extends Entity {
private static final UUID a = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
@@ -80,6 +95,14 @@
2016-02-29 22:32:46 +01:00
protected int bn;
protected int bo;
private BlockPosition bC;
+ // CraftBukkit start
+ public int expToDrop;
+ public int maxAirTicks = 300;
+ 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;
+ public boolean collides = true;
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
public void Q() {
this.damageEntity(DamageSource.OUT_OF_WORLD, Float.MAX_VALUE);
@@ -88,7 +111,8 @@
public EntityLiving(World world) {
super(world);
2015-02-26 23:41:06 +01:00
this.initAttributes();
- 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;
this.aL = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.setPosition(this.locX, this.locY, this.locZ);
2016-03-30 21:50:59 +02:00
@@ -126,7 +150,13 @@
2016-02-29 22:32:46 +01:00
double d1 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
int i = (int) (150.0D * d1);
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)});
+ // 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)});
+ }
+ // CraftBukkit end
}
}
2016-03-30 21:50:59 +02:00
@@ -188,7 +218,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
}
2016-02-29 22:32:46 +01:00
if (!this.world.isClientSide) {
2016-03-30 21:50:59 +02:00
@@ -245,6 +279,18 @@
this.world.methodProfiler.b();
}
2015-02-26 23:41:06 +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")) {
+ 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);
2016-03-30 21:50:59 +02:00
@@ -260,19 +306,19 @@
2016-02-29 22:32:46 +01:00
protected void bC() {
++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"))) {
- i = this.getExpValue(this.killer);
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);
- while (i > 0) {
- int j = EntityExperienceOrb.getOrbValue(i);
-
- 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();
2016-03-30 21:50:59 +02:00
@@ -426,6 +472,17 @@
}
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ if (nbttagcompound.hasKey("Bukkit.MaxHealth")) {
+ NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
+ if (nbtbase.getTypeId() == 5) {
+ this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double) ((NBTTagFloat) nbtbase).c());
+ } else if (nbtbase.getTypeId() == 3) {
+ this.getAttributeInstance(GenericAttributes.maxHealth).setValue((double) ((NBTTagInt) nbtbase).d());
+ }
+ }
+ // 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"));
}
2016-03-30 21:50:59 +02:00
@@ -441,9 +498,15 @@
2016-02-29 22:32:46 +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() {
Iterator iterator = this.effects.keySet().iterator();
2015-02-26 23:41:06 +01:00
+ isTickingEffects = true; // CraftBukkit
while (iterator.hasNext()) {
2016-02-29 22:32:46 +01:00
MobEffectList mobeffectlist = (MobEffectList) iterator.next();
MobEffect mobeffect = (MobEffect) this.effects.get(mobeffectlist);
2016-03-30 21:50:59 +02:00
@@ -457,6 +520,16 @@
this.a(mobeffect, false);
}
}
+ // 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);
+ }
+ }
+ // CraftBukkit end
if (this.updateEffects) {
2015-02-26 23:41:06 +01:00
if (!this.world.isClientSide) {
2016-03-30 21:50:59 +02:00
@@ -553,6 +626,12 @@
}
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());
2016-03-30 21:50:59 +02:00
@@ -584,6 +663,12 @@
}
2016-02-29 22:32:46 +01:00
public MobEffect c(MobEffectList mobeffectlist) {
+ // CraftBukkit start
+ if (isTickingEffects) {
2016-02-29 22:32:46 +01:00
+ effectsToProcess.add(mobeffectlist);
+ return null;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
return (MobEffect) this.effects.remove(mobeffectlist);
}
2016-03-30 21:50:59 +02:00
@@ -623,20 +708,52 @@
}
+ // 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
+
+ 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();
}
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()));
+ 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())));
}
2016-03-30 21:50:59 +02:00
@@ -652,14 +769,16 @@
2016-02-29 22:32:46 +01:00
} else if (damagesource.o() && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
} else {
2016-02-29 22:32:46 +01:00
- if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(EnumItemSlot.HEAD) != null) {
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
+ if (false && (damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getEquipment(EnumItemSlot.HEAD) != null) {
this.getEquipment(EnumItemSlot.HEAD).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this);
f *= 0.75F;
}
boolean flag = false;
- if (f > 0.0F && this.d(damagesource)) {
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
+ if (false && f > 0.0F && this.d(damagesource)) {
this.k(f);
if (damagesource.a()) {
f = 0.0F;
2016-03-30 21:50:59 +02:00
@@ -678,19 +797,38 @@
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
return false;
}
2016-02-29 22:32:46 +01:00
- this.damageEntity0(damagesource, f - this.lastDamage);
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ if (!this.damageEntity0(damagesource, f - this.lastDamage)) {
+ return false;
+ }
+ // CraftBukkit end
this.lastDamage = f;
2016-02-29 22:32:46 +01:00
flag1 = false;
} else {
+ // CraftBukkit start
2016-02-29 22:32:46 +01:00
+ if (!this.damageEntity0(damagesource, f)) {
+ 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);
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
this.hurtTicks = this.ay = 10;
}
+ // CraftBukkit start
+ if(this instanceof EntityAnimal){
2016-02-29 22:32:46 +01:00
+ ((EntityAnimal)this).resetLove();
+ if(this instanceof EntityTameableAnimal){
+ ((EntityTameableAnimal)this).getGoalSit().setSitting(false);
+ }
+ }
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
this.az = 0.0F;
Entity entity = damagesource.getEntity();
2016-03-30 21:50:59 +02:00
@@ -830,6 +968,12 @@
2016-02-29 22:32:46 +01:00
boolean flag = this.lastDamageByPlayerTime > 0;
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
}
}
2016-03-30 21:50:59 +02:00
@@ -917,8 +1061,13 @@
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);
- 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);
2016-03-30 21:50:59 +02:00
@@ -945,8 +1094,8 @@
2016-02-29 22:32:46 +01:00
protected float applyArmorModifier(DamageSource damagesource, float f) {
if (!damagesource.ignoresArmor()) {
- this.damageArmor(f);
2016-03-30 21:50:59 +02:00
- f = CombatMath.a(f, (float) this.getArmorStrength(), (float) this.getAttributeInstance(GenericAttributes.h).getValue());
2016-02-29 22:32:46 +01:00
+ // this.damageArmor(f); // CraftBukkit - Moved into damageEntity0(DamageSource, float)
2016-03-30 21:50:59 +02:00
+ f = CombatMath.a(f, (float) this.getArmorStrength());
}
2016-02-29 22:32:46 +01:00
return f;
2016-03-30 21:50:59 +02:00
@@ -958,7 +1107,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;
2016-03-30 21:50:59 +02:00
@@ -979,22 +1129,127 @@
}
}
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)) {
- 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)) {
+ final boolean human = this instanceof EntityHuman;
+ float originalDamage = f;
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
2016-02-29 22:32:46 +01:00
+ if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && EntityLiving.this.getEquipment(EnumItemSlot.HEAD) != null) {
+ return -(f - (f * 0.75F));
2016-03-20 00:54:23 +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-03-20 00:54:23 +01:00
+ return -((EntityLiving.this.d(damagesource)) ? ((damagesource.a()) ? f : (f - (f * 0.33F))) : 0.0); // PAIL: rename
+ }
+ };
+ 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;
+ 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();
+
+ 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();
+
+ // 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);
+ }
2015-02-26 23:41:06 +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
+
+ // Apply blocking code
2016-03-20 00:54:23 +01:00
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
2016-03-22 04:54:21 +01:00
+ this.k((float) event.getDamage()); // PAIL: rename
2016-03-20 00:54:23 +01:00
+ if (damagesource.i() instanceof EntityLiving) {// PAIL: rename
+ ((EntityLiving) damagesource.i()).a(EntityLiving.this, 0.5F, EntityLiving.this.locX - damagesource.i().locX, EntityLiving.this.locZ - damagesource.i().locZ);
+ }
+ if (f <= 0) {
+ return false;
+ }
+ }
+
+ absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
+ this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F));
2016-03-20 00:54:23 +01:00
+ if (f > 0) {
+ if (human) {
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
+ ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost());
+ if (f < 3.4028235E37F) {
2016-02-29 22:32:46 +01:00
+ ((EntityHuman) this).a(StatisticList.z, Math.round(f * 10.0F));
+ }
+ }
+ // 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);
+ // CraftBukkit start
2016-03-20 03:40:12 +01:00
+ if (!human) {
+ this.setAbsorptionHearts(this.getAbsorptionHearts() - f);
+ }
+ // CraftBukkit end
}
+ return true;
}
+ return false; // CraftBukkit
}
2016-02-29 22:32:46 +01:00
public CombatTracker getCombatTracker() {
2016-03-30 21:50:59 +02:00
@@ -1060,6 +1315,7 @@
2016-02-29 22:32:46 +01:00
public AttributeMapBase getAttributeMap() {
if (this.bp == null) {
this.bp = new AttributeMapServer();
+ this.craftAttributes = new CraftAttributeMap(bp); // CraftBukkit
}
2016-02-29 22:32:46 +01:00
return this.bp;
2016-03-30 21:50:59 +02:00
@@ -1334,6 +1590,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 {
2016-03-30 21:50:59 +02:00
@@ -1694,6 +1951,7 @@
2016-03-12 10:57:32 +01:00
}
if (!this.world.isClientSide) {
+ if (flag != this.getFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
2016-03-12 10:57:32 +01:00
this.setFlag(7, flag);
}
2016-03-30 21:50:59 +02:00
@@ -1707,6 +1965,13 @@
2016-02-29 22:32:46 +01:00
if (!list.isEmpty()) {
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity) list.get(i);
+ // 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;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2016-02-29 22:32:46 +01:00
this.C(entity);
}
2016-03-30 21:50:59 +02:00
@@ -1782,11 +2047,11 @@
2016-03-27 11:58:45 +02:00
}
public boolean isInteractable() {
- return !this.dead;
+ return !this.dead && this.collides; // CraftBukkit
}
public boolean isCollidable() {
- return !this.dead;
+ return !this.dead && this.collides; // CraftBukkit
}
protected void ao() {
2016-03-30 21:50:59 +02:00
@@ -1923,7 +2188,22 @@
2016-02-29 22:32:46 +01:00
protected void v() {
if (this.bm != null && this.cs()) {
this.a(this.bm, 16);
- ItemStack itemstack = this.bm.a(this.world, this);
+ // CraftBukkit start - fire PlayerItemConsumeEvent
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.bm); // PAIL: rename
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
+ world.getServer().getPluginManager().callEvent(event);
+
2016-02-29 22:32:46 +01:00
+ if (event.isCancelled()) {
+ // Update client
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
+ }
2016-02-29 22:32:46 +01:00
+ return;
+ }
2016-02-29 22:32:46 +01:00
+
+ ItemStack itemstack = (craftItem.equals(event.getItem())) ? this.bm.a(this.world, this) : CraftItemStack.asNMSCopy(event.getItem()).a(world, this);
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
if (itemstack != null && itemstack.count == 0) {
itemstack = null;