From 14ceb032182ddfab476c6f2bece7d0aa7d774f90 Mon Sep 17 00:00:00 2001 From: Rothes <449181985@qq.com> Date: Tue, 30 Dec 2025 21:11:28 +0800 Subject: [PATCH] Add config for chunk unload drains per tick --- .../moonrise/fabric/FabricHooks.java | 10 ++++++++++ .../moonrise/neoforge/NeoForgeHooks.java | 10 ++++++++++ .../moonrise/common/PlatformHooks.java | 4 ++++ .../common/config/moonrise/MoonriseConfig.java | 18 +++++++++++++++++- .../scheduling/ChunkHolderManager.java | 5 ++++- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java index 7c81bdf..421f722 100644 --- a/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java +++ b/fabric/src/main/java/ca/spottedleaf/moonrise/fabric/FabricHooks.java @@ -222,6 +222,16 @@ public int configMaxAutoSavePerTick(final ServerLevel world) { return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick; } + @Override + public int configMinUnlockChunksPerTick(final ServerLevel world) { + return ConfigHolder.getConfig().chunkSaving.minUnloadChunksPerTick; + } + + @Override + public double configMaxUnlockChunksPerTickFactor(final ServerLevel world) { + return ConfigHolder.getConfig().chunkSaving.maxUnloadChunksPerTickFactor; + } + @Override public boolean configFixMC159283() { return ConfigHolder.getConfig().bugFixes.fixMC159283; diff --git a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java index 25ba677..c3e9015 100644 --- a/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java +++ b/neoforge/src/main/java/ca/spottedleaf/moonrise/neoforge/NeoForgeHooks.java @@ -235,6 +235,16 @@ public int configMaxAutoSavePerTick(final ServerLevel world) { return ConfigHolder.getConfig().chunkSaving.maxAutoSaveChunksPerTick; } + @Override + public int configMinUnlockChunksPerTick(final ServerLevel world) { + return ConfigHolder.getConfig().chunkSaving.minUnloadChunksPerTick; + } + + @Override + public double configMaxUnlockChunksPerTickFactor(final ServerLevel world) { + return ConfigHolder.getConfig().chunkSaving.maxUnloadChunksPerTickFactor; + } + @Override public boolean configFixMC159283() { return ConfigHolder.getConfig().bugFixes.fixMC159283; diff --git a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java index ea9fbb1..b2b26bc 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java @@ -86,6 +86,10 @@ public void addToGetEntities(final Level world, final EntityT public int configMaxAutoSavePerTick(final ServerLevel world); + public int configMinUnlockChunksPerTick(final ServerLevel world); + + public double configMaxUnlockChunksPerTickFactor(final ServerLevel world); + public boolean configFixMC159283(); // support for CB chunk mustNotSave diff --git a/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java b/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java index 16c64a9..8b87cf3 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/config/moonrise/MoonriseConfig.java @@ -147,12 +147,28 @@ public static final class ChunkSaving { public Duration autoSaveInterval = Duration.parse("5m"); @Serializable( - comment = """ + comment = """ The maximum number of chunks to incrementally autosave each tick. If the value is <= 0, then no chunks will be incrementally saved. """ ) public int maxAutoSaveChunksPerTick = 12; + + @Serializable( + comment = """ + The minimum number of chunks to unload each tick. + See maxUnloadChunksPerTickFactor for more. + """ + ) + public int minUnloadChunksPerTick = 50; + + @Serializable( + comment = """ + The factor to determine maximum unload chunks per tick. The final value is + current pending unload chunks * maxUnloadChunksPerTickFactor . + """ + ) + public double maxUnloadChunksPerTickFactor = 0.05; } @Serializable( diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java index c832dda..3dddc89 100644 --- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java +++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java @@ -1155,7 +1155,10 @@ public void processUnloads() { // We do need to process updates here so that any addTicket that is synchronised before this call does not go missed. this.processTicketUpdates(); - final int toUnloadCount = Math.max(50, (int)(unloadCountTentative * 0.05)); + final int toUnloadCount = Math.max( + PlatformHooks.get().configMinUnlockChunksPerTick(this.world), + (int) (unloadCountTentative * PlatformHooks.get().configMaxUnlockChunksPerTickFactor(this.world)) + ); int processedCount = 0; for (final ChunkUnloadQueue.SectionToUnload sectionRef : unloadSectionsForRegion) {