From 635d3870ee97aa2c3506d2a791e884362a0d9600 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 25 Nov 2023 14:18:37 -0800 Subject: [PATCH] Don't fire EntityPotionEffectEvent during worldgen (#9965) --- ...ityPotionEffectEvent-during-worldgen.patch | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 patches/server/Don-t-fire-EntityPotionEffectEvent-during-worldgen.patch diff --git a/patches/server/Don-t-fire-EntityPotionEffectEvent-during-worldgen.patch b/patches/server/Don-t-fire-EntityPotionEffectEvent-during-worldgen.patch new file mode 100644 index 0000000000..ac46cf6de3 --- /dev/null +++ b/patches/server/Don-t-fire-EntityPotionEffectEvent-during-worldgen.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 23 Nov 2023 10:33:25 -0800 +Subject: [PATCH] Don't fire EntityPotionEffectEvent during worldgen + +Asynchronous chunk generation provides an opportunity for mobs +being added with generation to have effects added to them. The event +does not support asynchronous firing. + +diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java ++++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable { + } + + public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) { ++ // Paper start - add boolean param to optionally fire the event ++ return this.addEffect(mobeffect, entity, cause, true); ++ } ++ public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause, boolean fireEvent) { ++ // Paper end + // org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot // Paper - move to API + if (this.isTickingEffects) { + this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause)); +@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable { + override = new MobEffectInstance(mobeffect1).update(mobeffect); + } + ++ if (fireEvent) { // Paper + EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, mobeffect1, mobeffect, cause, override); ++ override = event.isOverride(); // Paper + if (event.isCancelled()) { + return false; + } ++ } // Paper + // CraftBukkit end + + if (mobeffect1 == null) { +@@ -0,0 +0,0 @@ public abstract class LivingEntity extends Entity implements Attackable { + this.onEffectAdded(mobeffect, entity); + flag = true; + // CraftBukkit start +- } else if (event.isOverride()) { ++ } else if (override) { // Paper + mobeffect1.update(mobeffect); + this.onEffectUpdated(mobeffect1, true, entity); + // CraftBukkit end +diff --git a/src/main/java/net/minecraft/world/entity/monster/Spider.java b/src/main/java/net/minecraft/world/entity/monster/Spider.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/monster/Spider.java ++++ b/src/main/java/net/minecraft/world/entity/monster/Spider.java +@@ -0,0 +0,0 @@ public class Spider extends Monster { + MobEffect mobeffectlist = entityspider_groupdataspider.effect; + + if (mobeffectlist != null) { +- this.addEffect(new MobEffectInstance(mobeffectlist, -1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN); // CraftBukkit ++ this.addEffect(new MobEffectInstance(mobeffectlist, -1), null, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN, world instanceof net.minecraft.server.level.ServerLevel); // CraftBukkit // Paper - only fire the effect event if this is happening in a ServerLevel + } + } +