11package org .embeddedt .modernfix .common .mixin .bugfix .paper_chunk_patches ;
22
33import com .mojang .datafixers .util .Either ;
4- import net .minecraft .server .MinecraftServer ;
54import net .minecraft .server .level .*;
65import net .minecraft .server .level .progress .ChunkProgressListener ;
76import net .minecraft .util .thread .BlockableEventLoop ;
87import net .minecraft .world .level .ChunkPos ;
98import net .minecraft .world .level .chunk .ChunkAccess ;
109import net .minecraft .world .level .chunk .ChunkStatus ;
1110import net .minecraft .world .level .levelgen .structure .templatesystem .StructureManager ;
12- import org .embeddedt .modernfix .duck .IPaperChunkHolder ;
1311import org .spongepowered .asm .mixin .Final ;
1412import org .spongepowered .asm .mixin .Mixin ;
1513import org .spongepowered .asm .mixin .Shadow ;
1614import org .spongepowered .asm .mixin .injection .At ;
1715import org .spongepowered .asm .mixin .injection .Inject ;
1816import org .spongepowered .asm .mixin .injection .ModifyArg ;
19- import org .spongepowered .asm .mixin .injection .Redirect ;
20- import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2117import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
2218
2319import java .util .Optional ;
2420import java .util .concurrent .CompletableFuture ;
2521import java .util .concurrent .Executor ;
26- import java .util .function .Function ;
2722
2823
2924@ Mixin (ChunkMap .class )
@@ -41,45 +36,13 @@ public abstract class ChunkMapMixin {
4136
4237 @ Shadow protected abstract CompletableFuture <Either <ChunkAccess , ChunkHolder .ChunkLoadingFailure >> scheduleChunkGeneration (ChunkHolder chunkHolder , ChunkStatus chunkStatus );
4338
44- private Executor mainInvokingExecutor ;
45-
46- @ Inject (method = "<init>" , at = @ At ("RETURN" ))
47- private void setup (CallbackInfo ci ) {
48- MinecraftServer server = this .level .getServer ();
49- this .mainInvokingExecutor = (runnable ) -> {
50- if (server .isSameThread ())
51- runnable .run ();
52- else
53- this .mainThreadExecutor .execute (runnable );
54- };
55- }
56-
5739
5840 /* https://github.com/PaperMC/Paper/blob/ver/1.17.1/patches/server/0752-Fix-chunks-refusing-to-unload-at-low-TPS.patch */
5941 @ ModifyArg (method = "prepareAccessibleChunk" , at = @ At (value = "INVOKE" , target = "Ljava/util/concurrent/CompletableFuture;thenApplyAsync(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;" ), index = 1 )
6042 private Executor useMainThreadExecutor (Executor executor ) {
6143 return this .mainThreadExecutor ;
6244 }
6345
64- /* https://github.com/PaperMC/Paper/blob/master/patches/removed/1.19.2-legacy-chunksystem/0482-Improve-Chunk-Status-Transition-Speed.patch */
65- @ ModifyArg (method = "prepareEntityTickingChunk" , at = @ At (value = "INVOKE" , target = "Ljava/util/concurrent/CompletableFuture;thenApplyAsync(Ljava/util/function/Function;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;" ), index = 1 )
66- private Executor useMainInvokingExecutor (Executor executor ) {
67- return this .mainInvokingExecutor ;
68- }
69-
70- @ SuppressWarnings ({"rawtypes" , "unchecked" })
71- @ 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;" ))
72- private CompletableFuture skipWorkerIfPossible (CompletableFuture inputFuture , Function function , Executor executor , ChunkHolder holder ) {
73- Executor targetExecutor = (runnable ) -> {
74- if (((IPaperChunkHolder )holder ).mfix$canAdvanceStatus ()) {
75- this .mainInvokingExecutor .execute (runnable );
76- return ;
77- }
78- executor .execute (runnable );
79- };
80- return inputFuture .thenComposeAsync (function , targetExecutor );
81- }
82-
8346 /**
8447 * @author embeddedt
8548 * @reason revert 1.17 chunk system changes, significantly reduces time and RAM needed to load chunks
0 commit comments