From 83028e2fd079a2480d80c7196724c6e282a03d88 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 16 Mar 2025 23:12:59 +0300 Subject: [PATCH] some new optimizations to moonrise --- .../features/0001-Rebrand.patch | 21 +- .../0012-Chunk-System-optimization.patch | 328 ++++++++++++++++-- .../features/0013-Optimize-hoppers.patch | 12 +- .../features/0019-Lag-compensation.patch | 8 +- .../0020-MSPT-Tracking-for-each-world.patch | 4 +- .../0030-Verify-Minecraft-EULA-earlier.patch | 6 +- .../0036-Regionized-Chunk-Ticking.patch | 6 +- ...ithium-block_entity_ticking.sleeping.patch | 6 +- 8 files changed, 336 insertions(+), 55 deletions(-) diff --git a/divinemc-server/minecraft-patches/features/0001-Rebrand.patch b/divinemc-server/minecraft-patches/features/0001-Rebrand.patch index e1498e7..ceca597 100644 --- a/divinemc-server/minecraft-patches/features/0001-Rebrand.patch +++ b/divinemc-server/minecraft-patches/features/0001-Rebrand.patch @@ -18,7 +18,7 @@ index 394443d00e661715439be1e56dddc129947699a4..480ad57a6b7b74e6b83e9c6ceb69ea1f public CrashReport(String title, Throwable exception) { io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(exception); // Paper diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java -index 1485186d4989874ef89c4e83830f26358a43759c..b48fc9e0b95fe6c8f72c5501b8de374e6ac2e5d6 100644 +index 1485186d4989874ef89c4e83830f26358a43759c..680369af59fd2aa36bf1cf4e28b598854383abe3 100644 --- a/net/minecraft/server/Main.java +++ b/net/minecraft/server/Main.java @@ -62,6 +62,14 @@ import org.slf4j.Logger; @@ -36,6 +36,25 @@ index 1485186d4989874ef89c4e83830f26358a43759c..b48fc9e0b95fe6c8f72c5501b8de374e @SuppressForbidden( reason = "System.out needed before bootstrap" +@@ -114,6 +122,18 @@ public class Main { + org.purpurmc.purpur.PurpurConfig.registerMinecraftDebugCommands = purpurConfiguration.getBoolean("settings.register-minecraft-debug-commands"); // Purpur - register minecraft debug commands + // Purpur end - Add toggle for enchant level clamping - load config files early + ++ // DivineMC start - Server startup settings ++ org.bukkit.configuration.file.YamlConfiguration divinemcConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("divinemc-settings")); ++ boolean divinemcNativeMathEnabled = divinemcConfiguration.getBoolean("settings.chunk-generation.native-acceleration-enabled", true); ++ if (divinemcNativeMathEnabled) { ++ try { ++ Class.forName("org.bxteam.divinemc.math.NativeLoader").getField("lookup").get(null); ++ } catch (Throwable e) { ++ e.printStackTrace(); ++ } ++ } ++ // DivineMC end - Server startup settings ++ + io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper + Bootstrap.bootStrap(); + Bootstrap.validate(); diff --git a/net/minecraft/server/gui/MinecraftServerGui.java b/net/minecraft/server/gui/MinecraftServerGui.java index 614c7d9f673c926562acc8fa3b3788623900db41..33456c7c106abbddf743e1203a6e8122cf10b797 100644 --- a/net/minecraft/server/gui/MinecraftServerGui.java diff --git a/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch b/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch index 54709a8..6894cfb 100644 --- a/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch +++ b/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch @@ -374,30 +374,245 @@ index b28083be4384d6c5efbdce898a0e9d7a2f5bd3d3..76b8d42ae530b59cdaba0583365a557d } } diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java -index 0c99bffa769d53562a10d23c4a9b37dc59c7f478..6094b9f2d4a686a4c639c739d182aba7aac430e8 100644 +index 0c99bffa769d53562a10d23c4a9b37dc59c7f478..16d3191fb6f90a5ea05090b951e265dff6a489f1 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java -@@ -1208,6 +1208,27 @@ public final class ChunkHolderManager { +@@ -71,36 +71,49 @@ public final class ChunkHolderManager { + private static final long PROBE_MARKER = Long.MIN_VALUE + 1; + public final ReentrantAreaLock ticketLockArea; + +- private final ConcurrentLong2ReferenceChainedHashTable>> tickets = new ConcurrentLong2ReferenceChainedHashTable<>(); +- private final ConcurrentLong2ReferenceChainedHashTable sectionToChunkToExpireCount = new ConcurrentLong2ReferenceChainedHashTable<>(); ++ // DivineMC start - Chunk System optimization ++ private final ConcurrentLong2ReferenceChainedHashTable>> tickets = ConcurrentLong2ReferenceChainedHashTable.createWithCapacity(20, 0.9F); ++ private final ConcurrentLong2ReferenceChainedHashTable sectionToChunkToExpireCount = ConcurrentLong2ReferenceChainedHashTable.createWithCapacity(20, 0.9F); ++ // DivineMC end - Chunk System optimization + final ChunkUnloadQueue unloadQueue; + +- private final ConcurrentLong2ReferenceChainedHashTable chunkHolders = ConcurrentLong2ReferenceChainedHashTable.createWithCapacity(16384, 0.25f); ++ private final ConcurrentLong2ReferenceChainedHashTable chunkHolders = ConcurrentLong2ReferenceChainedHashTable.createWithCapacity(20, 0.9F); // DivineMC - Chunk System optimization + private final ServerLevel world; + private final ChunkTaskScheduler taskScheduler; + private long currentTick; + +- private final ArrayDeque pendingFullLoadUpdate = new ArrayDeque<>(); +- private final ObjectRBTreeSet autoSaveQueue = new ObjectRBTreeSet<>((final NewChunkHolder c1, final NewChunkHolder c2) -> { +- if (c1 == c2) { +- return 0; +- } ++ // DivineMC start - Chunk System optimization ++ public static class LevelHolderData { ++ private final java.util.concurrent.ConcurrentLinkedDeque pendingFullLoadUpdate = new java.util.concurrent.ConcurrentLinkedDeque<>(); ++ private final ObjectRBTreeSet autoSaveQueue = new ObjectRBTreeSet<>((final NewChunkHolder c1, final NewChunkHolder c2) -> { ++ if (c1 == c2) { ++ return 0; ++ } + +- final int saveTickCompare = Long.compare(c1.lastAutoSave, c2.lastAutoSave); ++ final int saveTickCompare = Long.compare(c1.lastAutoSave, c2.lastAutoSave); + +- if (saveTickCompare != 0) { +- return saveTickCompare; +- } ++ if (saveTickCompare != 0) { ++ return saveTickCompare; ++ } + +- final long coord1 = CoordinateUtils.getChunkKey(c1.chunkX, c1.chunkZ); +- final long coord2 = CoordinateUtils.getChunkKey(c2.chunkX, c2.chunkZ); ++ final long coord1 = CoordinateUtils.getChunkKey(c1.chunkX, c1.chunkZ); ++ final long coord2 = CoordinateUtils.getChunkKey(c2.chunkX, c2.chunkZ); + +- if (coord1 == coord2) { +- throw new IllegalStateException("Duplicate chunkholder in auto save queue"); +- } ++ if (coord1 == coord2) { ++ throw new IllegalStateException("Duplicate chunkholder in auto save queue"); ++ } + +- return Long.compare(coord1, coord2); +- }); ++ return Long.compare(coord1, coord2); ++ }); ++ } ++ ++ public LevelHolderData getData() { ++ if (this.world == null) { ++ throw new RuntimeException("World was null!"); ++ } ++ return world.chunkHolderData; ++ } ++ // DivineMC end - Chunk System optimization + + public ChunkHolderManager(final ServerLevel world, final ChunkTaskScheduler taskScheduler) { + this.world = world; +@@ -222,26 +235,29 @@ public final class ChunkHolderManager { + this.taskScheduler.setShutdown(true); + } + +- void ensureInAutosave(final NewChunkHolder holder) { +- if (!this.autoSaveQueue.contains(holder)) { ++ // DivineMC start - Chunk System optimization ++ synchronized void ensureInAutosave(final NewChunkHolder holder) { ++ final LevelHolderData data = getData(); ++ if (!data.autoSaveQueue.contains(holder)) { + holder.lastAutoSave = this.currentTick; +- this.autoSaveQueue.add(holder); ++ data.autoSaveQueue.add(holder); + } + } + +- public void autoSave() { ++ public synchronized void autoSave() { ++ final LevelHolderData data = getData(); + final List reschedule = new ArrayList<>(); + final long currentTick = this.currentTick; + final long maxSaveTime = currentTick - Math.max(1L, PlatformHooks.get().configAutoSaveInterval(this.world)); + final int maxToSave = PlatformHooks.get().configMaxAutoSavePerTick(this.world); +- for (int autoSaved = 0; autoSaved < maxToSave && !this.autoSaveQueue.isEmpty();) { +- final NewChunkHolder holder = this.autoSaveQueue.first(); ++ for (int autoSaved = 0; autoSaved < maxToSave && !data.autoSaveQueue.isEmpty();) { ++ final NewChunkHolder holder = data.autoSaveQueue.first(); + + if (holder.lastAutoSave > maxSaveTime) { + break; + } + +- this.autoSaveQueue.remove(holder); ++ data.autoSaveQueue.remove(holder); + + holder.lastAutoSave = currentTick; + if (holder.save(false) != null) { +@@ -255,10 +271,11 @@ public final class ChunkHolderManager { + + for (final NewChunkHolder holder : reschedule) { + if (holder.getChunkStatus().isOrAfter(FullChunkStatus.FULL)) { +- this.autoSaveQueue.add(holder); ++ data.autoSaveQueue.add(holder); + } + } + } ++ // DivineMC end - Chunk System optimization + + public void saveAllChunks(final boolean flush, final boolean shutdown, final boolean logProgress) { + final List holders = this.getChunkHolders(); +@@ -317,13 +334,9 @@ public final class ChunkHolderManager { + } + if (logProgress) { + final long currTime = System.nanoTime(); +- if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(10L)) { ++ if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(5L)) { // DivineMC - Log a bit more frequently + lastLog = currTime; +- LOGGER.info( +- "Saved " + savedChunk + " block chunks, " + savedEntity + " entity chunks, " + savedPoi +- + " poi chunks in world '" + WorldUtil.getWorldName(this.world) + "', progress: " +- + format.format((double)(i+1)/(double)len * 100.0) +- ); ++ LOGGER.info("Saved {} block chunks, {} entity chunks, {} poi chunks in world '{}', progress: {}", savedChunk, savedEntity, savedPoi, ca.spottedleaf.moonrise.common.util.WorldUtil.getWorldName(this.world), format.format((double) (i + 1) / (double) len * 100.0)); // DivineMC - Beautify log + } + } + } +@@ -425,8 +438,8 @@ public final class ChunkHolderManager { + final Long2ObjectOpenHashMap>> ret = new Long2ObjectOpenHashMap<>(); + final Long2ObjectOpenHashMap sections = new Long2ObjectOpenHashMap<>(); + final int sectionShift = this.taskScheduler.getChunkSystemLockShift(); +- for (final PrimitiveIterator.OfLong iterator = this.tickets.keyIterator(); iterator.hasNext();) { +- final long coord = iterator.nextLong(); ++ for (final Iterator iterator = this.tickets.keyIterator(); iterator.hasNext();) { // DivineMC - Chunk System optimization ++ final long coord = iterator.next(); // DivineMC - Chunk System optimization + sections.computeIfAbsent( + CoordinateUtils.getChunkKey( + CoordinateUtils.getChunkX(coord) >> sectionShift, +@@ -523,7 +536,7 @@ public final class ChunkHolderManager { + chunkZ >> sectionShift + ); + +- this.sectionToChunkToExpireCount.computeIfAbsent(sectionKey, (final long keyInMap) -> { ++ this.sectionToChunkToExpireCount.computeIfAbsent(sectionKey, (keyInMap) -> { // DivineMC - Chunk System optimization + return new Long2IntOpenHashMap(); + }).addTo(chunkKey, 1); + } +@@ -567,7 +580,7 @@ public final class ChunkHolderManager { + + final ReentrantAreaLock.Node ticketLock = lock ? this.ticketLockArea.lock(chunkX, chunkZ) : null; + try { +- final SortedArraySet> ticketsAtChunk = this.tickets.computeIfAbsent(chunk, (final long keyInMap) -> { ++ final SortedArraySet> ticketsAtChunk = this.tickets.computeIfAbsent(chunk, (keyInMap) -> { // DivineMC - Chunk System optimization + return SortedArraySet.create(4); + }); + +@@ -697,8 +710,8 @@ public final class ChunkHolderManager { + + final Long2ObjectOpenHashMap sections = new Long2ObjectOpenHashMap<>(); + final int sectionShift = this.taskScheduler.getChunkSystemLockShift(); +- for (final PrimitiveIterator.OfLong iterator = this.tickets.keyIterator(); iterator.hasNext();) { +- final long coord = iterator.nextLong(); ++ for (final Iterator iterator = this.tickets.keyIterator(); iterator.hasNext();) { // DivineMC - Chunk System optimization ++ final long coord = iterator.next(); // DivineMC - Chunk System optimization + sections.computeIfAbsent( + CoordinateUtils.getChunkKey( + CoordinateUtils.getChunkX(coord) >> sectionShift, +@@ -746,8 +759,8 @@ public final class ChunkHolderManager { + return removeDelay <= 0L; + }; + +- for (final PrimitiveIterator.OfLong iterator = this.sectionToChunkToExpireCount.keyIterator(); iterator.hasNext();) { +- final long sectionKey = iterator.nextLong(); ++ for (final Iterator iterator = this.sectionToChunkToExpireCount.keyIterator(); iterator.hasNext();) { // DivineMC - Chunk System optimization ++ final long sectionKey = iterator.next(); // DivineMC - Chunk System optimization + + if (!this.sectionToChunkToExpireCount.containsKey(sectionKey)) { + // removed concurrently +@@ -1033,7 +1046,7 @@ public final class ChunkHolderManager { + } + if (!TickThread.isTickThreadFor(world)) { // DivineMC - parallel world ticking + this.taskScheduler.scheduleChunkTask(() -> { +- final ArrayDeque pendingFullLoadUpdate = ChunkHolderManager.this.pendingFullLoadUpdate; ++ final java.util.Deque pendingFullLoadUpdate = ChunkHolderManager.this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization + for (int i = 0, len = changedFullStatus.size(); i < len; ++i) { + pendingFullLoadUpdate.add(changedFullStatus.get(i)); + } +@@ -1041,16 +1054,16 @@ public final class ChunkHolderManager { + ChunkHolderManager.this.processPendingFullUpdate(); + }, Priority.HIGHEST); + } else { +- final ArrayDeque pendingFullLoadUpdate = this.pendingFullLoadUpdate; ++ final java.util.Deque pendingFullLoadUpdate = this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization + for (int i = 0, len = changedFullStatus.size(); i < len; ++i) { + pendingFullLoadUpdate.add(changedFullStatus.get(i)); + } + } + } + +- private void removeChunkHolder(final NewChunkHolder holder) { ++ private synchronized void removeChunkHolder(final NewChunkHolder holder) { // DivineMC - Chunk System optimization + holder.onUnload(); +- this.autoSaveQueue.remove(holder); ++ this.getData().autoSaveQueue.remove(holder); // DivineMC - Chunk System optimization + PlatformHooks.get().onChunkHolderDelete(this.world, holder.vanillaChunkHolder); + this.chunkHolders.remove(CoordinateUtils.getChunkKey(holder.chunkX, holder.chunkZ)); + } +@@ -1208,6 +1221,27 @@ public final class ChunkHolderManager { } } + // DivineMC start - Chunk System optimization -+ public final org.agrona.collections.Object2ObjectHashMap blockTickingChunkHolders = new org.agrona.collections.Object2ObjectHashMap<>(16384, 0.25f); -+ public final org.agrona.collections.Object2ObjectHashMap entityTickingChunkHolders = new org.agrona.collections.Object2ObjectHashMap<>(16384, 0.25f); ++ public final java.util.Set blockTickingChunkHolders = java.util.Collections.synchronizedSet(new org.agrona.collections.ObjectHashSet<>(1384, 0.75f)); ++ public final java.util.Set entityTickingChunkHolders = java.util.Collections.synchronizedSet(new org.agrona.collections.ObjectHashSet<>(1384, 0.75f)); + -+ public void markBlockTicking(NewChunkHolder newChunkHolder) { -+ this.blockTickingChunkHolders.put(newChunkHolder.getCachedLongPos(), newChunkHolder); ++ public void markBlockTicking(@org.jetbrains.annotations.NotNull NewChunkHolder newChunkHolder) { ++ this.blockTickingChunkHolders.add(newChunkHolder.getCachedLongPos()); + } + -+ public void markNonBlockTickingIfPossible(NewChunkHolder newChunkHolder) { ++ public void markNonBlockTickingIfPossible(@org.jetbrains.annotations.NotNull NewChunkHolder newChunkHolder) { + this.blockTickingChunkHolders.remove(newChunkHolder.getCachedLongPos()); + } + -+ public void markEntityTicking(NewChunkHolder newChunkHolder) { -+ this.entityTickingChunkHolders.put(newChunkHolder.getCachedLongPos(), newChunkHolder); ++ public void markEntityTicking(@org.jetbrains.annotations.NotNull NewChunkHolder newChunkHolder) { ++ this.entityTickingChunkHolders.add(newChunkHolder.getCachedLongPos()); + } + -+ public void markNonEntityTickingIfPossible(NewChunkHolder newChunkHolder) { ++ public void markNonEntityTickingIfPossible(@org.jetbrains.annotations.NotNull NewChunkHolder newChunkHolder) { + this.entityTickingChunkHolders.remove(newChunkHolder.getCachedLongPos()); + } + // DivineMC end - Chunk System optimization @@ -405,6 +620,25 @@ index 0c99bffa769d53562a10d23c4a9b37dc59c7f478..6094b9f2d4a686a4c639c739d182aba7 public enum TicketOperationType { ADD, REMOVE, ADD_IF_REMOVED, ADD_AND_REMOVE } +@@ -1381,7 +1415,7 @@ public final class ChunkHolderManager { + + // only call on tick thread + private boolean processPendingFullUpdate() { +- final ArrayDeque pendingFullLoadUpdate = this.pendingFullLoadUpdate; ++ final java.util.Deque pendingFullLoadUpdate = this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization + + boolean ret = false; + +@@ -1417,8 +1451,7 @@ public final class ChunkHolderManager { + final JsonArray allTicketsJson = new JsonArray(); + ret.add("tickets", allTicketsJson); + +- for (final Iterator>>> iterator = this.tickets.entryIterator(); +- iterator.hasNext();) { ++ for (final Iterator>>> iterator = this.tickets.entryIterator(); iterator.hasNext();) { // DivineMC - Chunk System optimization + final ConcurrentLong2ReferenceChainedHashTable.TableEntry>> coordinateTickets = iterator.next(); + final long coordinate = coordinateTickets.getKey(); + final SortedArraySet> tickets = coordinateTickets.getValue(); diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java index e4a5fa25ed368fc4662c30934da2963ef446d782..6da0ea5cd83a00578223e0a19f952c917bcbcdae 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java @@ -513,78 +747,106 @@ index e97e7d276faf055c89207385d3820debffb06463..4aeb75a2cdcfb4206bab3eee5ad674dd } diff --git a/net/minecraft/server/level/DistanceManager.java b/net/minecraft/server/level/DistanceManager.java -index 5eab6179ce3913cb4e4d424f910ba423faf21c85..189205fbeed7673398fa6f7706864d3723467811 100644 +index 5eab6179ce3913cb4e4d424f910ba423faf21c85..4b1efd53e423bdfe90d5efd472823869fc87e73b 100644 --- a/net/minecraft/server/level/DistanceManager.java +++ b/net/minecraft/server/level/DistanceManager.java -@@ -178,14 +178,14 @@ public abstract class DistanceManager implements ca.spottedleaf.moonrise.patches +@@ -178,15 +178,13 @@ public abstract class DistanceManager implements ca.spottedleaf.moonrise.patches public boolean inEntityTickingRange(long chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkHolderManager().getChunkHolder(chunkPos); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkHolderManager().entityTickingChunkHolders.get(chunkPos); // DivineMC - Chunk System optimization - return chunkHolder != null && chunkHolder.isEntityTickingReady(); +- return chunkHolder != null && chunkHolder.isEntityTickingReady(); ++ return this.moonrise$getChunkHolderManager().entityTickingChunkHolders.contains(chunkPos); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } public boolean inBlockTickingRange(long chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkHolderManager().getChunkHolder(chunkPos); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkHolderManager().blockTickingChunkHolders.get(chunkPos); // DivineMC - Chunk System optimization - return chunkHolder != null && chunkHolder.isTickingReady(); +- return chunkHolder != null && chunkHolder.isTickingReady(); ++ return this.moonrise$getChunkHolderManager().blockTickingChunkHolders.contains(chunkPos); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } + diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java -index 2678bf59d557f085c7265e2f3eb038647723d35e..b30d6968fba2ab4d9cde0ac9d4f1cfc629c65359 100644 +index 2678bf59d557f085c7265e2f3eb038647723d35e..cce12dce852457325ed6e57e5a4cc00555631ea6 100644 --- a/net/minecraft/server/level/ServerChunkCache.java +++ b/net/minecraft/server/level/ServerChunkCache.java -@@ -441,7 +441,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -441,8 +441,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon public boolean isPositionTicking(long chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder newChunkHolder = ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkPos); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder newChunkHolder = ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.get(chunkPos); // DivineMC Chunk System optimization - return newChunkHolder != null && newChunkHolder.isTickingReady(); +- return newChunkHolder != null && newChunkHolder.isTickingReady(); ++ return ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.contains(chunkPos); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } + diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..57668810e86b1f293c661d01c2486a3da7256c1e 100644 +index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..e5ef117e3fb3dd822a7d69e2e47fa25416be38b7 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -857,7 +857,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -183,6 +183,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + public final ServerChunkCache chunkSource; + private final MinecraftServer server; + public final net.minecraft.world.level.storage.PrimaryLevelData serverLevelData; // CraftBukkit - type ++ public final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager.LevelHolderData chunkHolderData; // DivineMC - Chunk System optimization + private int lastSpawnChunkRadius; + final EntityTickList entityTickList = new EntityTickList(this); // DivineMC - parallel world ticking + // Paper - rewrite chunk system +@@ -691,6 +692,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + // Paper start - rewrite chunk system + this.moonrise$setEntityLookup(new ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup((ServerLevel)(Object)this, ((ServerLevel)(Object)this).new EntityCallbacks())); + this.chunkTaskScheduler = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler((ServerLevel)(Object)this); ++ this.chunkHolderData = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager.LevelHolderData(); // DivineMC - Chunk System optimization + this.entityDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController( + new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController.EntityRegionFileStorage( + new RegionStorageInfo(levelStorageAccess.getLevelId(), dimension, "entities"), +@@ -857,8 +859,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public boolean shouldTickBlocksAt(long chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder holder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkPos); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder holder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.get(chunkPos); // DivineMC - Chunk System optimization - return holder != null && holder.isTickingReady(); +- return holder != null && holder.isTickingReady(); ++ return this.moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.contains(chunkPos); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } -@@ -2567,7 +2567,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + +@@ -2567,30 +2568,25 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe private boolean isPositionTickingWithEntitiesLoaded(long chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkPos); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.get(chunkPos); // DivineMC - Chunk System optimization - // isTicking implies the chunk is loaded, and the chunk is loaded now implies the entities are loaded - return chunkHolder != null && chunkHolder.isTickingReady(); +- // isTicking implies the chunk is loaded, and the chunk is loaded now implies the entities are loaded +- return chunkHolder != null && chunkHolder.isTickingReady(); ++ return this.moonrise$getChunkTaskScheduler().chunkHolderManager.blockTickingChunkHolders.contains(chunkPos); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system -@@ -2582,14 +2582,14 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + } + + public boolean isPositionEntityTicking(BlockPos pos) { + // Paper start - rewrite chunk system +- final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos)); +- return chunkHolder != null && chunkHolder.isEntityTickingReady(); ++ return this.moonrise$getChunkTaskScheduler().chunkHolderManager.entityTickingChunkHolders.contains(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos)); // DivineMC - Chunk System optimization + // Paper end - rewrite chunk system + } public boolean isNaturalSpawningAllowed(BlockPos pos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos)); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.entityTickingChunkHolders.get(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos)); // DivineMC - Chunk System optimization - return chunkHolder != null && chunkHolder.isEntityTickingReady(); +- return chunkHolder != null && chunkHolder.isEntityTickingReady(); ++ return this.moonrise$getChunkTaskScheduler().chunkHolderManager.entityTickingChunkHolders.contains(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos)); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } public boolean isNaturalSpawningAllowed(ChunkPos chunkPos) { // Paper start - rewrite chunk system - final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunkPos)); -+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.entityTickingChunkHolders.get(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunkPos)); // DivineMC - Chunk System optimization - return chunkHolder != null && chunkHolder.isEntityTickingReady(); +- return chunkHolder != null && chunkHolder.isEntityTickingReady(); ++ return this.moonrise$getChunkTaskScheduler().chunkHolderManager.entityTickingChunkHolders.contains(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunkPos)); // DivineMC - Chunk System optimization // Paper end - rewrite chunk system } + diff --git a/net/minecraft/world/level/LevelReader.java b/net/minecraft/world/level/LevelReader.java index 26c8c1e5598daf3550aef05b12218c47bda6618b..94c824ab1457939c425e1f99929d3222ee2c18a0 100644 --- a/net/minecraft/world/level/LevelReader.java diff --git a/divinemc-server/minecraft-patches/features/0013-Optimize-hoppers.patch b/divinemc-server/minecraft-patches/features/0013-Optimize-hoppers.patch index eae3845..97f5e6f 100644 --- a/divinemc-server/minecraft-patches/features/0013-Optimize-hoppers.patch +++ b/divinemc-server/minecraft-patches/features/0013-Optimize-hoppers.patch @@ -17,10 +17,10 @@ index 3002ed51a579e81c3266da79a5dd38bac0b4a39c..9fdd4bbbe0e4c75880e9f24741fea7c6 profilerFiller.push(() -> serverLevel + " " + serverLevel.dimension().location()); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..0de0570397a6c6de43b1143b0d722af7a6093c8e 100644 +index e5ef117e3fb3dd822a7d69e2e47fa25416be38b7..78be192760b5c4dfc9db740d856689a38a3ac1b1 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -195,7 +195,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -196,7 +196,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe private final LevelTicks fluidTicks = new LevelTicks<>(this::isPositionTickingWithEntitiesLoaded); private final PathTypeCache pathTypesByPosCache = new PathTypeCache(); final Set navigatingMobs = new ObjectOpenHashSet<>(); @@ -29,7 +29,7 @@ index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..0de0570397a6c6de43b1143b0d722af7 protected final Raids raids; private final ObjectLinkedOpenHashSet blockEvents = new ObjectLinkedOpenHashSet<>(); private final List blockEventsToReschedule = new ArrayList<>(64); -@@ -1770,7 +1770,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1771,7 +1771,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public void sendBlockUpdated(BlockPos pos, BlockState oldState, BlockState newState, int flags) { @@ -38,7 +38,7 @@ index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..0de0570397a6c6de43b1143b0d722af7 String string = "recursive call to sendBlockUpdated"; Util.logAndPauseIfInIde("recursive call to sendBlockUpdated", new IllegalStateException("recursive call to sendBlockUpdated")); } -@@ -1801,13 +1801,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1802,13 +1802,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // Paper end - catch CME see below why try { @@ -54,7 +54,7 @@ index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..0de0570397a6c6de43b1143b0d722af7 } } } // Paper - option to disable pathfinding updates -@@ -2699,7 +2699,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2695,7 +2695,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } if (entity instanceof Mob mob) { @@ -63,7 +63,7 @@ index a3f363d0c86142e03edc7fc6e2ff6ed81de8ed65..0de0570397a6c6de43b1143b0d722af7 String string = "onTrackingStart called during navigation iteration"; Util.logAndPauseIfInIde( "onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration") -@@ -2769,7 +2769,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2765,7 +2765,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } if (entity instanceof Mob mob) { diff --git a/divinemc-server/minecraft-patches/features/0019-Lag-compensation.patch b/divinemc-server/minecraft-patches/features/0019-Lag-compensation.patch index ed83110..6cd7da9 100644 --- a/divinemc-server/minecraft-patches/features/0019-Lag-compensation.patch +++ b/divinemc-server/minecraft-patches/features/0019-Lag-compensation.patch @@ -25,10 +25,10 @@ index 9fdd4bbbe0e4c75880e9f24741fea7c60c57d09a..ad308e75a58e7db5247489b5d4447b12 this.tickCount++; this.tickRateManager.tick(); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 6fc3db6fa365da0512ff3c845586a9d54e8b23b2..e684eaed9740c3236a8f2bd7cce0d86661632a87 100644 +index 78be192760b5c4dfc9db740d856689a38a3ac1b1..69e1b06cc8876f8ef743b77c850e4f4198b5728f 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -219,6 +219,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -220,6 +220,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current) public boolean hasRidableMoveEvent = false; // Purpur - Ridables @@ -36,7 +36,7 @@ index 6fc3db6fa365da0512ff3c845586a9d54e8b23b2..e684eaed9740c3236a8f2bd7cce0d866 public LevelChunk getChunkIfLoaded(int x, int z) { return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately -@@ -776,6 +777,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -778,6 +779,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } } @@ -45,7 +45,7 @@ index 6fc3db6fa365da0512ff3c845586a9d54e8b23b2..e684eaed9740c3236a8f2bd7cce0d866 this.updateSkyBrightness(); if (runsNormally) { this.tickTime(); -@@ -877,11 +880,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -878,11 +881,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.setDayTime(this.preciseTime); } else // Purpur end - Configurable daylight cycle diff --git a/divinemc-server/minecraft-patches/features/0020-MSPT-Tracking-for-each-world.patch b/divinemc-server/minecraft-patches/features/0020-MSPT-Tracking-for-each-world.patch index b957da9..b4e5b47 100644 --- a/divinemc-server/minecraft-patches/features/0020-MSPT-Tracking-for-each-world.patch +++ b/divinemc-server/minecraft-patches/features/0020-MSPT-Tracking-for-each-world.patch @@ -25,10 +25,10 @@ index ad308e75a58e7db5247489b5d4447b1271ee0102..8feec3f633f2fa12591fb84c90e0b28b CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world"); serverLevel.fillReportDetails(crashReport); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index e684eaed9740c3236a8f2bd7cce0d86661632a87..7aef92967cb8a662e644225a4122a544f3cff937 100644 +index 69e1b06cc8876f8ef743b77c850e4f4198b5728f..4e04fa8f7f57d30a63867dafa6d26fc88ed87a32 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -575,6 +575,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -576,6 +576,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } // Paper end - chunk tick iteration diff --git a/divinemc-server/minecraft-patches/features/0030-Verify-Minecraft-EULA-earlier.patch b/divinemc-server/minecraft-patches/features/0030-Verify-Minecraft-EULA-earlier.patch index dd5ff10..7ce0984 100644 --- a/divinemc-server/minecraft-patches/features/0030-Verify-Minecraft-EULA-earlier.patch +++ b/divinemc-server/minecraft-patches/features/0030-Verify-Minecraft-EULA-earlier.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Verify Minecraft EULA earlier diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java -index b48fc9e0b95fe6c8f72c5501b8de374e6ac2e5d6..44e98037c986dec845613fa24f9664ef1803b96c 100644 +index 680369af59fd2aa36bf1cf4e28b598854383abe3..d415a175ea1e7b5a5bf1149187247dd7b2619c29 100644 --- a/net/minecraft/server/Main.java +++ b/net/minecraft/server/Main.java -@@ -131,7 +131,6 @@ public class Main { +@@ -143,7 +143,6 @@ public class Main { dedicatedServerSettings.forceSave(); RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression); Path path2 = Paths.get("eula.txt"); @@ -16,7 +16,7 @@ index b48fc9e0b95fe6c8f72c5501b8de374e6ac2e5d6..44e98037c986dec845613fa24f9664ef // Paper start - load config files early for access below if needed org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("bukkit-settings")); org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("spigot-settings")); -@@ -154,19 +153,6 @@ public class Main { +@@ -166,19 +165,6 @@ public class Main { return; } diff --git a/divinemc-server/minecraft-patches/features/0036-Regionized-Chunk-Ticking.patch b/divinemc-server/minecraft-patches/features/0036-Regionized-Chunk-Ticking.patch index 5b5ad32..b48badc 100644 --- a/divinemc-server/minecraft-patches/features/0036-Regionized-Chunk-Ticking.patch +++ b/divinemc-server/minecraft-patches/features/0036-Regionized-Chunk-Ticking.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Regionized Chunk Ticking diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java -index b30d6968fba2ab4d9cde0ac9d4f1cfc629c65359..2aeb819cfea737284a8061debcf829417c19aa3c 100644 +index cce12dce852457325ed6e57e5a4cc00555631ea6..0c542bfa8f6d8fd47427dcf74f71500ed5772f35 100644 --- a/net/minecraft/server/level/ServerChunkCache.java +++ b/net/minecraft/server/level/ServerChunkCache.java @@ -56,6 +56,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon @@ -19,7 +19,7 @@ index b30d6968fba2ab4d9cde0ac9d4f1cfc629c65359..2aeb819cfea737284a8061debcf82941 public final Thread mainThread; final ThreadedLevelLightEngine lightEngine; public final ServerChunkCache.MainThreadExecutor mainThreadProcessor; -@@ -479,6 +483,46 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -478,6 +482,46 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon } // CraftBukkit end @@ -66,7 +66,7 @@ index b30d6968fba2ab4d9cde0ac9d4f1cfc629c65359..2aeb819cfea737284a8061debcf82941 @Override public void tick(BooleanSupplier hasTimeLeft, boolean tickChunks) { ProfilerFiller profilerFiller = Profiler.get(); -@@ -519,7 +563,44 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -518,7 +562,44 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon this.shuffleRandom.setSeed(this.level.random.nextLong()); if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled // Paper end - chunk tick iteration optimisation diff --git a/divinemc-server/minecraft-patches/features/0041-lithium-block_entity_ticking.sleeping.patch b/divinemc-server/minecraft-patches/features/0041-lithium-block_entity_ticking.sleeping.patch index 9cc77d8..8766380 100644 --- a/divinemc-server/minecraft-patches/features/0041-lithium-block_entity_ticking.sleeping.patch +++ b/divinemc-server/minecraft-patches/features/0041-lithium-block_entity_ticking.sleeping.patch @@ -5,10 +5,10 @@ Subject: [PATCH] lithium: block_entity_ticking.sleeping diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 9ccc6dd7d0e64a9cd54ab6f7bc276d380ea26717..c1a2d6716021909b511b1cb62f79aa68663faf41 100644 +index 4e04fa8f7f57d30a63867dafa6d26fc88ed87a32..62cc61d9d7115ed547ae87e74caf3d9131853a83 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -2439,7 +2439,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2440,7 +2440,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe CsvOutput csvOutput = CsvOutput.builder().addColumn("x").addColumn("y").addColumn("z").addColumn("type").build(output); for (TickingBlockEntity tickingBlockEntity : this.blockEntityTickers) { @@ -17,7 +17,7 @@ index 9ccc6dd7d0e64a9cd54ab6f7bc276d380ea26717..c1a2d6716021909b511b1cb62f79aa68 csvOutput.writeRow(pos.getX(), pos.getY(), pos.getZ(), tickingBlockEntity.getType()); } } -@@ -2494,6 +2494,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2495,6 +2495,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe return this; }