Skip to content

Commit

Permalink
Fix the compatibility of archers mod
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5 committed Jan 31, 2024
1 parent de329c1 commit fb311d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ default <T extends ParticleOptions> int sendParticles(ServerPlayer sender, T t0
default PrimaryLevelData bridge$serverLevelDataCB() {
return null;
}

default boolean canAddFreshEntity() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -382,6 +383,24 @@ public <T extends ParticleOptions> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fb311d3

Please sign in to comment.