2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/entity/EntityLiving.java
+++ b/net/minecraft/world/entity/EntityLiving.java
2021-06-11 07:00:00 +02:00
@@ -119,6 +119,30 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.scores.ScoreboardTeam;
2020-06-25 02:00:00 +02:00
import org.apache.logging.log4j.Logger;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
+import java.util.ArrayList;
2020-06-25 02:00:00 +02:00
+import java.util.HashSet;
+import java.util.Set;
2014-11-25 22:32:16 +01:00
+import com.google.common.base.Function;
2021-03-15 23:00:00 +01:00
+import net.minecraft.nbt.NBTTagFloat;
+import net.minecraft.nbt.NBTTagInt;
+import net.minecraft.world.entity.animal.EntityAnimal;
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;
2020-09-02 10:52:40 +02:00
+import org.bukkit.event.entity.ArrowBodyCountChangeEvent;
2014-11-25 22:32:16 +01:00
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
2018-07-20 08:04:37 +02:00
+import org.bukkit.event.entity.EntityPotionEffectEvent;
2014-11-25 22:32:16 +01:00
+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 {
2021-06-11 07:00:00 +02:00
private static final UUID SPEED_MODIFIER_SPRINTING_UUID = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
@@ -227,6 +251,21 @@
private float swimAmount;
private float swimAmountO;
protected BehaviorController<?> brain;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ public int expToDrop;
+ public int maxAirTicks = 300;
2021-03-15 23:00:00 +01:00
+ public boolean forceDrops;
+ public ArrayList<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>();
2020-06-25 02:00:00 +02:00
+ public final org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
2016-03-27 11:19:41 +02:00
+ public boolean collides = true;
2020-06-25 02:00:00 +02:00
+ public Set<UUID> collidableExemptions = new HashSet<>();
2021-06-11 07:00:00 +02:00
+ public boolean bukkitPickUpLoot;
2017-11-07 07:21:38 +01:00
+
+ @Override
+ public float getBukkitYaw() {
+ return getHeadRotation();
+ }
2014-11-25 22:32:16 +01:00
+ // 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);
2021-06-11 07:00:00 +02:00
@@ -239,7 +278,9 @@
this.useItem = ItemStack.EMPTY;
this.lastClimbablePos = Optional.empty();
this.attributes = new AttributeMapBase(AttributeDefaults.a(entitytypes));
2014-11-25 22:32:16 +01:00
- this.setHealth(this.getMaxHealth());
2021-06-11 07:00:00 +02:00
+ this.craftAttributes = new CraftAttributeMap(attributes); // CraftBukkit
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
2021-06-11 07:00:00 +02:00
+ this.entityData.set(EntityLiving.DATA_HEALTH_ID, (float) this.getAttributeInstance(GenericAttributes.MAX_HEALTH).getValue());
this.blocksBuilding = true;
this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.ah();
@@ -306,7 +347,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
2021-06-11 07:00:00 +02:00
- ((WorldServer) this.level).a(new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - visiblity api
+ if (this instanceof EntityPlayer) {
2021-06-11 07:00:00 +02:00
+ ((WorldServer) this.level).sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false);
2014-11-25 22:32:16 +01:00
+ } else {
2021-06-11 07:00:00 +02:00
+ ((WorldServer) this.level).a(new ParticleParamBlock(Particles.BLOCK, iblockdata), this.locX(), this.locY(), this.locZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
}
}
2021-06-11 07:00:00 +02:00
@@ -566,7 +613,7 @@
2016-02-29 22:32:46 +01:00
2021-06-11 07:00:00 +02:00
protected void dB() {
++this.deathTime;
- if (this.deathTime == 20 && !this.level.isClientSide()) {
+ if (this.deathTime >= 20 && !this.isRemoved() && !this.level.isClientSide()) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
this.level.broadcastEntityEffect(this, (byte) 60);
this.a(Entity.RemovalReason.KILLED);
}
@@ -658,9 +705,15 @@
2020-12-21 08:30:48 +01:00
}
2021-01-16 02:00:00 +01:00
protected void playEquipSound(ItemStack itemstack) {
2020-12-21 08:30:48 +01:00
+ // CraftBukkit start
2021-01-16 02:00:00 +01:00
+ this.playEquipSound(itemstack, false);
2020-12-21 08:30:48 +01:00
+ }
+
2021-01-16 02:00:00 +01:00
+ protected void playEquipSound(ItemStack itemstack, boolean silent) {
2021-06-11 07:00:00 +02:00
SoundEffect soundeffect = itemstack.M();
2020-12-21 08:30:48 +01:00
2021-06-11 07:00:00 +02:00
- if (!itemstack.isEmpty() && soundeffect != null && !this.isSpectator()) {
+ if (!itemstack.isEmpty() && soundeffect != null && !this.isSpectator() && !silent) {
+ // CraftBukkit end
this.a(GameEvent.EQUIP);
this.playSound(soundeffect, 1.0F, 1.0F);
}
@@ -722,6 +775,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) {
2019-04-23 04:00:00 +02:00
+ this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(((NBTTagFloat) nbtbase).asDouble());
2014-11-25 22:32:16 +01:00
+ } else if (nbtbase.getTypeId() == 3) {
2019-04-23 04:00:00 +02:00
+ this.getAttributeInstance(GenericAttributes.MAX_HEALTH).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"));
}
2021-06-11 07:00:00 +02:00
@@ -759,9 +823,32 @@
2016-02-29 22:32:46 +01:00
2015-02-12 15:00:40 +01:00
}
+ // CraftBukkit start
+ private boolean isTickingEffects = false;
2018-07-20 08:04:37 +02:00
+ 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;
+ }
+ }
2015-02-12 15:00:40 +01:00
+ // CraftBukkit end
+
2016-02-29 22:32:46 +01:00
protected void tickPotionEffects() {
2021-06-11 07:00:00 +02:00
Iterator iterator = this.activeEffects.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();
2021-06-11 07:00:00 +02:00
@@ -771,6 +858,12 @@
this.a(mobeffect, true, (Entity) null);
2020-01-21 22:00:00 +01:00
})) {
2021-06-11 07:00:00 +02:00
if (!this.level.isClientSide) {
2018-07-20 08:04:37 +02:00
+ // 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;
2018-07-20 08:04:37 +02:00
+ }
+ // CraftBukkit end
iterator.remove();
2021-06-11 07:00:00 +02:00
this.a(mobeffect);
2018-07-20 08:04:37 +02:00
}
2021-06-11 07:00:00 +02:00
@@ -781,6 +874,17 @@
2016-11-17 02:41:03 +01:00
} catch (ConcurrentModificationException concurrentmodificationexception) {
;
2015-02-12 15:00:40 +01:00
}
+ // CraftBukkit start
+ isTickingEffects = false;
2018-07-20 08:04:37 +02:00
+ for (ProcessableEffect e : effectsToProcess) {
+ if (e.effect != null) {
+ addEffect(e.effect, e.cause);
2015-02-12 15:00:40 +01:00
+ } else {
2018-07-20 08:04:37 +02:00
+ removeEffect(e.type, e.cause);
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
2021-06-11 07:00:00 +02:00
if (this.effectsDirty) {
if (!this.level.isClientSide) {
@@ -907,7 +1011,13 @@
this.entityData.set(EntityLiving.DATA_EFFECT_COLOR_ID, 0);
2015-02-12 15:00:40 +01:00
}
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
public boolean removeAllEffects() {
+ return removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ public boolean removeAllEffects(EntityPotionEffectEvent.Cause cause) {
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
if (this.level.isClientSide) {
2018-07-20 08:04:37 +02:00
return false;
} else {
2021-06-11 07:00:00 +02:00
@@ -916,7 +1026,14 @@
2018-07-20 08:04:37 +02:00
boolean flag;
for (flag = false; iterator.hasNext(); flag = true) {
2021-06-11 07:00:00 +02:00
- this.a((MobEffect) iterator.next());
2018-07-20 08:04:37 +02:00
+ // 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-20 08:04:37 +02:00
+ }
2021-06-11 07:00:00 +02:00
+ this.a(effect);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
iterator.remove();
}
2021-06-11 07:00:00 +02:00
@@ -945,18 +1062,48 @@
return this.addEffect(mobeffect, (Entity) null);
2018-07-20 08:04:37 +02:00
}
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ public boolean addEffect(MobEffect mobeffect, EntityPotionEffectEvent.Cause cause) {
+ return this.addEffect(mobeffect, (Entity) null, cause);
2018-07-20 08:04:37 +02:00
+ }
+
2021-06-11 07:00:00 +02:00
public boolean addEffect(MobEffect mobeffect, @Nullable Entity entity) {
+ return this.addEffect(mobeffect, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ public boolean addEffect(MobEffect mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) {
2015-02-12 15:00:40 +01:00
+ if (isTickingEffects) {
2018-07-20 08:04:37 +02:00
+ effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
2018-07-15 02:00:00 +02:00
+ return true;
2015-02-12 15:00:40 +01:00
+ }
+ // CraftBukkit end
2018-07-20 08:04:37 +02:00
+
2021-06-11 07:00:00 +02:00
if (!this.c(mobeffect)) {
2018-07-15 02:00:00 +02:00
return false;
} else {
2021-06-11 07:00:00 +02:00
MobEffect mobeffect1 = (MobEffect) this.activeEffects.get(mobeffect.getMobEffect());
2015-02-12 15:00:40 +01:00
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
+ boolean override = false;
+ if (mobeffect1 != null) {
2020-01-21 22:00:00 +01:00
+ override = new MobEffect(mobeffect1).b(mobeffect);
2018-07-20 08:04:37 +02:00
+ }
+
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect1, mobeffect, cause, override);
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
+
if (mobeffect1 == null) {
2021-06-11 07:00:00 +02:00
this.activeEffects.put(mobeffect.getMobEffect(), mobeffect);
this.a(mobeffect, entity);
2018-07-20 08:04:37 +02:00
return true;
2020-01-21 22:00:00 +01:00
- } else if (mobeffect1.b(mobeffect)) {
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
+ } else if (event.isOverride()) {
2020-01-21 22:00:00 +01:00
+ mobeffect1.b(mobeffect);
2021-06-11 07:00:00 +02:00
this.a(mobeffect1, true, entity);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
return true;
} else {
return false;
2021-06-11 07:00:00 +02:00
@@ -993,13 +1140,39 @@
2018-07-20 08:04:37 +02:00
return this.getMonsterType() == EnumMonsterType.UNDEAD;
}
2019-04-23 06:00:30 +02:00
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
2016-05-10 13:47:39 +02:00
@Nullable
public MobEffect c(@Nullable MobEffectList mobeffectlist) {
2018-07-20 08:04:37 +02:00
+ return c(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
+ }
+
+ @Nullable
+ public MobEffect c(@Nullable MobEffectList mobeffectlist, EntityPotionEffectEvent.Cause cause) {
2015-02-12 15:00:40 +01:00
+ if (isTickingEffects) {
2018-07-20 08:04:37 +02:00
+ effectsToProcess.add(new ProcessableEffect(mobeffectlist, cause));
2016-02-29 22:32:46 +01:00
+ return null;
2015-02-12 15:00:40 +01:00
+ }
2018-07-20 08:04:37 +02:00
+
2021-06-11 07:00:00 +02:00
+ MobEffect effect = this.activeEffects.get(mobeffectlist);
2018-07-20 08:04:37 +02:00
+ if (effect == null) {
+ return null;
+ }
+
+ EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, effect, null, cause);
+ if (event.isCancelled()) {
+ return null;
+ }
+
2021-06-11 07:00:00 +02:00
return (MobEffect) this.activeEffects.remove(mobeffectlist);
2016-02-29 22:32:46 +01:00
}
2015-02-12 15:00:40 +01:00
2018-07-20 08:04:37 +02:00
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) {
2021-06-11 07:00:00 +02:00
this.a(mobeffect);
@@ -1036,20 +1209,55 @@
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);
2019-04-23 04:00:00 +02:00
+ // Suppress during worldgen
+ if (this.valid) {
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(event);
2019-04-23 04:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+
+ if (!event.isCancelled()) {
+ this.setHealth((float) (this.getHealth() + event.getAmount()));
+ }
+ // CraftBukkit end
}
}
2018-07-15 02:00:00 +02:00
public float getHealth() {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Use unscaled health
+ if (this instanceof EntityPlayer) {
+ return (float) ((EntityPlayer) this).getBukkitEntity().getHealth();
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
return (Float) this.entityData.get(EntityLiving.DATA_HEALTH_ID);
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);
+ }
+
2018-12-27 01:37:19 +01:00
+ player.updateScaledHealth(false);
2014-11-25 22:32:16 +01:00
+ return;
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.a(f, 0.0F, this.getMaxHealth()));
2014-11-25 22:32:16 +01:00
}
2021-06-11 07:00:00 +02:00
@@ -1063,7 +1271,7 @@
2019-03-06 06:38:02 +01:00
return false;
2021-06-11 07:00:00 +02:00
} else if (this.level.isClientSide) {
2019-03-06 06:38:02 +01:00
return false;
2021-06-11 07:00:00 +02:00
- } else if (this.dV()) {
+ } else if (this.isRemoved() || this.dead || this.getHealth() <= 0.0F) { // CraftBukkit - Don't allow entities that got set to dead/killed elsewhere to get damaged and die
2019-03-06 06:38:02 +01:00
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;
2021-06-11 07:00:00 +02:00
@@ -1074,10 +1282,11 @@
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
this.noActionTime = 0;
float f1 = f;
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;
2021-06-11 07:00:00 +02:00
@@ -1095,27 +1304,47 @@
this.animationSpeed = 1.5F;
2020-12-27 22:28:57 +01:00
boolean flag1 = true;
2018-08-26 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
- if ((float) this.invulnerableTime > 10.0F) {
+ if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F) { // CraftBukkit - restore use of maxNoDamageTicks
if (f <= this.lastHurt) {
2018-08-26 04:00:00 +02:00
+ this.forceExplosionKnockback = true; // CraftBukkit - SPIGOT-949 - for vanilla consistency, cooldown does not prevent explosion knockback
return false;
2014-11-25 22:32:16 +01:00
}
2021-06-11 07:00:00 +02:00
- this.damageEntity0(damagesource, f - this.lastHurt);
2014-12-09 15:40:38 +01:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ if (!this.damageEntity0(damagesource, f - this.lastHurt)) {
2018-08-26 04:00:00 +02:00
+ return false;
2014-12-09 15:40:38 +01:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.lastHurt = f;
2018-08-26 04:00:00 +02:00
flag1 = false;
} else {
+ // CraftBukkit start
+ if (!this.damageEntity0(damagesource, f)) {
+ return false;
+ }
2021-06-11 07:00:00 +02:00
this.lastHurt = f;
- this.invulnerableTime = 20;
2018-08-26 04:00:00 +02:00
- this.damageEntity0(damagesource, f);
2021-06-11 07:00:00 +02:00
+ this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks
2018-08-26 04:00:00 +02:00
+ // this.damageEntity0(damagesource, f);
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.hurtDuration = 10;
2021-06-11 07:00:00 +02:00
this.hurtTime = this.hurtDuration;
}
- if (damagesource.g() && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ // CraftBukkit - Moved into damageEntity0(DamageSource, float)
+ if (false && damagesource.g() && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
this.damageHelmet(damagesource, f);
f *= 0.75F;
2018-08-26 04:00:00 +02:00
}
+ // CraftBukkit start
+ if (this instanceof EntityAnimal) {
+ ((EntityAnimal) this).resetLove();
+ if (this instanceof EntityTameableAnimal) {
2020-06-25 02:00:00 +02:00
+ ((EntityTameableAnimal) this).setWillSit(false);
2018-08-26 04:00:00 +02:00
+ }
+ }
+ // CraftBukkit end
2014-12-09 15:40:38 +01:00
+
2021-06-11 07:00:00 +02:00
this.hurtDir = 0.0F;
2018-08-26 04:00:00 +02:00
Entity entity1 = damagesource.getEntity();
2016-11-17 02:41:03 +01:00
2021-06-11 07:00:00 +02:00
@@ -1238,19 +1467,29 @@
2016-12-10 02:16:14 +01:00
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ ItemStack itemstack1 = ItemStack.EMPTY;
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
2021-06-11 07:00:00 +02:00
if (itemstack1.a(Items.TOTEM_OF_UNDYING)) {
2017-05-14 04:00:00 +02:00
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) {
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);
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(event);
2016-11-17 02:41:03 +01:00
+
2017-06-23 04:47:29 +02:00
+ if (!event.isCancelled()) {
2018-03-23 09:40:16 +01:00
+ 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));
2021-06-11 07:00:00 +02:00
@@ -1258,14 +1497,16 @@
2018-07-20 08:04:37 +02:00
}
this.setHealth(1.0F);
- this.removeAllEffects();
- this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1));
2021-06-11 07:00:00 +02:00
- this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1));
2020-08-11 23:00:00 +02:00
- this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0));
2018-07-20 08:04:37 +02:00
+ // 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);
2021-06-11 07:00:00 +02:00
+ this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
2020-08-11 23:00:00 +02:00
+ this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.level.broadcastEntityEffect(this, (byte) 35);
2017-06-23 04:47:29 +02:00
}
- return itemstack != null;
+ return !event.isCancelled();
}
}
2021-09-06 10:57:16 +02:00
@@ -1370,14 +1611,22 @@
IBlockData iblockdata = Blocks.WITHER_ROSE.getBlockData();
if (this.level.getType(blockposition).isAir() && iblockdata.canPlace(this.level, blockposition)) {
- this.level.setTypeAndData(blockposition, iblockdata, 3);
- flag = true;
+ // CraftBukkit start - call EntityBlockFormEvent for Wither Rose
+ flag = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this.level, blockposition, iblockdata, 3, this);
+ // CraftBukkit end
}
}
2021-01-29 00:19:39 +01:00
if (!flag) {
2021-06-11 07:00:00 +02:00
EntityItem entityitem = new EntityItem(this.level, this.locX(), this.locY(), this.locZ(), new ItemStack(Items.WITHER_ROSE));
2021-01-29 00:19:39 +01:00
+ // CraftBukkit start
+ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
+ CraftEventFactory.callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.level.addEntity(entityitem);
2021-01-29 00:19:39 +01:00
}
}
2021-09-06 10:57:16 +02:00
@@ -1397,21 +1646,40 @@
2019-08-02 11:13:16 +02:00
2021-06-11 07:00:00 +02:00
boolean flag = this.lastHurtByPlayerTime > 0;
2019-08-02 11:13:16 +02:00
2019-12-10 23:00:00 +01:00
+ this.dropInventory(); // CraftBukkit - from below
2021-06-11 07:00:00 +02:00
if (this.dD() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
2019-04-23 04:00:00 +02:00
this.a(damagesource, flag);
this.dropDeathLoot(damagesource, i, flag);
}
2020-07-22 10:45:52 +02:00
+ // CraftBukkit start - Call death event
+ CraftEventFactory.callEntityDeathEvent(this, this.drops);
+ this.drops = new ArrayList<>();
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
2019-12-10 23:00:00 +01:00
- this.dropInventory();
+ // this.dropInventory();// CraftBukkit - moved up
this.dropExperience();
2019-08-02 11:13:16 +02:00
}
2019-12-10 23:00:00 +01:00
protected void dropInventory() {}
- protected void dropExperience() {
+ // CraftBukkit start
+ public int getExpReward() {
2021-06-11 07:00:00 +02:00
if (this.level instanceof WorldServer && (this.alwaysGivesExp() || this.lastHurtByPlayerTime > 0 && this.isDropExperience() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
- EntityExperienceOrb.a((WorldServer) this.level, this.getPositionVector(), this.getExpValue(this.lastHurtByPlayer));
+ int i = this.getExpValue(this.lastHurtByPlayer);
2019-12-10 23:00:00 +01:00
+ return i;
+ } else {
+ return 0;
+ }
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
+
2019-12-10 23:00:00 +01:00
+ protected void dropExperience() {
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
+ if (true) {
2021-06-11 07:00:00 +02:00
+ EntityExperienceOrb.a((WorldServer) this.level, this.getPositionVector(), this.expToDrop);
2019-12-10 23:00:00 +01:00
+ this.expToDrop = 0;
}
+ // CraftBukkit end
}
2021-09-06 10:57:16 +02:00
@@ -1527,9 +1795,14 @@
2021-06-11 07:00:00 +02:00
int i = this.d(f, f1);
2014-11-25 22:32:16 +01:00
if (i > 0) {
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ if (!this.damageEntity(damagesource, (float) i)) {
2019-12-10 23:00:00 +01:00
+ return true;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.playSound(this.getSoundFall(i), 1.0F, 1.0F);
this.playBlockStepSound();
2021-06-11 07:00:00 +02:00
- this.damageEntity(damagesource, (float) i);
+ // this.damageEntity(damagesource, (float) i); // CraftBukkit - moved up
2019-12-10 23:00:00 +01:00
return true;
} else {
return flag;
2021-09-06 10:57:16 +02:00
@@ -1578,7 +1851,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()) {
2020-06-25 02:00:00 +02:00
- this.damageArmor(damagesource, f);
+ // this.damageArmor(damagesource, f); // CraftBukkit - Moved into damageEntity0(DamageSource, float)
f = CombatMath.a(f, (float) this.getArmorStrength(), (float) this.b(GenericAttributes.ARMOR_TOUGHNESS));
2014-11-25 22:32:16 +01:00
}
2021-09-06 10:57:16 +02:00
@@ -1591,7 +1864,8 @@
2016-02-29 22:32:46 +01:00
} else {
int i;
2021-06-11 07:00:00 +02:00
- if (this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
2016-02-29 22:32:46 +01:00
+ // CraftBukkit - Moved to damageEntity0(DamageSource, float)
2021-06-11 07:00:00 +02:00
+ if (false && this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
2016-02-29 22:32:46 +01:00
int j = 25 - i;
float f1 = f * (float) j;
2021-09-06 10:57:16 +02:00
@@ -1622,29 +1896,172 @@
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;
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) {
2021-06-11 07:00:00 +02:00
+ if (damagesource.g() && !EntityLiving.this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
2014-11-25 22:32:16 +01:00
+ return -(f - (f * 0.75F));
2020-12-22 21:53:45 +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) {
2021-06-11 07:00:00 +02:00
+ if (!damagesource.isStarvation() && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
+ int i = (EntityLiving.this.getEffect(MobEffects.DAMAGE_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();
2019-12-10 23:00:00 +01: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);
2020-04-23 03:13:40 +02:00
+ if (damagesource.getEntity() instanceof EntityHuman) {
2020-06-25 02:00:00 +02:00
+ ((EntityHuman) damagesource.getEntity()).resetAttackCooldown(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
2020-04-23 03:13:40 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ if (event.isCancelled()) {
+ return false;
+ }
2021-06-11 07:00:00 +02:00
- f = Math.max(f - this.getAbsorptionHearts(), 0.0F);
- this.setAbsorptionHearts(this.getAbsorptionHearts() - (f1 - f));
- float f2 = f1 - f;
2014-11-25 22:32:16 +01:00
+ f = (float) event.getFinalDamage();
2021-06-11 07:00:00 +02:00
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));
+ }
+ }
+ }
2021-06-11 07:00:00 +02:00
+
2014-11-25 22:32:16 +01:00
+ // Apply damage to helmet
2021-06-11 07:00:00 +02:00
+ if (damagesource.g() && !this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ this.damageHelmet(damagesource, f);
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));
2020-06-25 02:00:00 +02:00
+ this.damageArmor(damagesource, armorDamage);
2014-11-25 22:32:16 +01:00
+ }
2021-06-11 07:00:00 +02: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) {
2021-06-11 07:00:00 +02:00
+ this.level.broadcastEntityEffect(this, (byte) 29); // SPIGOT-4635 - shield damage sound
2016-11-17 02:41:03 +01:00
+ this.damageShield((float) -event.getDamage(DamageModifier.BLOCKING));
2021-06-11 07:00:00 +02:00
+ Entity entity = damagesource.k();
2021-05-25 00:24:08 +02: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);
2016-03-26 04:10:29 +01:00
+ }
2016-03-18 09:04:23 +01:00
+ }
2020-12-21 08:30:48 +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));
2018-08-26 04:00:00 +02:00
+ float f2 = absorptionModifier;
2018-09-17 08:40:35 +02:00
+
+ 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) {
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.
2021-03-03 22:28:05 +01:00
+ ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
2015-04-09 02:18:21 +02:00
+ if (f < 3.4028235E37F) {
2018-07-15 02:00:00 +02:00
+ ((EntityHuman) this).a(StatisticList.DAMAGE_TAKEN, Math.round(f * 10.0F));
2015-04-09 02:18:21 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
float f3 = this.getHealth();
2014-11-25 22:32:16 +01:00
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);
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
+ }
2021-06-11 07:00:00 +02:00
this.a(GameEvent.ENTITY_DAMAGED, damagesource.getEntity());
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) {
2021-06-11 07:00:00 +02:00
+ CriterionTriggers.ENTITY_HURT_PLAYER.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) {
2021-06-11 07:00:00 +02:00
+ CriterionTriggers.PLAYER_HURT_ENTITY.a((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
2017-05-14 04:00:00 +02:00
+ }
+
+ 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() {
2021-09-06 10:57:16 +02:00
@@ -1665,8 +2082,18 @@
2020-09-02 10:52:40 +02:00
}
public final void setArrowCount(int i) {
2021-06-11 07:00:00 +02:00
- this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, i);
2020-09-02 10:52:40 +02:00
+ // CraftBukkit start
+ setArrowCount(i, false);
2021-06-11 07:00:00 +02:00
+ }
+
2020-09-02 10:52:40 +02:00
+ public final void setArrowCount(int i, boolean flag) {
+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, getArrowCount(), i, flag);
+ if (event.isCancelled()) {
+ return;
+ }
2021-06-11 07:00:00 +02:00
+ this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, event.getNewAmount());
2020-09-02 10:52:40 +02:00
}
2021-06-11 07:00:00 +02:00
+ // CraftBukkit end
public final int eh() {
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
2021-09-06 10:57:16 +02:00
@@ -1962,6 +2389,12 @@
2020-12-22 21:53:45 +01:00
public abstract ItemStack getEquipment(EnumItemSlot enumitemslot);
+ // CraftBukkit start
+ public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) {
+ this.setSlot(enumitemslot, itemstack);
+ }
+ // CraftBukkit end
+
@Override
public abstract void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
2021-09-06 10:57:16 +02:00
@@ -2205,6 +2638,7 @@
2016-03-12 10:57:32 +01:00
}
2021-06-11 07:00:00 +02:00
if (this.onGround && !this.level.isClientSide) {
2016-03-12 10:57:32 +01:00
+ if (getFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setFlag(7, false);
}
} else {
2021-09-06 10:57:16 +02:00
@@ -2735,6 +3169,7 @@
2016-03-12 10:57:32 +01:00
}
2021-06-11 07:00:00 +02:00
if (!this.level.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);
}
2021-09-06 10:57:16 +02:00
@@ -2902,14 +3337,21 @@
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() {
2021-06-11 07:00:00 +02:00
- return !this.isRemoved();
+ return !this.isRemoved() && this.collides; // CraftBukkit
2016-03-27 11:19:41 +02:00
}
2019-04-23 04:00:00 +02:00
@Override
2016-03-27 11:19:41 +02:00
public boolean isCollidable() {
2020-08-11 23:00:00 +02:00
- return this.isAlive() && !this.isSpectator() && !this.isClimbing();
+ return this.isAlive() && !this.isSpectator() && !this.isClimbing() && this.collides; // CraftBukkit
2021-06-11 07:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start - collidable API
+ @Override
2021-06-11 07:00:00 +02:00
+ public boolean canCollideWithBukkit(Entity entity) {
2020-06-25 02:00:00 +02:00
+ return isCollidable() && this.collides != this.collidableExemptions.contains(entity.getUniqueID());
2021-06-11 07:00:00 +02:00
+ }
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
+
2019-04-23 04:00:00 +02:00
@Override
2020-06-25 02:00:00 +02:00
protected void velocityChanged() {
2021-06-11 07:00:00 +02:00
this.hurtMarked = this.random.nextDouble() >= this.b(GenericAttributes.KNOCKBACK_RESISTANCE);
2021-09-06 10:57:16 +02:00
@@ -3107,7 +3549,25 @@
2019-12-10 23:00:00 +01:00
} else {
2021-06-11 07:00:00 +02:00
if (!this.useItem.isEmpty() && this.isHandRaised()) {
this.b(this.useItem, 16);
- ItemStack itemstack = this.useItem.a(this.level, this);
2019-12-10 23:00:00 +01:00
+ // CraftBukkit start - fire PlayerItemConsumeEvent
+ ItemStack itemstack;
+ if (this instanceof EntityPlayer) {
2021-06-11 07:00:00 +02:00
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
2019-12-10 23:00:00 +01:00
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
2021-06-11 13:33:49 +02:00
+ level.getCraftServer().getPluginManager().callEvent(event);
2019-12-10 23:00:00 +01:00
+
+ if (event.isCancelled()) {
+ // Update client
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ ((EntityPlayer) this).getBukkitEntity().updateScaledHealth();
+ return;
+ }
2015-01-16 04:48:42 +01:00
+
2021-06-11 07:00:00 +02:00
+ itemstack = (craftItem.equals(event.getItem())) ? this.useItem.a(this.level, this) : CraftItemStack.asNMSCopy(event.getItem()).a(level, this);
2019-12-10 23:00:00 +01:00
+ } else {
2021-06-11 07:00:00 +02:00
+ itemstack = this.useItem.a(this.level, this);
2015-01-16 04:48:42 +01:00
+ }
2019-12-10 23:00:00 +01:00
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
2021-06-11 07:00:00 +02:00
if (itemstack != this.useItem) {
2020-08-11 23:00:00 +02:00
this.a(enumhand, itemstack);
2021-09-06 10:57:16 +02:00
@@ -3179,6 +3639,12 @@
2021-05-25 00:24:08 +02:00
}
public boolean a(double d0, double d1, double d2, boolean flag) {
+ // CraftBukkit start
+ return safeTeleport(d0, d1, d2, flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN).orElse(false);
+ }
+
+ public Optional<Boolean> safeTeleport(double d0, double d1, double d2, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ // CraftBukkit end
double d3 = this.locX();
double d4 = this.locY();
double d5 = this.locZ();
2021-09-06 10:57:16 +02:00
@@ -3203,16 +3669,41 @@
2016-04-08 11:06:31 +02:00
}
2019-04-23 04:00:00 +02:00
if (flag2) {
2019-12-10 23:00:00 +01:00
- this.enderTeleportTo(d0, d6, d2);
2016-04-08 11:06:31 +02:00
+ // CraftBukkit start - Teleport event
2019-12-10 23:00:00 +01:00
+ // this.enderTeleportTo(d0, d6, d2);
2021-05-25 00:24:08 +02:00
+
+ // first set position, to check if the place to teleport is valid
+ this.setPosition(d0, d6, d2);
if (world.getCubes(this) && !world.containsLiquid(this.getBoundingBox())) {
flag1 = true;
2016-04-08 11:06:31 +02:00
}
2021-05-25 00:24:08 +02:00
+ // now revert and call event if the teleport place is valid
+ this.setPosition(d3, d4, d5);
+
+ if (flag1) {
+ if (!(this instanceof EntityPlayer)) {
2021-06-11 07:00:00 +02:00
+ EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), new Location(this.level.getWorld(), d3, d4, d5), new Location(this.level.getWorld(), d0, d6, d2));
2021-06-11 13:33:49 +02:00
+ this.level.getCraftServer().getPluginManager().callEvent(teleport);
2021-05-25 00:24:08 +02:00
+ if (!teleport.isCancelled()) {
+ Location to = teleport.getTo();
+ this.enderTeleportTo(to.getX(), to.getY(), to.getZ());
+ } else {
+ return Optional.empty();
+ }
+ } else {
+ // player teleport event is called in the underlining code
2021-06-11 07:00:00 +02:00
+ if (((EntityPlayer) this).connection.a(d0, d6, d2, this.getYRot(), this.getXRot(), java.util.Collections.emptySet(), false, cause)) {
2021-05-25 00:24:08 +02:00
+ return Optional.empty();
+ }
+ }
+ }
2016-06-12 04:51:53 +02:00
+ // CraftBukkit end
}
}
2021-05-25 00:24:08 +02:00
if (!flag1) {
- this.enderTeleportTo(d3, d4, d5);
- return false;
+ // this.enderTeleportTo(d3, d4, d5); // CraftBukkit - already set the location back
+ return Optional.of(false); // CraftBukkit
} else {
if (flag) {
world.broadcastEntityEffect(this, (byte) 46);
2021-09-06 10:57:16 +02:00
@@ -3222,7 +3713,7 @@
2021-05-25 00:24:08 +02:00
((EntityCreature) this).getNavigation().o();
}
- return true;
+ return Optional.of(true); // CraftBukkit
}
}
2021-09-06 10:57:16 +02:00
@@ -3305,7 +3796,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
2021-06-11 07:00:00 +02:00
World world = this.level;
java.util.Objects.requireNonNull(this.level);
2021-09-06 10:57:16 +02:00
@@ -3337,7 +3828,7 @@
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
@Nullable
2021-07-06 16:00:00 +02:00
public EnumDirection eX() {
2021-06-11 07:00:00 +02:00
- BlockPosition blockposition = (BlockPosition) this.getBedPosition().orElse((Object) null);
+ BlockPosition blockposition = (BlockPosition) this.getBedPosition().orElse(null); // CraftBukkit - decompile error
return blockposition != null ? BlockBed.a((IBlockAccess) this.level, blockposition) : null;
}
2021-09-06 10:57:16 +02:00
@@ -3386,7 +3877,7 @@
2019-04-23 04:00:00 +02:00
Pair<MobEffect, Float> pair = (Pair) iterator.next();
2020-06-25 02:00:00 +02:00
if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) {
- entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst()));
+ entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst()), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
}