Skip to content

Commit

Permalink
Fixing the processUnloads() crash (pt 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Dec 18, 2023
1 parent 88d5832 commit 3cd4605
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -70,6 +66,6 @@ private boolean replaceProcessUnloads(final LongSet instance, final LongPredicat
}
}
chunksToUnload.removeAll(toRemove);
return !toRemove.isEmpty();
ci.cancel();
}
}

0 comments on commit 3cd4605

Please sign in to comment.