From 3cd460526546d1ae07533b3ad0ff3b2407c82214 Mon Sep 17 00:00:00 2001 From: StewStrong Date: Sun, 17 Dec 2023 23:41:23 -0700 Subject: [PATCH] Fixing the processUnloads() crash (pt 2) --- .../MixinPersistentEntitySectionManager.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/shipyard_entities/MixinPersistentEntitySectionManager.java b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/shipyard_entities/MixinPersistentEntitySectionManager.java index e330afdf9..4d6aa8996 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/shipyard_entities/MixinPersistentEntitySectionManager.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/shipyard_entities/MixinPersistentEntitySectionManager.java @@ -3,7 +3,6 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; -import java.util.function.LongPredicate; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.entity.EntitySectionStorage; @@ -14,7 +13,8 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.valkyrienskies.mod.mixinducks.world.OfLevel; @Mixin(PersistentEntitySectionManager.class) @@ -53,14 +53,10 @@ private boolean processChunkUnload(final long l) { /** * This fixes this function randomly crashing. I'm not sure why but the removeIf() function is buggy */ - @Redirect( - method = "processUnloads", - at = @At( - value = "INVOKE", - target = "Lit/unimi/dsi/fastutil/longs/LongSet;removeIf(Ljava/util/function/LongPredicate;)Z" - ) + @Inject( + method = "processUnloads", at = @At(value = "HEAD"), cancellable = true ) - private boolean replaceProcessUnloads(final LongSet instance, final LongPredicate longPredicate) { + private void replaceProcessUnloads(final CallbackInfo ci) { final LongSet toRemove = new LongOpenHashSet(); for (final long key : this.chunksToUnload) { if (this.chunkVisibility.get(key) != Visibility.HIDDEN) { @@ -70,6 +66,6 @@ private boolean replaceProcessUnloads(final LongSet instance, final LongPredicat } } chunksToUnload.removeAll(toRemove); - return !toRemove.isEmpty(); + ci.cancel(); } }