Skip to content

Commit c1a58a9

Browse files
committed
Short circuit remove() when invoked during remove() (see iron spellbooks); for #1705
1 parent 5c69d66 commit c1a58a9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.izzel.arclight.common.bridge.core.entity.LivingEntityBridge;
88
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
99
import io.izzel.arclight.common.bridge.core.network.play.ServerPlayNetHandlerBridge;
10+
import io.izzel.arclight.common.mod.server.ArclightServer;
1011
import io.izzel.arclight.common.mod.util.EntityDamageResult;
1112
import io.izzel.arclight.common.util.IteratorUtil;
1213
import io.izzel.arclight.i18n.ArclightConfig;
@@ -391,6 +392,24 @@ public MobEffectInstance removeEffectNoUpdate(@Nullable Holder<MobEffect> holder
391392
}
392393
}
393394

395+
// Fix entity removing itself when effect is removed causes looping remove
396+
@Unique private boolean removing = false;
397+
398+
@Inject(method = "remove", cancellable = true, at = @At("HEAD"))
399+
private void arclight$beginOnDeathMobEffects(Entity.RemovalReason removalReason, CallbackInfo ci) {
400+
if (removing) {
401+
ci.cancel();
402+
ArclightServer.LOGGER.warn("remove() is called recursively, skipping");
403+
return;
404+
}
405+
removing = true;
406+
}
407+
408+
@Inject(method = "remove", at = @At("TAIL"))
409+
private void arclight$endOnDeathMobEffects(CallbackInfo ci) {
410+
removing = false;
411+
}
412+
394413
@Inject(method = "triggerOnDeathMobEffects", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;clear()V"))
395414
private void arclight$fireRemoveEvents(Entity.RemovalReason removalReason, CallbackInfo ci) {
396415
this.removeAllEffects(EntityPotionEffectEvent.Cause.DEATH);

0 commit comments

Comments
 (0)