From 9f2465f16afcd6e31a24b608921aa5e9ff66edc0 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Wed, 25 Jun 2025 15:21:24 -0300 Subject: [PATCH] Updated Upstream (Paper / d7510ef) This removes the Folia scheduler optimization patch because Paper optimized it upstream (yay) --- gradle.properties | 2 +- sparklypaper-server/build.gradle.kts.patch | 18 +++--- .../0001-Parallel-World-Ticking.patch | 42 +++++-------- .../server/MinecraftServer.java.patch | 55 ----------------- .../EntityScheduler.java.patch | 60 ------------------- 5 files changed, 26 insertions(+), 151 deletions(-) delete mode 100644 sparklypaper-server/minecraft-patches/sources/net/minecraft/server/MinecraftServer.java.patch delete mode 100644 sparklypaper-server/paper-patches/files/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java.patch diff --git a/gradle.properties b/gradle.properties index 494ca03..461cde4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ group=net.sparklypower.sparklypaper version=1.21.6-R0.1-SNAPSHOT mcVersion=1.21.6 -paperRef=1814d8b47ad8c174ab5c5b5c22a06ffb7de20ab3 +paperRef=d7510efc16a586a732f6718963b555f649181a9b org.gradle.configuration-cache=true org.gradle.caching=true diff --git a/sparklypaper-server/build.gradle.kts.patch b/sparklypaper-server/build.gradle.kts.patch index e7c780c..ddbbb0b 100644 --- a/sparklypaper-server/build.gradle.kts.patch +++ b/sparklypaper-server/build.gradle.kts.patch @@ -1,6 +1,6 @@ --- a/paper-server/build.gradle.kts +++ b/paper-server/build.gradle.kts -@@ -7,6 +_,8 @@ +@@ -8,6 +_,8 @@ plugins { `java-library` @@ -9,7 +9,7 @@ `maven-publish` idea id("io.papermc.paperweight.core") -@@ -21,6 +_,16 @@ +@@ -23,6 +_,16 @@ } paperweight { @@ -19,14 +19,14 @@ + excludes = setOf("src/minecraft", "patches", "build.gradle.kts") + patchesDir = rootDirectory.dir("sparklypaper-server/paper-patches") + outputDir = rootDirectory.dir("paper-server") -+ } ++ } + } + activeFork = fork + minecraftVersion = providers.gradleProperty("mcVersion") gitFilePatches = false -@@ -105,7 +_,19 @@ +@@ -107,7 +_,19 @@ } } @@ -36,7 +36,7 @@ + java { srcDir("../paper-server/src/main/java") } + resources { srcDir("../paper-server/src/main/resources") } + } -+ test { ++ test { + java { srcDir("../paper-server/src/test/java") } + resources { srcDir("../paper-server/src/test/resources") } + } @@ -47,7 +47,7 @@ configurations.named(log4jPlugins.compileClasspathConfigurationName) { extendsFrom(configurations.compileClasspath.get()) } -@@ -127,7 +_,12 @@ +@@ -129,7 +_,12 @@ } dependencies { @@ -61,7 +61,7 @@ implementation("ca.spottedleaf:concurrentutil:0.0.3") implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+ implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21 -@@ -198,9 +_,14 @@ +@@ -200,9 +_,14 @@ val build = System.getenv("BUILD_NUMBER") ?: null val buildTime = if (build != null) Instant.now() else Instant.EPOCH val gitHash = git.exec(providers, "rev-parse", "--short=7", "HEAD").get().trim() @@ -77,7 +77,7 @@ attributes( "Main-Class" to "org.bukkit.craftbukkit.Main", "Implementation-Title" to "Paper", -@@ -209,8 +_,8 @@ +@@ -211,8 +_,8 @@ "Specification-Title" to "Paper", "Specification-Version" to project.version, "Specification-Vendor" to "Paper Team", @@ -88,7 +88,7 @@ "Build-Number" to (build ?: ""), "Build-Time" to buildTime.toString(), "Git-Branch" to gitBranch, -@@ -269,7 +_,7 @@ +@@ -271,7 +_,7 @@ jvmArgumentProviders.add(provider) } diff --git a/sparklypaper-server/minecraft-patches/features/0001-Parallel-World-Ticking.patch b/sparklypaper-server/minecraft-patches/features/0001-Parallel-World-Ticking.patch index 2016d00..e2b2e72 100644 --- a/sparklypaper-server/minecraft-patches/features/0001-Parallel-World-Ticking.patch +++ b/sparklypaper-server/minecraft-patches/features/0001-Parallel-World-Ticking.patch @@ -57,18 +57,18 @@ index ca02c4c71a0a5a1a0ae8bbb40f0b1b7eac64e6fd..7ce68f270d809ab0b2be45ffdd0346f0 List states = new java.util.ArrayList<>(level.capturedBlockStates.values()); level.capturedBlockStates.clear(); diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index 6f492b08d63eb6621383261361f94eaeb7e2f20c..f7d3804035d2c8daecef0b52b4346e9b20da12f2 100644 +index 52fa5112cd90ba766c94512a02401dd3aee82cc9..07528605b060115fe4a61c881eec76897320df63 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java -@@ -304,6 +304,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation - public final Set entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async) + public java.util.concurrent.Semaphore serverLevelTickingSemaphore = null; // SparklyPaper - parallel world ticking public static S spin(Function threadFunction) { ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system -@@ -1719,6 +1720,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper - BlockPhysicsEvent serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent -@@ -1735,27 +1739,46 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop, ServerLevel> oldLevels = this.levels; Map, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels); newLevels.remove(level.dimension()); @@ -150,7 +140,7 @@ index 6f492b08d63eb6621383261361f94eaeb7e2f20c..f7d3804035d2c8daecef0b52b4346e9b } // CraftBukkit end diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java -index c1f8bf904a099e80248d5970ce14fd810e683b4d..9034f43140cd92919d2d6eb7aec47f4bc8019e8c 100644 +index 17846055ae1b88a357ed671362aab7983331921a..36aae942ff6ea14a3e6060140af661a6692af891 100644 --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java @@ -193,6 +193,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @@ -251,18 +241,18 @@ index ecfe237fbecde610d095647a1f2a10f7d426d786..4211816c3b21a2ee66297a8f58b51de3 // Paper start - extra debug info if (entity.valid) { diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java -index 53f038e1b5e7a13a08a0c925c8bd3f8a40868195..b7373b769a751a6381272915c6e424c7a661a11f 100644 +index f3eca351021c37b64315872d075bd0a84aeee267..d4648ecc943324d1f66fe5fcfe4cfafef98af7ba 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java -@@ -461,6 +461,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc - return this.viewDistanceHolder; +@@ -525,6 +525,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc + } } - // Paper end - rewrite chunk system + // Paper end - improve keepalives + public boolean hasTickedAtLeastOnceInNewWorld = false; // SparklyPaper - parallel world ticking (fixes bug in DreamResourceReset where the inventory is opened AFTER the player has changed worlds, if you click with the quick tp torch in a chest, because the inventory is opened AFTER the player has teleported) public ServerPlayer(MinecraftServer server, ServerLevel level, GameProfile gameProfile, ClientInformation clientInformation) { super(level, gameProfile); -@@ -741,6 +742,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc +@@ -805,6 +806,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc @Override public void tick() { @@ -270,7 +260,7 @@ index 53f038e1b5e7a13a08a0c925c8bd3f8a40868195..b7373b769a751a6381272915c6e424c7 // CraftBukkit start if (this.joining) { this.joining = false; -@@ -1396,6 +1398,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc +@@ -1460,6 +1462,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc return this; } else { // CraftBukkit start @@ -278,7 +268,7 @@ index 53f038e1b5e7a13a08a0c925c8bd3f8a40868195..b7373b769a751a6381272915c6e424c7 /* this.isChangingDimension = true; LevelData levelData = level.getLevelData(); -@@ -1732,6 +1735,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc +@@ -1796,6 +1799,12 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc return OptionalInt.empty(); } else { // CraftBukkit start @@ -291,7 +281,7 @@ index 53f038e1b5e7a13a08a0c925c8bd3f8a40868195..b7373b769a751a6381272915c6e424c7 this.containerMenu = abstractContainerMenu; // Moved up if (!this.isImmobile()) this.connection -@@ -1796,6 +1805,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc +@@ -1860,6 +1869,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc } @Override public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) { @@ -439,7 +429,7 @@ index f9e7532f86122a379692561a639a209a126e8bba..2709dfae53c1a210f36c45fa0df0d495 if (isLocatorBarEnabledFor(player)) { if (!connection.isBroken()) { diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 7546ff4c5ffc62d93a3f874519db8fef1e3bfbcb..ab951849440817877ecf6f52ba61cebd900cf100 100644 +index 81413ac0de7b3c7a72bc606fe5ae6fb4ae7055e3..69980f5a2766b17c429785ef05520d6af3201735 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -834,7 +834,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess diff --git a/sparklypaper-server/minecraft-patches/sources/net/minecraft/server/MinecraftServer.java.patch b/sparklypaper-server/minecraft-patches/sources/net/minecraft/server/MinecraftServer.java.patch deleted file mode 100644 index 1f93067..0000000 --- a/sparklypaper-server/minecraft-patches/sources/net/minecraft/server/MinecraftServer.java.patch +++ /dev/null @@ -1,55 +0,0 @@ ---- a/net/minecraft/server/MinecraftServer.java -+++ b/net/minecraft/server/MinecraftServer.java -@@ -303,6 +_,7 @@ - public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked - private final Set pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping - public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation -+ public final Set entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async) - - public static S spin(Function threadFunction) { - ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system -@@ -1659,6 +_,18 @@ - this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit - // Paper start - Folia scheduler API - ((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) org.bukkit.Bukkit.getGlobalRegionScheduler()).tick(); -+ // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run -+ for (final net.minecraft.world.entity.Entity entity : entitiesWithScheduledTasks) { -+ if (entity.isRemoved()) { -+ continue; -+ } -+ -+ final org.bukkit.craftbukkit.entity.CraftEntity bukkit = entity.getBukkitEntityRaw(); -+ if (bukkit != null) { -+ bukkit.taskScheduler.executeTick(); -+ } -+ } -+ /* - getAllLevels().forEach(level -> { - for (final net.minecraft.world.entity.Entity entity : level.getEntities().getAll()) { - if (entity.isRemoved()) { -@@ -1670,6 +_,8 @@ - } - } - }); -+ */ -+ // SparklyPaper end - // Paper end - Folia scheduler API - io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper - profilerFiller.push("commandFunctions"); -@@ -1721,7 +_,16 @@ - profilerFiller.push("tick"); - - try { -+ long i = Util.getNanos(); // SparklyPaper - track world's MSPT - serverLevel.tick(hasTimeLeft); -+ // SparklyPaper start - track world's MSPT -+ long j = Util.getNanos() - i; -+ -+ // These are from the "tickServer" function -+ serverLevel.tickTimes5s.add(this.tickCount, j); -+ serverLevel.tickTimes10s.add(this.tickCount, j); -+ serverLevel.tickTimes60s.add(this.tickCount, j); -+ // SparklyPaper end - } catch (Throwable var7) { - CrashReport crashReport = CrashReport.forThrowable(var7, "Exception ticking world"); - serverLevel.fillReportDetails(crashReport); diff --git a/sparklypaper-server/paper-patches/files/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java.patch b/sparklypaper-server/paper-patches/files/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java.patch deleted file mode 100644 index 0a27de8..0000000 --- a/sparklypaper-server/paper-patches/files/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java.patch +++ /dev/null @@ -1,60 +0,0 @@ ---- a/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java -+++ b/src/main/java/io/papermc/paper/threadedregions/EntityScheduler.java -@@ -36,6 +_,7 @@ - * The Entity. Note that it is the CraftEntity, since only that class properly tracks world transfers. - */ - public final CraftEntity entity; -+ public final net.minecraft.server.MinecraftServer server; // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run - - private static final record ScheduledTask(Consumer run, Consumer retired) {} - -@@ -46,7 +_,8 @@ - - private final ArrayDeque currentlyExecuting = new ArrayDeque<>(); - -- public EntityScheduler(final CraftEntity entity) { -+ public EntityScheduler(final net.minecraft.server.MinecraftServer server, final CraftEntity entity) { // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run -+ this.server = Validate.notNull(server); - this.entity = Validate.notNull(entity); - } - -@@ -61,14 +_,16 @@ - * @throws IllegalStateException If the scheduler is already retired. - */ - public void retire() { -+ final Entity thisEntity = this.entity.getHandleRaw(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run - synchronized (this.stateLock) { - if (this.tickCount == RETIRED_TICK_COUNT) { - throw new IllegalStateException("Already retired"); - } - this.tickCount = RETIRED_TICK_COUNT; -+ this.server.entitiesWithScheduledTasks.remove(thisEntity); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run - } - -- final Entity thisEntity = this.entity.getHandleRaw(); -+ // final Entity thisEntity = this.entity.getHandleRaw(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (moved up) - - // correctly handle and order retiring while running executeTick - for (int i = 0, len = this.currentlyExecuting.size(); i < len; ++i) { -@@ -124,6 +_,7 @@ - if (this.tickCount == RETIRED_TICK_COUNT) { - return false; - } -+ this.server.entitiesWithScheduledTasks.add(this.entity.getHandleRaw()); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run - this.oneTimeDelayed.computeIfAbsent(this.tickCount + Math.max(1L, delay), (final long keyInMap) -> { - return new ArrayList<>(); - }).add(task); -@@ -143,6 +_,13 @@ - TickThread.ensureTickThread(thisEntity, "May not tick entity scheduler asynchronously"); - final List toRun; - synchronized (this.stateLock) { -+ // SparklyPaper start - skip EntityScheduler's executeTick checks if there isn't any tasks to be run -+ // Do we *really* have scheduled tasks tho? -+ if (this.currentlyExecuting.isEmpty() && this.oneTimeDelayed.isEmpty()) { // Check if we have any pending tasks and, if not, skip! -+ this.server.entitiesWithScheduledTasks.remove(thisEntity); // We don't! Bye bye!! -+ return; -+ } -+ // SparklyPaper end - if (this.tickCount == RETIRED_TICK_COUNT) { - throw new IllegalStateException("Ticking retired scheduler"); - }