diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkHolderMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkHolderMixin.java deleted file mode 100644 index c255628f..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkHolderMixin.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches; - -import com.mojang.datafixers.util.Either; -import net.minecraft.server.level.ChunkHolder; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.ChunkStatus; -import org.embeddedt.modernfix.duck.IPaperChunkHolder; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -@Mixin(ChunkHolder.class) -public abstract class ChunkHolderMixin implements IPaperChunkHolder { - - @Shadow public abstract CompletableFuture> getFutureIfPresentUnchecked(ChunkStatus arg); - - @Shadow @Final private static List CHUNK_STATUSES; - - public ChunkStatus mfix$getChunkHolderStatus() { - for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) { - CompletableFuture> future = this.getFutureIfPresentUnchecked(curr); - Either either = future.getNow(null); - if (either == null || !either.left().isPresent()) { - continue; - } - return curr; - } - - return null; - } - - public ChunkAccess mfix$getAvailableChunkNow() { - // TODO can we just getStatusFuture(EMPTY)? - for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) { - CompletableFuture> future = this.getFutureIfPresentUnchecked(curr); - Either either = future.getNow(null); - if (either == null || !either.left().isPresent()) { - continue; - } - return either.left().get(); - } - return null; - } - - private static ChunkStatus mfix$getNextStatus(ChunkStatus status) { - if (status == ChunkStatus.FULL) { - return status; - } - return CHUNK_STATUSES.get(status.getIndex() + 1); - } - - @Override - public boolean mfix$canAdvanceStatus() { - ChunkStatus status = mfix$getChunkHolderStatus(); - ChunkAccess chunk = mfix$getAvailableChunkNow(); - return chunk != null && (status == null || chunk.getStatus().isOrAfter(mfix$getNextStatus(status))); - } -} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkMapMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkMapMixin.java index 96c474ff..044ea69b 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkMapMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/paper_chunk_patches/ChunkMapMixin.java @@ -1,7 +1,6 @@ package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches; import com.mojang.datafixers.util.Either; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.*; import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.util.thread.BlockableEventLoop; @@ -9,21 +8,17 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; -import org.embeddedt.modernfix.duck.IPaperChunkHolder; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; 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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import java.util.function.Function; @Mixin(ChunkMap.class) @@ -41,19 +36,6 @@ public abstract class ChunkMapMixin { @Shadow protected abstract CompletableFuture> scheduleChunkGeneration(ChunkHolder chunkHolder, ChunkStatus chunkStatus); - private Executor mainInvokingExecutor; - - @Inject(method = "", at = @At("RETURN")) - private void setup(CallbackInfo ci) { - MinecraftServer server = this.level.getServer(); - this.mainInvokingExecutor = (runnable) -> { - if(server.isSameThread()) - runnable.run(); - else - this.mainThreadExecutor.execute(runnable); - }; - } - /* https://github.com/PaperMC/Paper/blob/ver/1.17.1/patches/server/0752-Fix-chunks-refusing-to-unload-at-low-TPS.patch */ @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) @@ -61,25 +43,6 @@ public abstract class ChunkMapMixin { return this.mainThreadExecutor; } - /* https://github.com/PaperMC/Paper/blob/master/patches/removed/1.19.2-legacy-chunksystem/0482-Improve-Chunk-Status-Transition-Speed.patch */ - @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) - private Executor useMainInvokingExecutor(Executor executor) { - return this.mainInvokingExecutor; - } - - @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); - } - /** * @author embeddedt * @reason revert 1.17 chunk system changes, significantly reduces time and RAM needed to load chunks diff --git a/common/src/main/java/org/embeddedt/modernfix/duck/IPaperChunkHolder.java b/common/src/main/java/org/embeddedt/modernfix/duck/IPaperChunkHolder.java deleted file mode 100644 index 0d83c721..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/duck/IPaperChunkHolder.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.embeddedt.modernfix.duck; - -public interface IPaperChunkHolder { - boolean mfix$canAdvanceStatus(); -}