Fix patches being nonfunctional

This commit is contained in:
embeddedt 2023-04-27 21:36:32 -04:00
parent da6e9dc075
commit a0ceaa4dac
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 14 additions and 6 deletions

View File

@ -70,7 +70,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.dynamic_structure_manager", true);
this.addMixinRule("bugfix.mc218112", true);
this.addMixinRule("bugfix.chunk_deadlock", true);
this.addMixinRule("bugfix.chunk_not_unloading", true);
this.addMixinRule("bugfix.paper_chunk_patches", true);
this.addMixinRule("bugfix.chunk_deadlock.valhesia", modPresent("valhelsia_structures"));
this.addMixinRule("bugfix.tf_cme_on_load", modPresent("twilightforest"));
this.addMixinRule("bugfix.refinedstorage", modPresent("refinedstorage"));

View File

@ -45,7 +45,7 @@ public abstract class ChunkHolderMixin implements IPaperChunkHolder {
return null;
}
public static ChunkStatus mfix$getNextStatus(ChunkStatus status) {
private static ChunkStatus mfix$getNextStatus(ChunkStatus status) {
if (status == ChunkStatus.FULL) {
return status;
}

View File

@ -1,9 +1,11 @@
package org.embeddedt.modernfix.mixin.bugfix.paper_chunk_patches;
import com.mojang.datafixers.util.Either;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import org.embeddedt.modernfix.duck.IPaperChunkHolder;
import org.spongepowered.asm.mixin.Final;
@ -12,9 +14,13 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Function;
@Mixin(ChunkMap.class)
@ -46,14 +52,16 @@ public class ChunkMapMixin {
return this.mainInvokingExecutor;
}
@ModifyArg(method = "scheduleChunkGeneration", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenComposeAsync(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"), index = 1)
private Executor skipWorkerIfPossible(Executor executor, ChunkHolder chunkHolder) {
return (runnable) -> {
if(((IPaperChunkHolder)chunkHolder).mfix$canAdvanceStatus()) {
@SuppressWarnings({"rawtypes", "unchecked"})
@Redirect(method = "scheduleChunkGeneration", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;thenComposeAsync(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private CompletableFuture skipWorkerIfPossible(CompletableFuture inputFuture, Function function, Executor executor, ChunkHolder holder) {
Executor targetExecutor = (runnable) -> {
if(((IPaperChunkHolder)holder).mfix$canAdvanceStatus()) {
this.mainInvokingExecutor.execute(runnable);
return;
}
executor.execute(runnable);
};
return inputFuture.thenComposeAsync(function, targetExecutor);
}
}