13
0
geforkt von Mirrors/Paper
Paper/nms-patches/EntityLiving.patch

843 Zeilen
35 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityLiving.java
+++ b/net/minecraft/server/EntityLiving.java
2019-12-10 23:00:00 +01:00
@@ -18,6 +18,25 @@
2019-04-23 04:00:00 +02:00
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
+// CraftBukkit start
+import java.util.ArrayList;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import org.bukkit.Location;
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-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;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
+import org.bukkit.event.entity.EntityPotionEffectEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
2016-11-17 02:41:03 +01:00
+import org.bukkit.event.entity.EntityResurrectEvent;
+import org.bukkit.event.entity.EntityTeleportEvent;
2016-02-29 22:32:46 +01:00
+import org.bukkit.event.player.PlayerItemConsumeEvent;
+// CraftBukkit end
+
public abstract class EntityLiving extends Entity {
2019-04-23 04:00:00 +02:00
private static final UUID b = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
2019-12-10 23:00:00 +01:00
@@ -100,6 +119,20 @@
private float bH;
private float bI;
protected BehaviorController<?> bo;
+ // 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;
+ public boolean canPickUpLoot;
2017-11-07 07:21:38 +01:00
+
+ @Override
+ public float getBukkitYaw() {
+ return getHeadRotation();
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
protected EntityLiving(EntityTypes<? extends EntityLiving> entitytypes, World world) {
2018-07-15 02:00:00 +02:00
super(entitytypes, world);
2019-12-10 23:00:00 +01:00
@@ -110,7 +143,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();
- this.setHealth(this.getMaxHealth());
+ // CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
2019-04-23 04:00:00 +02:00
+ this.datawatcher.set(EntityLiving.HEALTH, (float) this.getAttributeInstance(GenericAttributes.MAX_HEALTH).getValue());
this.i = true;
2019-12-10 23:00:00 +01:00
this.aH = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.Z();
@@ -170,7 +204,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
2019-12-10 23:00:00 +01:00
- ((WorldServer) this.world).a(new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ // CraftBukkit start - visiblity api
+ if (this instanceof EntityPlayer) {
2019-12-10 23:00:00 +01:00
+ ((WorldServer) this.world).sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false);
+ } else {
2019-12-10 23:00:00 +01:00
+ ((WorldServer) this.world).a(new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ }
+ // CraftBukkit end
}
}
2019-12-10 23:00:00 +01:00
@@ -318,7 +358,7 @@
2016-02-29 22:32:46 +01:00
2019-12-10 23:00:00 +01:00
protected void cD() {
++this.deathTicks;
- if (this.deathTicks == 20) {
+ if (this.deathTicks >= 20 && !this.dead) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
this.die();
2019-12-10 23:00:00 +01:00
for (int i = 0; i < 20; ++i) {
@@ -464,6 +504,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) {
2019-04-23 04:00:00 +02:00
+ this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(((NBTTagFloat) nbtbase).asDouble());
+ } else if (nbtbase.getTypeId() == 3) {
2019-04-23 04:00:00 +02:00
+ this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(((NBTTagInt) nbtbase).asDouble());
+ }
+ }
+ // 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"));
}
2019-12-10 23:00:00 +01:00
@@ -501,9 +552,32 @@
2016-02-29 22:32:46 +01:00
}
+ // CraftBukkit start
+ private boolean isTickingEffects = false;
+ private List<ProcessableEffect> effectsToProcess = Lists.newArrayList();
+
+ private static class ProcessableEffect {
+
+ private MobEffectList type;
+ private MobEffect effect;
+ private final EntityPotionEffectEvent.Cause cause;
+
+ private ProcessableEffect(MobEffect effect, EntityPotionEffectEvent.Cause cause) {
+ this.effect = effect;
+ this.cause = cause;
+ }
+
+ private ProcessableEffect(MobEffectList type, EntityPotionEffectEvent.Cause cause) {
+ this.type = type;
+ this.cause = cause;
+ }
+ }
+ // 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
2016-11-17 02:41:03 +01:00
try {
while (iterator.hasNext()) {
MobEffectList mobeffectlist = (MobEffectList) iterator.next();
2019-12-10 23:00:00 +01:00
@@ -511,6 +585,12 @@
if (!mobeffect.tick(this)) {
if (!this.world.isClientSide) {
+ // CraftBukkit start
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect, null, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.EXPIRATION);
2018-07-21 02:13:45 +02:00
+ if (event.isCancelled()) {
+ continue;
+ }
+ // CraftBukkit end
iterator.remove();
2018-07-21 02:13:45 +02:00
this.b(mobeffect);
}
2019-12-10 23:00:00 +01:00
@@ -521,6 +601,17 @@
2016-11-17 02:41:03 +01:00
} catch (ConcurrentModificationException concurrentmodificationexception) {
;
}
+ // CraftBukkit start
+ isTickingEffects = false;
+ for (ProcessableEffect e : effectsToProcess) {
+ if (e.effect != null) {
+ addEffect(e.effect, e.cause);
+ } else {
+ removeEffect(e.type, e.cause);
+ }
+ }
+ effectsToProcess.clear();
+ // CraftBukkit end
if (this.updateEffects) {
2015-02-26 23:41:06 +01:00
if (!this.world.isClientSide) {
2019-12-10 23:00:00 +01:00
@@ -630,7 +721,13 @@
2019-04-23 04:00:00 +02:00
this.datawatcher.set(EntityLiving.e, 0);
}
+ // CraftBukkit start
public boolean removeAllEffects() {
+ return removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ public boolean removeAllEffects(EntityPotionEffectEvent.Cause cause) {
+ // CraftBukkit end
if (this.world.isClientSide) {
return false;
} else {
2019-12-10 23:00:00 +01:00
@@ -639,7 +736,14 @@
boolean flag;
for (flag = false; iterator.hasNext(); flag = true) {
- this.b((MobEffect) iterator.next());
+ // CraftBukkit start
+ MobEffect effect = (MobEffect) iterator.next();
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, effect, null, cause, EntityPotionEffectEvent.Action.CLEARED);
2018-07-21 02:13:45 +02:00
+ if (event.isCancelled()) {
+ continue;
+ }
2018-07-21 02:13:45 +02:00
+ this.b(effect);
+ // CraftBukkit end
iterator.remove();
}
2019-12-10 23:00:00 +01:00
@@ -664,18 +768,44 @@
return (MobEffect) this.effects.get(mobeffectlist);
}
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
public boolean addEffect(MobEffect mobeffect) {
+ return addEffect(mobeffect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ public boolean addEffect(MobEffect mobeffect, EntityPotionEffectEvent.Cause cause) {
+ if (isTickingEffects) {
+ effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
2018-07-15 02:00:00 +02:00
+ return true;
+ }
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
if (!this.d(mobeffect)) {
return false;
} else {
MobEffect mobeffect1 = (MobEffect) this.effects.get(mobeffect.getMobEffect());
+ // CraftBukkit start
+ boolean override = false;
+ if (mobeffect1 != null) {
+ override = new MobEffect(mobeffect1).a(mobeffect);
+ }
+
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect1, mobeffect, cause, override);
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
+
if (mobeffect1 == null) {
this.effects.put(mobeffect.getMobEffect(), mobeffect);
this.a(mobeffect);
return true;
- } else if (mobeffect1.a(mobeffect)) {
+ // CraftBukkit start
+ } else if (event.isOverride()) {
+ mobeffect1.a(mobeffect);
this.a(mobeffect1, true);
+ // CraftBukkit end
return true;
} else {
return false;
2019-12-10 23:00:00 +01:00
@@ -699,13 +829,39 @@
return this.getMonsterType() == EnumMonsterType.UNDEAD;
}
+ // CraftBukkit start
2016-05-10 13:47:39 +02:00
@Nullable
public MobEffect c(@Nullable MobEffectList mobeffectlist) {
+ return c(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ @Nullable
+ public MobEffect c(@Nullable MobEffectList mobeffectlist, EntityPotionEffectEvent.Cause cause) {
+ if (isTickingEffects) {
+ effectsToProcess.add(new ProcessableEffect(mobeffectlist, cause));
2016-02-29 22:32:46 +01:00
+ return null;
+ }
+
+ MobEffect effect = this.effects.get(mobeffectlist);
+ if (effect == null) {
+ return null;
+ }
+
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, effect, null, cause);
+ if (event.isCancelled()) {
+ return null;
+ }
+
2016-02-29 22:32:46 +01:00
return (MobEffect) this.effects.remove(mobeffectlist);
}
public boolean removeEffect(MobEffectList mobeffectlist) {
- MobEffect mobeffect = this.c(mobeffectlist);
+ return removeEffect(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ public boolean removeEffect(MobEffectList mobeffectlist, EntityPotionEffectEvent.Cause cause) {
+ MobEffect mobeffect = this.c(mobeffectlist, cause);
+ // CraftBukkit end
if (mobeffect != null) {
this.b(mobeffect);
2019-12-10 23:00:00 +01:00
@@ -742,20 +898,55 @@
}
+ // 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);
2019-04-23 04:00:00 +02:00
+ // Suppress during worldgen
+ if (this.valid) {
+ this.world.getServer().getPluginManager().callEvent(event);
+ }
+
+ if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
+ }
+ // CraftBukkit end
}
}
2018-07-15 02:00:00 +02:00
public float getHealth() {
+ // CraftBukkit start - Use unscaled health
+ if (this instanceof EntityPlayer) {
+ return (float) ((EntityPlayer) this).getBukkitEntity().getHealth();
+ }
+ // CraftBukkit end
2018-12-06 00:00:00 +01:00
return (Float) this.datawatcher.get(EntityLiving.HEALTH);
}
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);
+ }
+
+ player.updateScaledHealth(false);
+ return;
+ }
+ // CraftBukkit end
2018-12-06 00:00:00 +01:00
this.datawatcher.set(EntityLiving.HEALTH, MathHelper.a(f, 0.0F, this.getMaxHealth()));
}
2019-12-10 23:00:00 +01:00
@@ -765,7 +956,7 @@
2019-03-06 06:38:02 +01:00
return false;
} else if (this.world.isClientSide) {
return false;
- } else if (this.getHealth() <= 0.0F) {
+ } else if (this.dead || this.killed || this.getHealth() <= 0.0F) { // CraftBukkit - Don't allow entities that got set to dead/killed elsewhere to get damaged and die
return false;
2019-12-10 23:00:00 +01:00
} else if (damagesource.isFire() && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
2019-03-06 06:38:02 +01:00
return false;
2019-12-10 23:00:00 +01:00
@@ -777,17 +968,19 @@
2018-08-26 04:00:00 +02:00
this.ticksFarFromPlayer = 0;
float f1 = f;
2018-08-26 04:00:00 +02:00
- if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
+ if (false && (damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
2019-04-23 04:00:00 +02:00
this.getEquipment(EnumItemSlot.HEAD).damage((int) (f * 4.0F + this.random.nextFloat() * f * 2.0F), this, (entityliving) -> {
entityliving.c(EnumItemSlot.HEAD);
});
2018-08-26 04:00:00 +02:00
f *= 0.75F;
}
2018-08-26 04:00:00 +02:00
- boolean flag = false;
+ boolean flag = f > 0.0F && this.applyBlockingModifier(damagesource); // Copied from below
float f2 = 0.0F;
- if (f > 0.0F && this.applyBlockingModifier(damagesource)) {
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
+ if (false && f > 0.0F && this.applyBlockingModifier(damagesource)) {
this.damageShield(f);
f2 = f;
f = 0.0F;
2019-12-10 23:00:00 +01:00
@@ -807,20 +1000,39 @@
2018-08-26 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
if ((float) this.noDamageTicks > 10.0F) {
2018-08-26 04:00:00 +02:00
if (f <= this.lastDamage) {
+ this.forceExplosionKnockback = true; // CraftBukkit - SPIGOT-949 - for vanilla consistency, cooldown does not prevent explosion knockback
return false;
}
2018-08-26 04:00:00 +02:00
- this.damageEntity0(damagesource, f - this.lastDamage);
+ // CraftBukkit start
2018-08-26 04:00:00 +02:00
+ if (!this.damageEntity0(damagesource, f - this.lastDamage)) {
+ return false;
+ }
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
this.lastDamage = f;
flag1 = false;
} else {
+ // CraftBukkit start
+ if (!this.damageEntity0(damagesource, f)) {
+ return false;
+ }
this.lastDamage = f;
2019-04-23 04:00:00 +02:00
this.noDamageTicks = 20;
2018-08-26 04:00:00 +02:00
- this.damageEntity0(damagesource, f);
+ // this.damageEntity0(damagesource, f);
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.hurtDuration = 10;
this.hurtTicks = this.hurtDuration;
2018-08-26 04:00:00 +02:00
}
+ // CraftBukkit start
+ if (this instanceof EntityAnimal) {
+ ((EntityAnimal) this).resetLove();
+ if (this instanceof EntityTameableAnimal) {
+ ((EntityTameableAnimal) this).getGoalSit().setSitting(false);
+ }
+ }
+ // CraftBukkit end
+
2019-12-10 23:00:00 +01:00
this.ax = 0.0F;
2018-08-26 04:00:00 +02:00
Entity entity1 = damagesource.getEntity();
2016-11-17 02:41:03 +01:00
2019-12-10 23:00:00 +01:00
@@ -941,19 +1153,29 @@
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
+ // CraftBukkit start
2017-05-14 04:00:00 +02:00
+ ItemStack itemstack1 = ItemStack.a;
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);
2018-07-15 02:00:00 +02:00
if (itemstack1.getItem() == Items.TOTEM_OF_UNDYING) {
2017-05-14 04:00:00 +02:00
itemstack = itemstack1.cloneItemStack();
- itemstack1.subtract(1);
+ // itemstack1.subtract(1); // CraftBukkit
break;
2016-11-17 02:41:03 +01:00
}
}
2017-05-14 04:00:00 +02:00
- if (itemstack != null) {
2018-03-24 06:13:17 +01:00
- if (this instanceof EntityPlayer) {
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);
+
+ if (!event.isCancelled()) {
+ if (!itemstack1.isEmpty()) {
+ itemstack1.subtract(1);
+ }
2018-03-24 06:13:17 +01:00
+ if (itemstack != null && this instanceof EntityPlayer) {
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
EntityPlayer entityplayer = (EntityPlayer) this;
2018-07-15 02:00:00 +02:00
entityplayer.b(StatisticList.ITEM_USED.b(Items.TOTEM_OF_UNDYING));
2019-12-10 23:00:00 +01:00
@@ -961,13 +1183,15 @@
}
this.setHealth(1.0F);
- this.removeAllEffects();
- this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1));
- this.addEffect(new MobEffect(MobEffects.ABSORBTION, 100, 1));
+ // CraftBukkit start
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
+ this.addEffect(new MobEffect(MobEffects.ABSORBTION, 100, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
+ // CraftBukkit end
this.world.broadcastEntityEffect(this, (byte) 35);
}
- return itemstack != null;
+ return !event.isCancelled();
}
}
2019-12-10 23:00:00 +01:00
@@ -1084,28 +1308,48 @@
boolean flag = this.lastDamageByPlayerTime > 0;
2019-12-10 23:00:00 +01:00
+ this.dropInventory(); // CraftBukkit - from below
2019-06-21 12:00:00 +02:00
if (this.isDropExperience() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
2019-04-23 04:00:00 +02:00
this.a(damagesource, flag);
this.dropDeathLoot(damagesource, i, flag);
+ // CraftBukkit start - Call death event
+ CraftEventFactory.callEntityDeathEvent(this, this.drops);
+ this.drops = new ArrayList<org.bukkit.inventory.ItemStack>();
+ } else {
+ CraftEventFactory.callEntityDeathEvent(this);
+ // CraftBukkit end
}
2019-12-10 23:00:00 +01:00
- this.dropInventory();
+ // this.dropInventory();// CraftBukkit - moved up
this.dropExperience();
}
2019-12-10 23:00:00 +01:00
protected void dropInventory() {}
- protected void dropExperience() {
+ // CraftBukkit start
+ public int getExpReward() {
if (!this.world.isClientSide && (this.alwaysGivesExp() || this.lastDamageByPlayerTime > 0 && this.isDropExperience() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) {
int i = this.getExpValue(this.killer);
+ return i;
+ } else {
+ return 0;
+ }
+ }
+ // CraftBukkit end
+ protected void dropExperience() {
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
+ if (true) {
+ int i = this.expToDrop;
while (i > 0) {
int j = EntityExperienceOrb.getOrbValue(i);
i -= j;
this.world.addEntity(new EntityExperienceOrb(this.world, this.locX(), this.locY(), this.locZ(), j));
}
+ this.expToDrop = 0;
}
+ // CraftBukkit end
}
@@ -1203,9 +1447,14 @@
int i = this.e(f, f1);
if (i > 0) {
+ // CraftBukkit start
+ if (!this.damageEntity(DamageSource.FALL, (float) i)) {
2019-12-10 23:00:00 +01:00
+ return true;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.a(this.getSoundFall(i), 1.0F, 1.0F);
2019-12-10 23:00:00 +01:00
this.cZ();
- this.damageEntity(DamageSource.FALL, (float) i);
+ // this.damageEntity(DamageSource.FALL, (float) i); // CraftBukkit - moved up
2019-12-10 23:00:00 +01:00
return true;
} else {
return flag;
@@ -1247,7 +1496,7 @@
2016-02-29 22:32:46 +01:00
protected float applyArmorModifier(DamageSource damagesource, float f) {
if (!damagesource.ignoresArmor()) {
- this.damageArmor(f);
2016-02-29 22:32:46 +01:00
+ // this.damageArmor(f); // CraftBukkit - Moved into damageEntity0(DamageSource, float)
2019-04-23 04:00:00 +02:00
f = CombatMath.a(f, (float) this.getArmorStrength(), (float) this.getAttributeInstance(GenericAttributes.ARMOR_TOUGHNESS).getValue());
}
2019-12-10 23:00:00 +01:00
@@ -1260,7 +1509,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;
2019-12-10 23:00:00 +01:00
@@ -1291,28 +1541,170 @@
}
}
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;
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-11-17 02:41:03 +01:00
+ if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !EntityLiving.this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ return -(f - (f * 0.75F));
2019-12-10 23:00:00 +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);
+ }
+ };
+ 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();
2019-12-10 23:00:00 +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;
+ }
2019-04-23 04:00:00 +02:00
+
+ f = (float) event.getFinalDamage();
+
2018-08-26 04:00:00 +02:00
+ // Resistance
+ if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
+ float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
+ if (f3 > 0.0F && f3 < 3.4028235E37F) {
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).a(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
+ } else if (damagesource.getEntity() instanceof EntityPlayer) {
+ ((EntityPlayer) damagesource.getEntity()).a(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
+ }
+ }
+ }
2019-04-23 04:00:00 +02: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) {
2019-04-23 04:00:00 +02:00
+ this.getEquipment(EnumItemSlot.HEAD).damage((int) (event.getDamage() * 4.0F + this.random.nextFloat() * event.getDamage() * 2.0F), this, (entityliving) -> {
+ entityliving.c(EnumItemSlot.HEAD);
+ });
+ }
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);
+ }
2019-12-10 23:00:00 +01:00
- f = Math.max(f - this.getAbsorptionHearts(), 0.0F);
- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f));
- float f2 = f1 - f;
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) {
+ this.world.broadcastEntityEffect(this, (byte) 29); // SPIGOT-4635 - shield damage sound
2016-11-17 02:41:03 +01:00
+ this.damageShield((float) -event.getDamage(DamageModifier.BLOCKING));
2018-07-15 02:00:00 +02:00
+ Entity entity = damagesource.j();
2019-12-10 23:00:00 +01:00
2016-11-17 02:41:03 +01:00
+ if (entity instanceof EntityLiving) {
2019-05-27 22:30:00 +02:00
+ this.shieldBlock((EntityLiving) entity);
+ }
+ }
2019-05-27 22:30:00 +02:00
+
+ absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
+ this.setAbsorptionHearts(Math.max(this.getAbsorptionHearts() - absorptionModifier, 0.0F));
2018-08-26 04:00:00 +02:00
+ float f2 = absorptionModifier;
+
+ if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof EntityHuman) {
+ ((EntityHuman) this).a(StatisticList.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
+ }
2018-08-26 04:00:00 +02:00
if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof EntityPlayer) {
((EntityPlayer) damagesource.getEntity()).a(StatisticList.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
}
- if (f != 0.0F) {
+ if (f > 0 || !human) {
+ 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) {
2018-07-15 02:00:00 +02:00
+ ((EntityHuman) this).a(StatisticList.DAMAGE_TAKEN, Math.round(f * 10.0F));
+ }
+ }
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
float f3 = this.getHealth();
2018-08-26 04:00:00 +02:00
this.setHealth(f3 - f);
this.getCombatTracker().trackDamage(damagesource, f3, 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);
+ }
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);
2018-08-26 04:00:00 +02:00
+ f2 = (float) -event.getDamage(DamageModifier.BLOCKING);
+ if (f2 > 0.0F && f2 < 3.4028235E37F) {
+ ((EntityPlayer) this).a(StatisticList.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
+ }
2017-05-14 04:00:00 +02:00
+ }
+
+ if (damagesource.getEntity() instanceof EntityPlayer) {
+ CriterionTriggers.g.a((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
+ }
+
+ return false;
+ } else {
+ return originalDamage > 0;
+ }
+ // CraftBukkit end
}
}
+ return false; // CraftBukkit
}
2016-02-29 22:32:46 +01:00
public CombatTracker getCombatTracker() {
2019-12-10 23:00:00 +01:00
@@ -1399,6 +1791,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
}
2016-11-17 02:41:03 +01:00
return this.attributeMap;
2019-12-10 23:00:00 +01:00
@@ -1769,6 +2162,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 {
2019-12-10 23:00:00 +01:00
@@ -2166,6 +2560,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);
}
2019-12-10 23:00:00 +01:00
@@ -2294,12 +2689,12 @@
2016-03-27 11:58:45 +02:00
2019-04-23 04:00:00 +02:00
@Override
2016-03-27 11:58:45 +02:00
public boolean isInteractable() {
- return !this.dead;
+ return !this.dead && this.collides; // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
public boolean isCollidable() {
2019-04-23 04:00:00 +02:00
- return this.isAlive() && !this.isClimbing();
+ return this.isAlive() && !this.isClimbing() && this.collides; // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
2019-12-10 23:00:00 +01:00
@@ -2482,7 +2877,27 @@
} else {
if (!this.activeItem.isEmpty() && this.isHandRaised()) {
this.b(this.activeItem, 16);
- this.a(this.getRaisedHand(), this.activeItem.a(this.world, this));
+ // CraftBukkit start - fire PlayerItemConsumeEvent
+ 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);
+
+ if (event.isCancelled()) {
+ // Update client
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
+ return;
+ }
+
2019-12-10 23:00:00 +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);
+ }
+
2019-12-10 23:00:00 +01:00
+ this.a(this.getRaisedHand(), itemstack);
+ // CraftBukkit end
this.dH();
}
2016-02-29 22:32:46 +01:00
2019-12-10 23:00:00 +01:00
@@ -2569,10 +2984,18 @@
}
2019-04-23 04:00:00 +02:00
if (flag2) {
2019-12-10 23:00:00 +01:00
- this.enderTeleportTo(d0, d6, d2);
2019-04-23 04:00:00 +02:00
- if (world.getCubes(this) && !world.containsLiquid(this.getBoundingBox())) {
- flag1 = true;
+ // CraftBukkit start - Teleport event
2019-12-10 23:00:00 +01:00
+ // this.enderTeleportTo(d0, d6, d2);
+ EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), new Location(this.world.getWorld(), d3, d4, d5), new Location(this.world.getWorld(), d0, d6, d2));
+ this.world.getServer().getPluginManager().callEvent(teleport);
+ if (!teleport.isCancelled()) {
+ Location to = teleport.getTo();
+ this.enderTeleportTo(to.getX(), to.getY(), to.getZ());
2019-04-23 04:00:00 +02:00
+ if (world.getCubes(this) && !world.containsLiquid(this.getBoundingBox())) {
+ flag1 = true;
+ }
}
+ // CraftBukkit end
}
}
2019-12-10 23:00:00 +01:00
@@ -2659,7 +3082,7 @@
2019-04-23 04:00:00 +02:00
}
2019-12-10 23:00:00 +01:00
public void entityWakeup() {
2019-04-23 04:00:00 +02:00
- Optional optional = this.getBedPosition();
+ Optional<BlockPosition> optional = this.getBedPosition(); // CraftBukkit - decompile error
World world = this.world;
this.world.getClass();
2019-12-10 23:00:00 +01:00
@@ -2723,7 +3146,7 @@
2019-04-23 04:00:00 +02:00
Pair<MobEffect, Float> pair = (Pair) iterator.next();
if (!world.isClientSide && pair.getLeft() != null && world.random.nextFloat() < (Float) pair.getRight()) {
- entityliving.addEffect(new MobEffect((MobEffect) pair.getLeft()));
+ entityliving.addEffect(new MobEffect((MobEffect) pair.getLeft()), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit
}
}
}