2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/entity/EntityLiving.java
+++ b/net/minecraft/world/entity/EntityLiving.java
2024-06-13 17:05:00 +02:00
@@ -132,6 +132,32 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.scores.ScoreboardTeam;
2022-02-28 16:00:00 +01:00
import org.slf4j.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;
2024-06-13 17:05:00 +02:00
+import java.util.UUID;
2021-03-15 23:00:00 +01:00
+import net.minecraft.nbt.NBTTagFloat;
+import net.minecraft.nbt.NBTTagInt;
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;
2024-01-27 04:53:41 +01:00
+import org.bukkit.event.entity.EntityKnockbackEvent;
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;
2024-02-21 10:55:34 +01:00
+import org.bukkit.event.entity.EntityRemoveEvent;
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
+
2023-03-14 17:30:00 +01:00
public abstract class EntityLiving extends Entity implements Attackable {
2014-11-25 22:32:16 +01:00
2022-02-28 16:00:00 +01:00
private static final Logger LOGGER = LogUtils.getLogger();
2024-09-07 10:08:13 +02:00
@@ -157,7 +183,7 @@
private static final double MAX_LINE_OF_SIGHT_TEST_RANGE = 128.0D;
protected static final int LIVING_ENTITY_FLAG_IS_USING = 1;
protected static final int LIVING_ENTITY_FLAG_OFF_HAND = 2;
- protected static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4;
+ public static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4;
protected static final DataWatcherObject<Byte> DATA_LIVING_ENTITY_FLAGS = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.BYTE);
public static final DataWatcherObject<Float> DATA_HEALTH_ID = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.FLOAT);
private static final DataWatcherObject<List<ParticleParam>> DATA_EFFECT_PARTICLES = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.PARTICLES);
2024-06-13 17:05:00 +02:00
@@ -249,6 +275,19 @@
2024-04-23 17:15:00 +02:00
protected boolean skipDropExperience;
2024-06-13 17:05:00 +02:00
private final Reference2ObjectMap<Enchantment, Set<EnchantmentLocationBasedEffect>> activeLocationDependentEnchantments;
2024-04-23 17:15:00 +02:00
protected float appliedScale;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ public int expToDrop;
2021-03-15 23:00:00 +01:00
+ 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() {
2021-11-21 23:00:00 +01:00
+ return getYHeadRot();
2017-11-07 07:21:38 +01:00
+ }
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);
2024-06-13 17:05:00 +02:00
@@ -264,7 +303,9 @@
this.activeLocationDependentEnchantments = new Reference2ObjectArrayMap();
2024-04-23 17:15:00 +02:00
this.appliedScale = 1.0F;
2021-11-21 23:00:00 +01:00
this.attributes = new AttributeMapBase(AttributeDefaults.getSupplier(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-11-21 23:00:00 +01:00
+ this.entityData.set(EntityLiving.DATA_HEALTH_ID, (float) this.getAttribute(GenericAttributes.MAX_HEALTH).getValue());
2021-06-11 07:00:00 +02:00
this.blocksBuilding = true;
this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
2021-11-21 23:00:00 +01:00
this.reapplyPosition();
2024-06-13 17:05:00 +02:00
@@ -344,7 +385,13 @@
double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
int i = (int) (150.0D * d8);
- ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ // CraftBukkit start - visiblity api
+ if (this instanceof EntityPlayer) {
+ ((WorldServer) this.level()).sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false);
+ } else {
+ ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D);
+ }
+ // CraftBukkit end
}
2024-04-23 17:15:00 +02:00
}
2014-11-25 22:32:16 +01:00
}
2024-06-13 17:05:00 +02:00
@@ -555,7 +602,7 @@
2024-02-21 10:55:34 +01:00
++this.deathTime;
if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) {
this.level().broadcastEntityEvent(this, (byte) 60);
- this.remove(Entity.RemovalReason.KILLED);
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
}
}
2024-06-13 17:05:00 +02:00
@@ -661,13 +708,19 @@
2020-12-21 08:30:48 +01:00
}
2022-06-07 18:00:00 +02:00
public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1) {
2020-12-21 08:30:48 +01:00
+ // CraftBukkit start
2022-06-07 18:00:00 +02:00
+ onEquipItem(enumitemslot, itemstack, itemstack1, false);
2020-12-21 08:30:48 +01:00
+ }
+
2022-06-07 18:00:00 +02:00
+ public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
2020-12-21 08:30:48 +01:00
2024-04-23 17:15:00 +02:00
if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
2023-03-14 17:30:00 +01:00
Equipable equipable = Equipable.get(itemstack1);
2023-09-21 18:40:00 +02:00
if (!this.level().isClientSide() && !this.isSpectator()) {
- if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot) {
+ if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot && !silent) { // CraftBukkit
2024-04-23 17:15:00 +02:00
this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
2023-03-14 17:30:00 +01:00
}
2022-06-07 18:00:00 +02:00
2024-06-13 17:05:00 +02:00
@@ -681,11 +734,18 @@
2024-02-21 10:55:34 +01:00
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
+ // CraftBukkit start - add Bukkit remove cause
+ this.remove(entity_removalreason, null);
+ }
+
+ @Override
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ // CraftBukkit end
2024-04-23 17:15:00 +02:00
if (entity_removalreason == Entity.RemovalReason.KILLED || entity_removalreason == Entity.RemovalReason.DISCARDED) {
2024-06-13 17:05:00 +02:00
this.triggerOnDeathMobEffects(entity_removalreason);
2024-04-23 17:15:00 +02:00
}
- super.remove(entity_removalreason);
+ super.remove(entity_removalreason, cause); // CraftBukkit
2024-02-21 10:55:34 +01:00
this.brain.clearMemories();
}
2024-06-18 23:10:02 +02:00
@@ -698,6 +758,7 @@
mobeffect.onMobRemoved(this, entity_removalreason);
}
+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.DEATH); // CraftBukkit
this.activeEffects.clear();
}
@@ -757,6 +818,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
2021-11-21 23:00:00 +01:00
+ if (nbttagcompound.contains("Bukkit.MaxHealth")) {
2014-11-25 22:32:16 +01:00
+ NBTBase nbtbase = nbttagcompound.get("Bukkit.MaxHealth");
2021-11-21 23:00:00 +01:00
+ if (nbtbase.getId() == 5) {
+ this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(((NBTTagFloat) nbtbase).getAsDouble());
+ } else if (nbtbase.getId() == 3) {
+ this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(((NBTTagInt) nbtbase).getAsDouble());
2014-11-25 22:32:16 +01:00
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2021-11-21 23:00:00 +01:00
if (nbttagcompound.contains("Health", 99)) {
2016-02-29 22:32:46 +01:00
this.setHealth(nbttagcompound.getFloat("Health"));
}
2024-06-18 23:10:02 +02:00
@@ -795,9 +867,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 {
+
2024-04-23 17:15:00 +02:00
+ private Holder<MobEffectList> type;
2018-07-20 08:04:37 +02:00
+ private MobEffect effect;
+ private final EntityPotionEffectEvent.Cause cause;
+
+ private ProcessableEffect(MobEffect effect, EntityPotionEffectEvent.Cause cause) {
+ this.effect = effect;
+ this.cause = cause;
+ }
+
2024-04-23 17:15:00 +02:00
+ private ProcessableEffect(Holder<MobEffectList> type, EntityPotionEffectEvent.Cause cause) {
2018-07-20 08:04:37 +02:00
+ this.type = type;
+ this.cause = cause;
+ }
+ }
2015-02-12 15:00:40 +01:00
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
protected void tickEffects() {
2024-04-23 17:15:00 +02:00
Iterator<Holder<MobEffectList>> 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()) {
2024-04-23 17:15:00 +02:00
Holder<MobEffectList> holder = (Holder) iterator.next();
2024-06-18 23:10:02 +02:00
@@ -807,6 +902,12 @@
2021-11-21 23:00:00 +01:00
this.onEffectUpdated(mobeffect, true, (Entity) null);
2020-01-21 22:00:00 +01:00
})) {
2023-06-07 17:30: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-11-21 23:00:00 +01:00
this.onEffectRemoved(mobeffect);
2018-07-20 08:04:37 +02:00
}
2024-06-18 23:10:02 +02:00
@@ -817,6 +918,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) {
2023-06-07 17:30:00 +02:00
if (!this.level().isClientSide) {
2024-06-18 23:10:02 +02:00
@@ -932,7 +1044,13 @@
2024-04-23 17:15:00 +02:00
this.entityData.set(EntityLiving.DATA_EFFECT_PARTICLES, List.of());
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
2023-06-07 17:30:00 +02:00
if (this.level().isClientSide) {
2018-07-20 08:04:37 +02:00
return false;
} else {
2024-06-18 23:10:02 +02:00
@@ -941,7 +1059,14 @@
2018-07-20 08:04:37 +02:00
boolean flag;
for (flag = false; iterator.hasNext(); flag = true) {
2021-11-21 23:00:00 +01:00
- this.onEffectRemoved((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-11-21 23:00:00 +01:00
+ this.onEffectRemoved(effect);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
iterator.remove();
}
2024-06-18 23:10:02 +02:00
@@ -970,20 +1095,50 @@
2021-06-11 07:00:00 +02:00
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-11-21 23:00:00 +01:00
if (!this.canBeAffected(mobeffect)) {
2018-07-15 02:00:00 +02:00
return false;
} else {
2021-11-21 23:00:00 +01:00
MobEffect mobeffect1 = (MobEffect) this.activeEffects.get(mobeffect.getEffect());
2023-09-21 18:40:00 +02:00
boolean flag = false;
2015-02-12 15:00:40 +01:00
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
+ boolean override = false;
+ if (mobeffect1 != null) {
2021-11-21 23:00:00 +01:00
+ override = new MobEffect(mobeffect1).update(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-11-21 23:00:00 +01:00
this.activeEffects.put(mobeffect.getEffect(), mobeffect);
this.onEffectAdded(mobeffect, entity);
2023-09-21 18:40:00 +02:00
flag = true;
2024-04-23 17:15:00 +02:00
mobeffect.onEffectAdded(this);
2021-11-21 23:00:00 +01:00
- } else if (mobeffect1.update(mobeffect)) {
2018-07-20 08:04:37 +02:00
+ // CraftBukkit start
+ } else if (event.isOverride()) {
2021-11-21 23:00:00 +01:00
+ mobeffect1.update(mobeffect);
this.onEffectUpdated(mobeffect1, true, entity);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
2023-09-21 18:40:00 +02:00
flag = true;
}
2024-06-18 23:10:02 +02:00
@@ -1014,13 +1169,39 @@
2024-04-23 17:15:00 +02:00
return this.getType().is(TagsEntity.INVERTED_HEALING_AND_HARM);
2018-07-20 08:04:37 +02:00
}
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
2024-04-23 17:15:00 +02:00
public MobEffect removeEffectNoUpdate(Holder<MobEffectList> holder) {
+ return removeEffectNoUpdate(holder, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
2018-07-20 08:04:37 +02:00
+ }
+
+ @Nullable
2024-04-23 17:15:00 +02:00
+ public MobEffect removeEffectNoUpdate(Holder<MobEffectList> holder, EntityPotionEffectEvent.Cause cause) {
2015-02-12 15:00:40 +01:00
+ if (isTickingEffects) {
2024-04-23 17:15:00 +02:00
+ effectsToProcess.add(new ProcessableEffect(holder, 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
+
2024-04-23 17:15:00 +02:00
+ MobEffect effect = this.activeEffects.get(holder);
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;
+ }
+
2024-04-23 17:15:00 +02:00
return (MobEffect) this.activeEffects.remove(holder);
2016-02-29 22:32:46 +01:00
}
2015-02-12 15:00:40 +01:00
2024-04-23 17:15:00 +02:00
public boolean removeEffect(Holder<MobEffectList> holder) {
- MobEffect mobeffect = this.removeEffectNoUpdate(holder);
+ return removeEffect(holder, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN);
2018-07-20 08:04:37 +02:00
+ }
+
2024-04-23 17:15:00 +02:00
+ public boolean removeEffect(Holder<MobEffectList> holder, EntityPotionEffectEvent.Cause cause) {
+ MobEffect mobeffect = this.removeEffectNoUpdate(holder, cause);
2018-07-20 08:04:37 +02:00
+ // CraftBukkit end
if (mobeffect != null) {
2021-11-21 23:00:00 +01:00
this.onEffectRemoved(mobeffect);
2024-06-18 23:10:02 +02:00
@@ -1118,20 +1299,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) {
2023-06-07 17:30:00 +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-11-21 23:00:00 +01:00
this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.clamp(f, 0.0F, this.getMaxHealth()));
2014-11-25 22:32:16 +01:00
}
2024-06-18 23:10:02 +02:00
@@ -1145,7 +1361,7 @@
2019-03-06 06:38:02 +01:00
return false;
2023-06-07 17:30:00 +02:00
} else if (this.level().isClientSide) {
2019-03-06 06:38:02 +01:00
return false;
2021-11-21 23:00:00 +01:00
- } else if (this.isDeadOrDying()) {
2021-06-11 07:00:00 +02:00
+ } 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;
2023-03-14 17:30:00 +01:00
} else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
2019-03-06 06:38:02 +01:00
return false;
2024-06-18 23:10:02 +02:00
@@ -1156,10 +1372,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;
2021-11-21 23:00:00 +01:00
+ boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below
2018-08-26 04:00:00 +02:00
float f2 = 0.0F;
2021-11-21 23:00:00 +01:00
- if (f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
2024-06-23 19:32:25 +02:00
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float) for get f and actuallyHurt(DamageSource, float, EntityDamageEvent) for handle damage
2021-11-21 23:00:00 +01:00
+ if (false && f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
this.hurtCurrentlyUsedShield(f);
2018-08-26 04:00:00 +02:00
f2 = f;
f = 0.0F;
2024-06-22 10:46:41 +02:00
@@ -1176,30 +1393,50 @@
flag = true;
}
- if (damagesource.is(DamageTypeTags.IS_FREEZING) && this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
2024-06-23 19:32:25 +02:00
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float) for get f
2024-06-22 10:46:41 +02:00
+ if (false && damagesource.is(DamageTypeTags.IS_FREEZING) && this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
2024-04-23 17:15:00 +02:00
f *= 5.0F;
}
- if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
2024-06-23 19:32:25 +02:00
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float) for get f and actuallyHurt(DamageSource, float, EntityDamageEvent) for handle damage
2024-04-23 17:15:00 +02:00
+ if (false && damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
this.hurtHelmet(damagesource, f);
f *= 0.75F;
}
2024-06-22 10:46:41 +02:00
+ // CraftBukkit start
+ EntityDamageEvent event = handleEntityDamage(damagesource, f);
+ f = 0;
+ f += (float) event.getDamage(DamageModifier.BASE);
+ f += (float) event.getDamage(DamageModifier.BLOCKING);
+ f += (float) event.getDamage(DamageModifier.FREEZING);
+ f += (float) event.getDamage(DamageModifier.HARD_HAT);
+ // CraftBukkit end
+
2023-03-14 17:30:00 +01:00
this.walkAnimation.setSpeed(1.5F);
2020-12-27 22:28:57 +01:00
boolean flag1 = true;
2018-08-26 04:00:00 +02:00
2023-03-14 17:30:00 +01:00
- if ((float) this.invulnerableTime > 10.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) {
+ if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) { // CraftBukkit - restore use of maxNoDamageTicks
2021-06-11 07:00:00 +02:00
if (f <= this.lastHurt) {
2018-08-26 04:00:00 +02:00
return false;
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
- this.actuallyHurt(damagesource, f - this.lastHurt);
2024-03-20 10:31:48 +01:00
+ // CraftBukkit start
2024-06-22 10:46:41 +02:00
+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) {
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
2024-06-22 10:46:41 +02:00
+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage(), event)) {
2018-08-26 04:00:00 +02:00
+ return false;
+ }
2021-06-11 07:00:00 +02:00
this.lastHurt = f;
- this.invulnerableTime = 20;
2021-11-21 23:00:00 +01:00
- this.actuallyHurt(damagesource, f);
2021-06-11 07:00:00 +02:00
+ this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks
2024-02-10 23:58:07 +01:00
+ // this.actuallyHurt(damagesource, f);
2018-08-26 04:00:00 +02:00
+ // 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;
}
2024-06-22 10:46:41 +02:00
@@ -1245,7 +1482,7 @@
2024-04-26 08:03:46 +02:00
this.level().broadcastDamageEvent(this, damagesource);
}
- if (!damagesource.is(DamageTypeTags.NO_IMPACT) && (!flag || f > 0.0F)) {
+ if (!damagesource.is(DamageTypeTags.NO_IMPACT) && !flag) { // CraftBukkit - Prevent marking hurt if the damage is blocked
this.markHurt();
}
2024-06-22 10:46:41 +02:00
@@ -1265,7 +1502,7 @@
2024-06-13 17:05:00 +02:00
d1 = damagesource.getSourcePosition().z() - this.getZ();
2024-01-27 04:53:41 +01:00
}
- this.knockback(0.4000000059604645D, d0, d1);
+ this.knockback(0.4000000059604645D, d0, d1, entity1, entity1 == null ? EntityKnockbackEvent.KnockbackCause.DAMAGE : EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
if (!flag) {
this.indicateDamage(d0, d1);
}
2024-06-22 10:46:41 +02:00
@@ -1284,7 +1521,7 @@
2024-04-26 08:03:46 +02:00
this.playHurtSound(damagesource);
}
- boolean flag2 = !flag || f > 0.0F;
+ boolean flag2 = !flag; // CraftBukkit - Ensure to return false if damage is blocked
if (flag2) {
this.lastDamageSource = damagesource;
2024-06-22 10:46:41 +02:00
@@ -1318,7 +1555,7 @@
2024-01-27 04:53:41 +01:00
}
protected void blockedByShield(EntityLiving entityliving) {
- entityliving.knockback(0.5D, entityliving.getX() - this.getX(), entityliving.getZ() - this.getZ());
+ entityliving.knockback(0.5D, entityliving.getX() - this.getX(), entityliving.getZ() - this.getZ(), null, EntityKnockbackEvent.KnockbackCause.SHIELD_BLOCK); // CraftBukkit
}
private boolean checkTotemDeathProtection(DamageSource damagesource) {
2024-06-22 10:46:41 +02:00
@@ -1329,19 +1566,32 @@
2016-12-10 02:16:14 +01:00
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
+ // CraftBukkit start
2022-10-02 00:07:14 +02:00
+ EnumHand hand = null;
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];
2021-11-21 23:00:00 +01:00
- ItemStack itemstack1 = this.getItemInHand(enumhand);
+ itemstack1 = this.getItemInHand(enumhand);
2016-12-10 02:16:14 +01:00
2021-11-21 23:00:00 +01:00
if (itemstack1.is(Items.TOTEM_OF_UNDYING)) {
2022-10-02 00:07:14 +02:00
+ hand = enumhand; // CraftBukkit
2021-11-21 23:00:00 +01:00
itemstack = itemstack1.copy();
- itemstack1.shrink(1);
2017-05-14 04:00:00 +02:00
+ // 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) {
2022-10-02 00:07:14 +02:00
+ org.bukkit.inventory.EquipmentSlot handSlot = (hand != null) ? org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(hand) : null;
+ EntityResurrectEvent event = new EntityResurrectEvent((LivingEntity) this.getBukkitEntity(), handSlot);
2017-05-14 04:00:00 +02:00
+ event.setCancelled(itemstack == null);
2023-06-07 17:30:00 +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()) {
2021-11-21 23:00:00 +01:00
+ itemstack1.shrink(1);
2018-03-23 09:40:16 +01:00
+ }
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;
2021-11-21 23:00:00 +01:00
entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
2024-06-22 10:46:41 +02:00
@@ -1350,14 +1600,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
2023-06-07 17:30:00 +02:00
this.level().broadcastEntityEvent(this, (byte) 35);
2017-06-23 04:47:29 +02:00
}
- return itemstack != null;
+ return !event.isCancelled();
}
}
2024-06-22 10:46:41 +02:00
@@ -1464,14 +1716,22 @@
2021-11-21 23:00:00 +01:00
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
2021-09-06 10:57:16 +02:00
2023-06-07 17:30:00 +02:00
if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
- this.level().setBlock(blockposition, iblockdata, 3);
2021-09-06 10:57:16 +02:00
- flag = true;
+ // CraftBukkit start - call EntityBlockFormEvent for Wither Rose
2023-06-07 17:30:00 +02:00
+ flag = org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(this.level(), blockposition, iblockdata, 3, this);
2021-09-06 10:57:16 +02:00
+ // CraftBukkit end
}
}
2021-01-29 00:19:39 +01:00
if (!flag) {
2023-06-07 17:30:00 +02:00
EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), 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
2023-06-07 17:30:00 +02:00
this.level().addFreshEntity(entityitem);
2021-01-29 00:19:39 +01:00
}
}
2024-06-22 10:46:41 +02:00
@@ -1482,26 +1742,41 @@
2024-06-13 17:05:00 +02:00
protected void dropAllDeathLoot(WorldServer worldserver, DamageSource damagesource) {
2021-06-11 07:00:00 +02:00
boolean flag = this.lastHurtByPlayerTime > 0;
2019-08-02 11:13:16 +02:00
2021-11-21 23:00:00 +01:00
+ this.dropEquipment(); // CraftBukkit - from below
2024-06-13 17:05:00 +02:00
if (this.shouldDropLoot() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
2021-11-21 23:00:00 +01:00
this.dropFromLootTable(damagesource, flag);
2024-06-13 17:05:00 +02:00
this.dropCustomDeathLoot(worldserver, damagesource, flag);
2019-04-23 04:00:00 +02:00
}
2020-07-22 10:45:52 +02:00
+ // CraftBukkit start - Call death event
2024-05-04 00:16:00 +02:00
+ CraftEventFactory.callEntityDeathEvent(this, damagesource, this.drops);
2020-07-22 10:45:52 +02:00
+ this.drops = new ArrayList<>();
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
- this.dropEquipment();
2024-06-13 17:05:00 +02:00
+ // this.dropEquipment();// CraftBukkit - moved up
this.dropExperience(damagesource.getEntity());
2019-08-02 11:13:16 +02:00
}
2021-11-21 23:00:00 +01:00
protected void dropEquipment() {}
2019-12-10 23:00:00 +01:00
2024-06-13 17:05:00 +02:00
- protected void dropExperience(@Nullable Entity entity) {
+ public int getExpReward(@Nullable Entity entity) { // CraftBukkit
World world = this.level();
if (world instanceof WorldServer worldserver) {
if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
- EntityExperienceOrb.award(worldserver, this.position(), this.getExperienceReward(worldserver, entity));
+ return this.getExperienceReward(worldserver, entity); // CraftBukkit
}
2024-01-27 04:53:41 +01:00
}
2024-06-13 17:05:00 +02:00
+ return 0; // CraftBukkit
2019-12-10 23:00:00 +01:00
+ }
2021-06-11 07:00:00 +02:00
+
2024-06-13 17:05:00 +02:00
+ protected void dropExperience(@Nullable Entity entity) {
2019-12-10 23:00:00 +01:00
+ // CraftBukkit start - Update getExpReward() above if the removed if() changes!
2024-06-13 17:05:00 +02:00
+ if (!(this instanceof net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon)) { // CraftBukkit - SPIGOT-2420: Special case ender dragon will drop the xp over time
2023-06-07 17:30:00 +02:00
+ EntityExperienceOrb.award((WorldServer) this.level(), this.position(), this.expToDrop);
2019-12-10 23:00:00 +01:00
+ this.expToDrop = 0;
2024-01-27 04:53:41 +01:00
+ }
2019-12-10 23:00:00 +01:00
+ // CraftBukkit end
}
2024-06-13 17:05:00 +02:00
protected void dropCustomDeathLoot(WorldServer worldserver, DamageSource damagesource, boolean flag) {}
2024-06-22 10:46:41 +02:00
@@ -1540,9 +1815,14 @@
2024-01-27 04:53:41 +01:00
}
public void knockback(double d0, double d1, double d2) {
+ // CraftBukkit start - EntityKnockbackEvent
+ knockback(d0, d1, d2, null, EntityKnockbackEvent.KnockbackCause.UNKNOWN);
+ }
+
+ public void knockback(double d0, double d1, double d2, Entity attacker, EntityKnockbackEvent.KnockbackCause cause) {
d0 *= 1.0D - this.getAttributeValue(GenericAttributes.KNOCKBACK_RESISTANCE);
- if (d0 > 0.0D) {
- this.hasImpulse = true;
+ if (true || d0 > 0.0D) { // CraftBukkit - Call event even when force is 0
+ //this.hasImpulse = true; // CraftBukkit - Move down
2024-06-13 17:05:00 +02:00
Vec3D vec3d;
2024-06-22 10:46:41 +02:00
@@ -1552,7 +1832,14 @@
2024-06-13 17:05:00 +02:00
2024-01-27 04:53:41 +01:00
Vec3D vec3d1 = (new Vec3D(d1, 0.0D, d2)).normalize().scale(d0);
- this.setDeltaMovement(vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
+ EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, cause, d0, vec3d1, vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
+ if (event.isCancelled()) {
+ return;
+ }
+
+ this.hasImpulse = true;
+ this.setDeltaMovement(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ());
+ // CraftBukkit end
}
}
2024-06-22 10:46:41 +02:00
@@ -1613,6 +1900,28 @@
2022-09-11 14:24:15 +02:00
return itemstack.getEatingSound();
}
+ // CraftBukkit start - Add delegate methods
+ public SoundEffect getHurtSound0(DamageSource damagesource) {
+ return getHurtSound(damagesource);
+ }
+
+ public SoundEffect getDeathSound0() {
+ return getDeathSound();
+ }
+
+ public SoundEffect getFallDamageSound0(int fallHeight) {
+ return getFallDamageSound(fallHeight);
+ }
+
+ public SoundEffect getDrinkingSound0(ItemStack itemstack) {
+ return getDrinkingSound(itemstack);
+ }
+
+ public SoundEffect getEatingSound0(ItemStack itemstack) {
+ return getEatingSound(itemstack);
+ }
+ // CraftBukkit end
+
2023-06-07 17:30:00 +02:00
public Optional<BlockPosition> getLastClimbablePos() {
return this.lastClimbablePos;
}
2024-06-22 10:46:41 +02:00
@@ -1666,9 +1975,14 @@
2021-11-21 23:00:00 +01:00
int i = this.calculateFallDamage(f, f1);
2014-11-25 22:32:16 +01:00
if (i > 0) {
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ if (!this.hurt(damagesource, (float) i)) {
2019-12-10 23:00:00 +01:00
+ return true;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.playSound(this.getFallDamageSound(i), 1.0F, 1.0F);
this.playBlockFallSound();
- this.hurt(damagesource, (float) i);
2021-06-11 07:00:00 +02:00
+ // this.damageEntity(damagesource, (float) i); // CraftBukkit - moved up
2019-12-10 23:00:00 +01:00
return true;
} else {
return flag;
2024-06-22 10:46:41 +02:00
@@ -1738,7 +2052,7 @@
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
2023-03-14 17:30:00 +01:00
if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
2021-11-21 23:00:00 +01:00
- this.hurtArmor(damagesource, f);
2024-06-23 19:32:25 +02:00
+ // this.hurtArmor(damagesource, f); // CraftBukkit - actuallyHurt(DamageSource, float, EntityDamageEvent) for handle damage
2024-06-13 17:05:00 +02:00
f = CombatMath.getDamageAfterAbsorb(this, f, damagesource, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
2014-11-25 22:32:16 +01:00
}
2024-06-22 10:46:41 +02:00
@@ -1749,7 +2063,8 @@
2024-06-13 17:05:00 +02:00
if (damagesource.is(DamageTypeTags.BYPASSES_EFFECTS)) {
return f;
2016-02-29 22:32:46 +01:00
} else {
2023-03-14 17:30:00 +01:00
- if (this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
2024-06-22 10:46:41 +02:00
+ // CraftBukkit - Moved to handleEntityDamage(DamageSource, float)
2023-03-14 17:30:00 +01:00
+ if (false && this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
2024-06-13 17:05:00 +02:00
int 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;
2024-06-23 19:32:25 +02:00
@@ -1792,15 +2107,140 @@
2014-11-25 22:32:16 +01:00
}
}
2021-11-21 23:00:00 +01:00
- protected void actuallyHurt(DamageSource damagesource, float f) {
2024-03-20 10:31:48 +01:00
+ // CraftBukkit start
2024-06-22 10:46:41 +02:00
+ private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f) {
+ float originalDamage = f;
2014-11-25 22:32:16 +01:00
+
2024-06-22 10:46:41 +02:00
+ Function<Double, Double> freezing = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.IS_FREEZING) && EntityLiving.this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
+ return -(f - (f * 5.0F));
2014-11-25 22:32:16 +01:00
+ }
2024-06-22 10:46:41 +02:00
+ return -0.0;
+ }
+ };
+ float freezingModifier = freezing.apply((double) f).floatValue();
+ f += freezingModifier;
2024-01-27 04:53:41 +01:00
+
2024-06-22 10:46:41 +02:00
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ return -(f - (f * 0.75F));
2014-11-25 22:32:16 +01:00
+ }
2024-06-22 10:46:41 +02:00
+ return -0.0;
+ }
+ };
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
2014-11-25 22:32:16 +01:00
+
2024-06-22 10:46:41 +02:00
+ Function<Double, Double> blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -((EntityLiving.this.isDamageSourceBlocked(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.getDamageAfterArmorAbsorb(damagesource, f.floatValue()));
+ }
+ };
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
2014-11-25 22:32:16 +01:00
+
2024-06-22 10:46:41 +02:00
+ Function<Double, Double> resistance = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (!damagesource.is(DamageTypeTags.BYPASSES_EFFECTS) && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
+ int i = (EntityLiving.this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
+ int j = 25 - i;
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
2014-11-25 22:32:16 +01:00
+ }
2024-06-22 10:46:41 +02:00
+ return -0.0;
+ }
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
2019-12-10 23:00:00 +01:00
+
2024-06-22 10:46:41 +02:00
+ Function<Double, Double> magic = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue()));
2020-04-23 03:13:40 +02:00
+ }
2024-06-22 10:46:41 +02:00
+ };
+ 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.getAbsorptionAmount(), 0.0F), 0.0F));
2014-11-25 22:32:16 +01:00
+ }
2024-06-22 10:46:41 +02:00
+ };
+ float absorptionModifier = absorption.apply((double) f).floatValue();
+
2024-06-23 19:32:25 +02:00
+ return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption);
2024-06-22 10:46:41 +02:00
+ }
2023-06-07 17:30:00 +02:00
+
2024-06-22 10:46:41 +02:00
+ protected boolean actuallyHurt(final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final
if (!this.isInvulnerableTo(damagesource)) {
- f = this.getDamageAfterArmorAbsorb(damagesource, f);
- f = this.getDamageAfterMagicAbsorb(damagesource, f);
- float f1 = f;
+ if (event.isCancelled()) {
+ return false;
+ }
- f = Math.max(f - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - f));
- float f2 = f1 - f;
2024-06-23 19:32:25 +02:00
+ if (damagesource.getEntity() instanceof EntityHuman) {
+ ((EntityHuman) damagesource.getEntity()).resetAttackStrengthTicker(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
+ }
+
+ // 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).awardStat(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
+ } else if (damagesource.getEntity() instanceof EntityPlayer) {
+ ((EntityPlayer) damagesource.getEntity()).awardStat(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
+ }
+ }
+ }
+
+ // Apply damage to helmet
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ this.hurtHelmet(damagesource, f);
+ }
+
+ // Apply damage to armor
+ if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ this.hurtArmor(damagesource, armorDamage);
+ }
+
+ // Apply blocking code // PAIL: steal from above
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
+ Entity entity = damagesource.getDirectEntity();
+
+ if (entity instanceof EntityLiving) {
+ this.blockUsingShield((EntityLiving) entity);
+ }
+ }
+
2024-06-22 10:46:41 +02:00
+ boolean human = this instanceof EntityHuman;
+ float originalDamage = (float) event.getDamage();
+ float absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
2021-11-21 23:00:00 +01:00
+ this.setAbsorptionAmount(Math.max(this.getAbsorptionAmount() - absorptionModifier, 0.0F));
2018-08-26 04:00:00 +02:00
+ float f2 = absorptionModifier;
2024-05-14 13:32:40 +02:00
+
2018-09-17 08:40:35 +02:00
+ if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof EntityHuman) {
2021-11-21 23:00:00 +01:00
+ ((EntityHuman) this).awardStat(StatisticList.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
2018-09-17 08:40:35 +02:00
+ }
2024-06-22 10:46:41 +02:00
+ // CraftBukkit end
2023-03-14 17:30:00 +01:00
if (f2 > 0.0F && f2 < 3.4028235E37F) {
Entity entity = damagesource.getEntity();
2024-06-23 19:32:25 +02:00
@@ -1812,13 +2252,48 @@
2023-03-14 17:30:00 +01:00
}
2018-08-26 04:00:00 +02:00
}
- if (f != 0.0F) {
2024-06-22 10:46:41 +02:00
+ // CraftBukkit start
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-11-21 23:00:00 +01:00
+ ((EntityHuman) this).causeFoodExhaustion(damagesource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
2015-04-09 02:18:21 +02:00
+ if (f < 3.4028235E37F) {
2021-11-21 23:00:00 +01:00
+ ((EntityHuman) this).awardStat(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
2023-06-07 17:30:00 +02:00
this.getCombatTracker().recordDamage(damagesource, f);
this.setHealth(this.getHealth() - f);
2021-11-21 23:00:00 +01:00
- this.setAbsorptionAmount(this.getAbsorptionAmount() - f);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2016-03-20 03:40:12 +01:00
+ if (!human) {
2021-11-21 23:00:00 +01:00
+ this.setAbsorptionAmount(this.getAbsorptionAmount() - f);
2014-11-25 22:32:16 +01:00
+ }
2022-06-07 18:00:00 +02:00
this.gameEvent(GameEvent.ENTITY_DAMAGE);
2016-11-17 02:41:03 +01:00
+
2024-03-20 10:31:48 +01:00
+ return true;
2016-11-17 02:41:03 +01:00
+ } else {
2017-05-14 04:00:00 +02:00
+ // Duplicate triggers if blocking
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ if (this instanceof EntityPlayer) {
2021-11-21 23:00:00 +01:00
+ CriterionTriggers.ENTITY_HURT_PLAYER.trigger((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) {
2021-11-21 23:00:00 +01:00
+ ((EntityPlayer) this).awardStat(StatisticList.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
2018-08-26 04:00:00 +02:00
+ }
2017-05-14 04:00:00 +02:00
+ }
+
+ if (damagesource.getEntity() instanceof EntityPlayer) {
2021-11-21 23:00:00 +01:00
+ CriterionTriggers.PLAYER_HURT_ENTITY.trigger((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
2017-05-14 04:00:00 +02:00
+ }
+
2024-04-26 08:03:46 +02:00
+ return true;
2017-05-14 04:00:00 +02:00
+ } else {
2024-05-14 13:32:40 +02:00
+ return originalDamage > 0;
2017-05-14 04:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
}
2024-03-20 10:31:48 +01:00
+ return false; // CraftBukkit
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
public CombatTracker getCombatTracker() {
2024-06-23 19:32:25 +02:00
@@ -1843,9 +2318,19 @@
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);
2024-06-22 10:46:41 +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());
2024-06-22 10:46:41 +02:00
+ }
2021-06-11 07:00:00 +02:00
+ // CraftBukkit end
2024-06-22 10:46:41 +02:00
+
2021-11-21 23:00:00 +01:00
public final int getStingerCount() {
2021-06-11 07:00:00 +02:00
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
2024-06-22 10:46:41 +02:00
}
2024-06-23 19:32:25 +02:00
@@ -2086,6 +2571,12 @@
2020-12-22 21:53:45 +01:00
2021-11-21 23:00:00 +01:00
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
2020-12-22 21:53:45 +01:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack, boolean silent) {
+ this.setItemSlot(enumitemslot, itemstack);
2020-12-22 21:53:45 +01:00
+ }
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
2020-12-22 21:53:45 +01:00
2024-04-23 17:15:00 +02:00
public Iterable<ItemStack> getHandSlots() {
2024-06-23 19:32:25 +02:00
@@ -2336,6 +2827,7 @@
2016-03-12 10:57:32 +01:00
}
2023-06-07 17:30:00 +02:00
if (this.onGround() && !this.level().isClientSide) {
2021-11-21 23:00:00 +01:00
+ if (getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setSharedFlag(7, false);
2016-03-12 10:57:32 +01:00
}
} else {
2024-06-23 19:32:25 +02:00
@@ -2506,7 +2998,7 @@
2023-09-24 23:47:22 +02:00
}
}
- this.detectEquipmentUpdates();
+ this.detectEquipmentUpdatesPublic(); // CraftBukkit
if (this.tickCount % 20 == 0) {
this.getCombatTracker().recheckStatus();
}
2024-06-23 19:32:25 +02:00
@@ -2610,7 +3102,7 @@
2024-04-23 17:15:00 +02:00
2023-09-24 23:47:22 +02:00
}
- public void detectEquipmentUpdates() {
+ public void detectEquipmentUpdatesPublic() { // CraftBukkit
Map<EnumItemSlot, ItemStack> map = this.collectEquipmentChanges();
if (map != null) {
2024-06-23 19:32:25 +02:00
@@ -2949,6 +3441,7 @@
2016-03-12 10:57:32 +01:00
}
2023-06-07 17:30:00 +02:00
if (!this.level().isClientSide) {
2021-11-21 23:00:00 +01:00
+ if (flag != this.getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit
this.setSharedFlag(7, flag);
2016-03-12 10:57:32 +01:00
}
2024-09-07 10:08:13 +02:00
@@ -3141,13 +3634,20 @@
2016-03-27 11:58:45 +02:00
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public boolean isPickable() {
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
2021-11-21 23:00:00 +01:00
public boolean isPushable() {
- return this.isAlive() && !this.isSpectator() && !this.onClimbable();
+ return this.isAlive() && !this.isSpectator() && !this.onClimbable() && this.collides; // CraftBukkit
2024-09-07 10:08:13 +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) {
2021-11-21 23:00:00 +01:00
+ return isPushable() && this.collides != this.collidableExemptions.contains(entity.getUUID());
2024-09-07 10:08:13 +02:00
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2024-09-07 10:08:13 +02:00
2019-04-23 04:00:00 +02:00
@Override
2022-02-28 16:00:00 +01:00
public float getYHeadRot() {
2024-09-07 10:08:13 +02:00
@@ -3245,7 +3745,7 @@
}
- protected void setLivingEntityFlag(int i, boolean flag) {
+ public void setLivingEntityFlag(int i, boolean flag) {
int j = (Byte) this.entityData.get(EntityLiving.DATA_LIVING_ENTITY_FLAGS);
if (flag) {
2024-09-07 11:35:16 +02:00
@@ -3346,7 +3846,29 @@
2021-11-24 22:00:00 +01:00
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
this.triggerItemUseEffects(this.useItem, 16);
2023-06-07 17:30:00 +02:00
- ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this);
2021-11-24 22:00:00 +01:00
+ // CraftBukkit start - fire PlayerItemConsumeEvent
+ ItemStack itemstack;
2024-09-07 11:35:16 +02:00
+ if (this instanceof EntityPlayer entityPlayer) {
2021-11-24 22:00:00 +01:00
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.useItem);
2022-10-02 00:07:14 +02:00
+ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(enumhand);
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem, hand);
2023-06-07 17:30:00 +02:00
+ this.level().getCraftServer().getPluginManager().callEvent(event);
2019-12-10 23:00:00 +01:00
+
2021-11-24 22:00:00 +01:00
+ if (event.isCancelled()) {
+ // Update client
2024-09-07 11:35:16 +02:00
+ if (this.useItem.getItem() instanceof net.minecraft.world.item.ItemSuspiciousStew itemSuspiciousStew) {
+ itemSuspiciousStew.cancelUsingItem(entityPlayer, this.useItem);
+ }
+ entityPlayer.getBukkitEntity().updateInventory();
+ entityPlayer.getBukkitEntity().updateScaledHealth();
2021-11-24 22:00:00 +01:00
+ return;
+ }
2015-01-16 04:48:42 +01:00
+
2023-06-07 17:30:00 +02:00
+ itemstack = (craftItem.equals(event.getItem())) ? this.useItem.finishUsingItem(this.level(), this) : CraftItemStack.asNMSCopy(event.getItem()).finishUsingItem(this.level(), this);
2021-11-24 22:00:00 +01:00
+ } else {
2023-06-07 17:30:00 +02:00
+ itemstack = this.useItem.finishUsingItem(this.level(), this);
2021-11-24 22:00:00 +01:00
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
2021-11-24 22:00:00 +01:00
if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack);
2024-09-07 11:35:16 +02:00
@@ -3424,6 +3946,12 @@
2021-05-25 00:24:08 +02:00
}
2021-11-21 23:00:00 +01:00
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
2021-05-25 00:24:08 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ return randomTeleport(d0, d1, d2, flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN).orElse(false);
2021-05-25 00:24:08 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public Optional<Boolean> randomTeleport(double d0, double d1, double d2, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
2021-05-25 00:24:08 +02:00
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
double d3 = this.getX();
double d4 = this.getY();
double d5 = this.getZ();
2024-09-07 11:35:16 +02:00
@@ -3448,16 +3976,41 @@
2016-04-08 11:06:31 +02:00
}
2019-04-23 04:00:00 +02:00
if (flag2) {
2021-11-21 23:00:00 +01:00
- this.teleportTo(d0, d6, d2);
2016-04-08 11:06:31 +02:00
+ // CraftBukkit start - Teleport event
2021-11-21 23:00:00 +01:00
+ // this.teleportTo(d0, d6, d2);
2021-05-25 00:24:08 +02:00
+
+ // first set position, to check if the place to teleport is valid
2021-11-21 23:00:00 +01:00
+ this.setPos(d0, d6, d2);
if (world.noCollision((Entity) this) && !world.containsAnyLiquid(this.getBoundingBox())) {
2021-05-25 00:24:08 +02:00
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
2021-11-21 23:00:00 +01:00
+ this.setPos(d3, d4, d5);
2021-05-25 00:24:08 +02:00
+
+ if (flag1) {
+ if (!(this instanceof EntityPlayer)) {
2023-06-07 17:30: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));
+ this.level().getCraftServer().getPluginManager().callEvent(teleport);
2021-05-25 00:24:08 +02:00
+ if (!teleport.isCancelled()) {
+ Location to = teleport.getTo();
2021-11-21 23:00:00 +01:00
+ this.teleportTo(to.getX(), to.getY(), to.getZ());
2021-05-25 00:24:08 +02:00
+ } else {
+ return Optional.empty();
+ }
+ } else {
+ // player teleport event is called in the underlining code
2024-06-15 10:47:12 +02:00
+ if (!((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), java.util.Collections.emptySet(), 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) {
2021-11-21 23:00:00 +01:00
- this.teleportTo(d3, d4, d5);
2021-05-25 00:24:08 +02:00
- return false;
+ // this.enderTeleportTo(d3, d4, d5); // CraftBukkit - already set the location back
+ return Optional.of(false); // CraftBukkit
} else {
if (flag) {
2021-11-21 23:00:00 +01:00
world.broadcastEntityEvent(this, (byte) 46);
2024-09-07 11:35:16 +02:00
@@ -3469,7 +4022,7 @@
2023-12-05 17:40:00 +01:00
entitycreature.getNavigation().stop();
2021-05-25 00:24:08 +02:00
}
- return true;
+ return Optional.of(true); // CraftBukkit
}
}
2024-09-07 11:35:16 +02:00
@@ -3562,7 +4115,7 @@
2019-04-23 04:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
public void stopSleeping() {
- Optional optional = this.getSleepingPos();
+ Optional<BlockPosition> optional = this.getSleepingPos(); // CraftBukkit - decompile error
2023-06-07 17:30:00 +02:00
World world = this.level();
2021-06-11 07:00:00 +02:00
2023-06-07 17:30:00 +02:00
java.util.Objects.requireNonNull(world);
2024-09-07 11:35:16 +02:00
@@ -3596,7 +4149,7 @@
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
@Nullable
2021-11-21 23:00:00 +01:00
public EnumDirection getBedOrientation() {
- BlockPosition blockposition = (BlockPosition) this.getSleepingPos().orElse((Object) null);
+ BlockPosition blockposition = (BlockPosition) this.getSleepingPos().orElse(null); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
2023-06-07 17:30:00 +02:00
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
2021-06-11 07:00:00 +02:00
}
2024-09-07 11:35:16 +02:00
@@ -3633,7 +4186,7 @@
2024-04-23 17:15:00 +02:00
FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next();
2019-04-23 04:00:00 +02:00
2024-04-23 17:15:00 +02:00
if (this.random.nextFloat() < foodinfo_b.probability()) {
- this.addEffect(foodinfo_b.effect());
+ this.addEffect(foodinfo_b.effect(), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
2024-04-23 17:15:00 +02:00