From fb311d3764d258c3a45318dcce972223359251f6 Mon Sep 17 00:00:00 2001 From: 1798643961 <1798643961@qq.com> Date: Wed, 31 Jan 2024 23:13:16 +0800 Subject: [PATCH] Fix the compatibility of archers mod --- .../server/level/InjectionServerLevel.java | 4 ++++ .../mixin/server/level/MixinServerLevel.java | 19 +++++++++++++++++++ .../banner/mixin/world/item/MixinBowItem.java | 15 +++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mohistmc/banner/injection/server/level/InjectionServerLevel.java b/src/main/java/com/mohistmc/banner/injection/server/level/InjectionServerLevel.java index c55021ae1..d8e0dcee5 100644 --- a/src/main/java/com/mohistmc/banner/injection/server/level/InjectionServerLevel.java +++ b/src/main/java/com/mohistmc/banner/injection/server/level/InjectionServerLevel.java @@ -59,4 +59,8 @@ default int sendParticles(ServerPlayer sender, T t0 default PrimaryLevelData bridge$serverLevelDataCB() { return null; } + + default boolean canAddFreshEntity() { + return false; + } } diff --git a/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java b/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java index fd44ec3a5..c353e3dcb 100644 --- a/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java +++ b/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import net.minecraft.core.BlockPos; @@ -382,6 +383,24 @@ public int sendParticles(T type, double posX, double } } + // Banner start + public AtomicBoolean canaddFreshEntity = new AtomicBoolean(false); + + @Override + public boolean canAddFreshEntity() { + return canaddFreshEntity.getAndSet(false); + } + // Banner end + + // Banner - fix mixin + @Redirect(method = "addFreshEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean banner$fixAddFreshEntity(ServerLevel instance, Entity entity) { + boolean add = addFreshEntity(entity); + canaddFreshEntity.set(add); + return add; + } + + @Override public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { pushAddEntityReason(reason); diff --git a/src/main/java/com/mohistmc/banner/mixin/world/item/MixinBowItem.java b/src/main/java/com/mohistmc/banner/mixin/world/item/MixinBowItem.java index 9add1c5c1..4d3da3cc8 100644 --- a/src/main/java/com/mohistmc/banner/mixin/world/item/MixinBowItem.java +++ b/src/main/java/com/mohistmc/banner/mixin/world/item/MixinBowItem.java @@ -1,5 +1,7 @@ package com.mohistmc.banner.mixin.world.item; +import com.mohistmc.banner.bukkit.DistValidate; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -95,12 +97,17 @@ public void releaseUsing(ItemStack stack, Level level, LivingEntity livingEntity // CraftBukkit start if (event.getProjectile() == abstractArrow.getBukkitEntity()) { - if (!level.addFreshEntity(abstractArrow)) { - if (player instanceof ServerPlayer) { - ((ServerPlayer) player).getBukkitEntity().updateInventory(); + // Baner start - fix mixin + level.addFreshEntity(abstractArrow); + if (DistValidate.isValid(level)) { + if (!((ServerLevel)level).canAddFreshEntity()) { + if (player instanceof ServerPlayer) { + ((ServerPlayer) player).getBukkitEntity().updateInventory(); + } + return; } - return; } + // Banner end } // CraftBukkit end }