Drop chunk status transition patch from paper_chunk_patches
Research by ishland suggests that vanilla already does this, at least since 1.18
This commit is contained in:
parent
8067cb6e65
commit
aff4e0c2d0
|
|
@ -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<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getFutureIfPresentUnchecked(ChunkStatus arg);
|
|
||||||
|
|
||||||
@Shadow @Final private static List<ChunkStatus> CHUNK_STATUSES;
|
|
||||||
|
|
||||||
public ChunkStatus mfix$getChunkHolderStatus() {
|
|
||||||
for (ChunkStatus curr = ChunkStatus.FULL, next = curr.getParent(); curr != next; curr = next, next = next.getParent()) {
|
|
||||||
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.getFutureIfPresentUnchecked(curr);
|
|
||||||
Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> 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<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.getFutureIfPresentUnchecked(curr);
|
|
||||||
Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> 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)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches;
|
package org.embeddedt.modernfix.common.mixin.bugfix.paper_chunk_patches;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.*;
|
import net.minecraft.server.level.*;
|
||||||
import net.minecraft.server.level.progress.ChunkProgressListener;
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
import net.minecraft.util.thread.BlockableEventLoop;
|
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.ChunkAccess;
|
||||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
|
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.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
|
|
||||||
@Mixin(ChunkMap.class)
|
@Mixin(ChunkMap.class)
|
||||||
|
|
@ -41,19 +36,6 @@ public abstract class ChunkMapMixin {
|
||||||
|
|
||||||
@Shadow protected abstract CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> scheduleChunkGeneration(ChunkHolder chunkHolder, ChunkStatus chunkStatus);
|
@Shadow protected abstract CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> scheduleChunkGeneration(ChunkHolder chunkHolder, ChunkStatus chunkStatus);
|
||||||
|
|
||||||
private Executor mainInvokingExecutor;
|
|
||||||
|
|
||||||
@Inject(method = "<init>", 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 */
|
/* 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)
|
@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;
|
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
|
* @author embeddedt
|
||||||
* @reason revert 1.17 chunk system changes, significantly reduces time and RAM needed to load chunks
|
* @reason revert 1.17 chunk system changes, significantly reduces time and RAM needed to load chunks
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package org.embeddedt.modernfix.duck;
|
|
||||||
|
|
||||||
public interface IPaperChunkHolder {
|
|
||||||
boolean mfix$canAdvanceStatus();
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user