Eliminate usages of MinecraftServer#tickCount field

Mobs would use the evenness of server tick count plus id
to determine whether they eoilf tick only their running
goals or to tick the goal selector to find additional
goals. If the server had an even number of regions,
then every 50ms the server tick field would be incremented
by an even number and as a result would not change
the evenness of the mob goal check. This could put
some mobs in a state where they only ticked their
running goals, which would result in them
freezing.

Fixes https://github.com/PaperMC/Folia/issues/42
This commit is contained in:
Spottedleaf 2023-05-27 09:41:57 -07:00
parent be3c9e596e
commit df0065bd53
3 changed files with 124 additions and 39 deletions

View File

@ -11786,9 +11786,18 @@ index d2f0a0755317f5fa9a1ccf7db346aa77fd287d80..b07df826a3028c14b48b09dbaeccc907
// CraftBukkit start - SPIGOT-5477, MC-142590 // CraftBukkit start - SPIGOT-5477, MC-142590
} else if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerGamePacketListenerImpl && ((ServerGamePacketListenerImpl) listener).processedDisconnect)) { } else if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerGamePacketListenerImpl && ((ServerGamePacketListenerImpl) listener).processedDisconnect)) {
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e823cfe56e0 100644 index 3219482b96cab8262e393a790c88d903d7de5166..3478d9c1db9acf19165df7308b6ae4461fa8fef7 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -242,7 +242,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private volatile boolean running;
private volatile boolean isRestarting = false; // Paper - flag to signify we're attempting to restart
private boolean stopped;
- private int tickCount;
+ // Folia - region threading
protected final Proxy proxy;
private boolean onlineMode;
private boolean preventProxyConnections;
@@ -295,7 +295,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -295,7 +295,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public org.bukkit.command.ConsoleCommandSender console; public org.bukkit.command.ConsoleCommandSender console;
public org.bukkit.command.RemoteConsoleCommandSender remoteConsole; public org.bukkit.command.RemoteConsoleCommandSender remoteConsole;
@ -11995,7 +12004,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
if (waitForShutdown) { if (waitForShutdown) {
try { try {
this.serverThread.join(); this.serverThread.join();
@@ -1109,6 +1196,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1109,10 +1196,23 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus(); this.status = this.buildServerStatus();
@ -12015,6 +12024,11 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
// Spigot start // Spigot start
// Paper start - move done tracking // Paper start - move done tracking
LOGGER.info("Running delayed init tasks"); LOGGER.info("Running delayed init tasks");
- this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // run all 1 tick delay tasks during init,
+ //this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // run all 1 tick delay tasks during init, // Folia - region threading
// this is going to be the first thing the tick process does anyways, so move done and run it after
// everything is init before watchdog tick.
// anything at 3+ won't be caught here but also will trip watchdog....
@@ -1144,8 +1244,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1144,8 +1244,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.lastOverloadWarning = this.nextTickTime; this.lastOverloadWarning = this.nextTickTime;
} }
@ -12026,6 +12040,15 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
{ {
final long diff = curTime - tickSection; final long diff = curTime - tickSection;
java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP); java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
@@ -1163,7 +1263,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (this.debugCommandProfilerDelayStart) {
this.debugCommandProfilerDelayStart = false;
- this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
+ //this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount); // Folia - region threading
}
//MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
@@ -1171,7 +1271,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1171,7 +1271,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.nextTickTime += 50L; this.nextTickTime += 50L;
this.startMetricsRecordingTick(); this.startMetricsRecordingTick();
@ -12035,7 +12058,24 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
this.profiler.popPush("nextTickWait"); this.profiler.popPush("nextTickWait");
this.mayHaveDelayedTasks = true; this.mayHaveDelayedTasks = true;
this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + 50L, this.nextTickTime); this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + 50L, this.nextTickTime);
@@ -1309,6 +1409,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1294,21 +1394,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override
public TickTask wrapRunnable(Runnable runnable) {
- // Paper start - anything that does try to post to main during watchdog crash, run on watchdog
- if (this.hasStopped && Thread.currentThread().equals(shutdownThread)) {
- runnable.run();
- runnable = () -> {};
- }
- // Paper end
- return new TickTask(this.tickCount, runnable);
+ throw new UnsupportedOperationException(); // Folia - region threading
}
protected boolean shouldRun(TickTask ticktask) {
- return ticktask.getTick() + 3 < this.tickCount || this.haveTime();
+ throw new UnsupportedOperationException(); // Folia - region threading
}
@Override @Override
public boolean pollTask() { public boolean pollTask() {
@ -12043,7 +12083,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
boolean flag = this.pollTaskInternal(); boolean flag = this.pollTaskInternal();
this.mayHaveDelayedTasks = flag; this.mayHaveDelayedTasks = flag;
@@ -1316,6 +1417,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1316,6 +1411,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
private boolean pollTaskInternal() { private boolean pollTaskInternal() {
@ -12051,7 +12091,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
if (super.pollTask()) { if (super.pollTask()) {
this.executeMidTickTasks(); // Paper - execute chunk tasks mid tick this.executeMidTickTasks(); // Paper - execute chunk tasks mid tick
return true; return true;
@@ -1338,6 +1440,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1338,6 +1434,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error
@ -12059,7 +12099,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
this.getProfiler().incrementCounter("runTask"); this.getProfiler().incrementCounter("runTask");
super.doRunTask(ticktask); super.doRunTask(ticktask);
} }
@@ -1380,22 +1483,64 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1380,22 +1477,64 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public void onServerExit() {} public void onServerExit() {}
@ -12121,15 +12161,23 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
+ } + }
+ // Folia end - region threading + // Folia end - region threading
++this.tickCount; - ++this.tickCount;
- this.tickChildren(shouldKeepTicking); - this.tickChildren(shouldKeepTicking);
- if (i - this.lastServerStatus >= 5000000000L) { - if (i - this.lastServerStatus >= 5000000000L) {
+ // Folia - region threading
+ this.tickChildren(shouldKeepTicking, region); // Folia - region threading + this.tickChildren(shouldKeepTicking, region); // Folia - region threading
+ if (region == null && i - this.lastServerStatus >= 5000000000L) { // Folia - region threading - moved to global tick + if (region == null && i - this.lastServerStatus >= 5000000000L) { // Folia - region threading - moved to global tick
this.lastServerStatus = i; this.lastServerStatus = i;
this.status = this.buildServerStatus(); this.status = this.buildServerStatus();
} }
@@ -1412,9 +1557,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1406,15 +1545,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
playerSaveInterval = autosavePeriod;
}
this.profiler.push("save");
- final boolean fullSave = autosavePeriod > 0 && this.tickCount % autosavePeriod == 0;
+ final boolean fullSave = autosavePeriod > 0 && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % autosavePeriod == 0; // Folia - region threading
try {
this.isSaving = true;
if (playerSaveInterval > 0) { if (playerSaveInterval > 0) {
this.playerList.saveAll(playerSaveInterval); this.playerList.saveAll(playerSaveInterval);
} }
@ -12141,7 +12189,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
} }
} }
} finally { } finally {
@@ -1424,16 +1569,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1424,32 +1563,28 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end // Paper end
io.papermc.paper.util.CachedLists.reset(); // Paper io.papermc.paper.util.CachedLists.reset(); // Paper
// Paper start - move executeAll() into full server tick timing // Paper start - move executeAll() into full server tick timing
@ -12155,18 +12203,21 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
- long remaining = (TICK_TIME - (endTime - lastTick)) - catchupTime; - long remaining = (TICK_TIME - (endTime - lastTick)) - catchupTime;
- new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent(); - new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - lastTick) / 1000000D), remaining).callEvent();
+ long remaining = scheduledEnd - endTime; // Folia - region ticking + long remaining = scheduledEnd - endTime; // Folia - region ticking
+ new com.destroystokyo.paper.event.server.ServerTickEndEvent(this.tickCount, ((double)(endTime - startTime) / 1000000D), remaining).callEvent(); // Folia - region ticking + new com.destroystokyo.paper.event.server.ServerTickEndEvent((int)io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick(), ((double)(endTime - startTime) / 1000000D), remaining).callEvent(); // Folia - region ticking
// Paper end // Paper end
this.profiler.push("tallying"); this.profiler.push("tallying");
+ if (region == null) { // Folia - region threading - long j = this.tickTimes[this.tickCount % 100] = Util.getNanos() - i;
long j = this.tickTimes[this.tickCount % 100] = Util.getNanos() - i; -
- this.averageTickTime = this.averageTickTime * 0.8F + (float) j / 1000000.0F * 0.19999999F;
this.averageTickTime = this.averageTickTime * 0.8F + (float) j / 1000000.0F * 0.19999999F; - long k = Util.getNanos();
@@ -1445,11 +1591,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa -
tickTimes60s.add(this.tickCount, j); - // Paper start
// Paper end - tickTimes5s.add(this.tickCount, j);
this.frameTimer.logFrameDuration(k - i); - tickTimes10s.add(this.tickCount, j);
+ } // Folia - region threading - tickTimes60s.add(this.tickCount, j);
- // Paper end
- this.frameTimer.logFrameDuration(k - i);
+ // Folia - region threading
this.profiler.pop(); this.profiler.pop();
org.spigotmc.WatchdogThread.tick(); // Spigot org.spigotmc.WatchdogThread.tick(); // Spigot
co.aikar.timings.TimingsManager.FULL_SERVER_TICK.stopTiming(); // Paper co.aikar.timings.TimingsManager.FULL_SERVER_TICK.stopTiming(); // Paper
@ -12181,7 +12232,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
private ServerStatus buildServerStatus() { private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus(); ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
@@ -1457,7 +1610,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1457,7 +1592,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
private ServerStatus.Players buildPlayerStatus() { private ServerStatus.Players buildPlayerStatus() {
@ -12190,7 +12241,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
int i = this.getMaxPlayers(); int i = this.getMaxPlayers();
if (this.hidesOnlinePlayers()) { if (this.hidesOnlinePlayers()) {
@@ -1478,14 +1631,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1478,14 +1613,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
} }
@ -12198,10 +12249,10 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
+ public void tickChildren(BooleanSupplier shouldKeepTicking, io.papermc.paper.threadedregions.TickRegions.TickRegionData region) { // Folia - region threading + public void tickChildren(BooleanSupplier shouldKeepTicking, io.papermc.paper.threadedregions.TickRegions.TickRegionData region) { // Folia - region threading
MinecraftTimings.bukkitSchedulerTimer.startTiming(); // Spigot // Paper MinecraftTimings.bukkitSchedulerTimer.startTiming(); // Spigot // Paper
- this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit - this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
+ if (region == null) this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit // Folia - region threading - TODO REPLACE CRAFT SCHEDULER + // Folia - region threading
MinecraftTimings.bukkitSchedulerTimer.stopTiming(); // Spigot // Paper MinecraftTimings.bukkitSchedulerTimer.stopTiming(); // Spigot // Paper
- io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper - io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
+ if (region == null) io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper + // Folia - region threading - moved to global tick
this.profiler.push("commandFunctions"); this.profiler.push("commandFunctions");
MinecraftTimings.commandFunctionsTimer.startTiming(); // Spigot // Paper MinecraftTimings.commandFunctionsTimer.startTiming(); // Spigot // Paper
- this.getFunctions().tick(); - this.getFunctions().tick();
@ -12209,7 +12260,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
MinecraftTimings.commandFunctionsTimer.stopTiming(); // Spigot // Paper MinecraftTimings.commandFunctionsTimer.stopTiming(); // Spigot // Paper
this.profiler.popPush("levels"); this.profiler.popPush("levels");
//Iterator iterator = this.getAllLevels().iterator(); // Paper - moved down //Iterator iterator = this.getAllLevels().iterator(); // Paper - moved down
@@ -1493,7 +1646,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1493,7 +1628,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit start // CraftBukkit start
// Run tasks that are waiting on processing // Run tasks that are waiting on processing
MinecraftTimings.processQueueTimer.startTiming(); // Spigot MinecraftTimings.processQueueTimer.startTiming(); // Spigot
@ -12218,7 +12269,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
this.processQueue.remove().run(); this.processQueue.remove().run();
} }
MinecraftTimings.processQueueTimer.stopTiming(); // Spigot MinecraftTimings.processQueueTimer.stopTiming(); // Spigot
@@ -1501,13 +1654,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1501,13 +1636,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
// Send time updates to everyone, it will get the right time from the world the player is in. // Send time updates to everyone, it will get the right time from the world the player is in.
// Paper start - optimize time updates // Paper start - optimize time updates
@ -12231,11 +12282,11 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
- for (Player entityhuman : world.players()) { - for (Player entityhuman : world.players()) {
- if (!(entityhuman instanceof ServerPlayer) || (tickCount + entityhuman.getId()) % 20 != 0) { - if (!(entityhuman instanceof ServerPlayer) || (tickCount + entityhuman.getId()) % 20 != 0) {
+ for (Player entityhuman : world.getLocalPlayers()) { // Folia - region threading + for (Player entityhuman : world.getLocalPlayers()) { // Folia - region threading
+ if (!(entityhuman instanceof ServerPlayer) || ((region == null ? tickCount : region.getCurrentTick()) + entityhuman.getId()) % 20 != 0) { // Folia - region threading + if (!(entityhuman instanceof ServerPlayer) || (io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() + entityhuman.getId()) % 20 != 0) { // Folia - region threading
continue; continue;
} }
ServerPlayer entityplayer = (ServerPlayer) entityhuman; ServerPlayer entityplayer = (ServerPlayer) entityhuman;
@@ -1520,13 +1673,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1520,13 +1655,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end // Paper end
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
@ -12252,7 +12303,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
this.profiler.push(() -> { this.profiler.push(() -> {
return worldserver + " " + worldserver.dimension().location(); return worldserver + " " + worldserver.dimension().location();
@@ -1543,7 +1694,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1543,7 +1676,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
try { try {
worldserver.timings.doTick.startTiming(); // Spigot worldserver.timings.doTick.startTiming(); // Spigot
@ -12261,7 +12312,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
// Paper start // Paper start
for (final io.papermc.paper.chunk.SingleThreadChunkRegionManager regionManager : worldserver.getChunkSource().chunkMap.regionManagers) { for (final io.papermc.paper.chunk.SingleThreadChunkRegionManager regionManager : worldserver.getChunkSource().chunkMap.regionManagers) {
regionManager.recalculateRegions(); regionManager.recalculateRegions();
@@ -1567,17 +1718,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1567,17 +1700,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.profiler.pop(); this.profiler.pop();
this.profiler.pop(); this.profiler.pop();
@ -12283,7 +12334,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
MinecraftTimings.playerListTimer.stopTiming(); // Spigot // Paper MinecraftTimings.playerListTimer.stopTiming(); // Spigot // Paper
if (SharedConstants.IS_RUNNING_IN_IDE) { if (SharedConstants.IS_RUNNING_IN_IDE) {
GameTestTicker.SINGLETON.tick(); GameTestTicker.SINGLETON.tick();
@@ -1586,7 +1737,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1586,7 +1719,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.profiler.popPush("server gui refresh"); this.profiler.popPush("server gui refresh");
MinecraftTimings.tickablesTimer.startTiming(); // Spigot // Paper MinecraftTimings.tickablesTimer.startTiming(); // Spigot // Paper
@ -12292,7 +12343,16 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
((Runnable) this.tickables.get(i)).run(); ((Runnable) this.tickables.get(i)).run();
} }
MinecraftTimings.tickablesTimer.stopTiming(); // Spigot // Paper MinecraftTimings.tickablesTimer.stopTiming(); // Spigot // Paper
@@ -1977,6 +2128,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1924,7 +2057,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public int getTickCount() {
- return this.tickCount;
+ throw new UnsupportedOperationException(); // Folia - region threading
}
public int getSpawnProtectionRadius() {
@@ -1977,6 +2110,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
public void invalidateStatus() { public void invalidateStatus() {
@ -12308,7 +12368,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
this.lastServerStatus = 0L; this.lastServerStatus = 0L;
} }
@@ -1991,6 +2151,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -1991,6 +2133,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@Override @Override
public void executeIfPossible(Runnable runnable) { public void executeIfPossible(Runnable runnable) {
@ -12316,7 +12376,23 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
if (this.isStopped()) { if (this.isStopped()) {
throw new RejectedExecutionException("Server already shutting down"); throw new RejectedExecutionException("Server already shutting down");
} else { } else {
@@ -2740,33 +2901,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -2606,14 +2749,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public ProfileResults stopTimeProfiler() {
- if (this.debugCommandProfiler == null) {
- return EmptyProfileResults.EMPTY;
- } else {
- ProfileResults methodprofilerresults = this.debugCommandProfiler.stop(Util.getNanos(), this.tickCount);
-
- this.debugCommandProfiler = null;
- return methodprofilerresults;
- }
+ throw new UnsupportedOperationException(); // Folia - region threading
}
public int getMaxChainedNeighborUpdates() {
@@ -2740,33 +2876,18 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
static final long TASK_EXECUTION_FAILURE_BACKOFF = 5L * 1000L; // 5us static final long TASK_EXECUTION_FAILURE_BACKOFF = 5L * 1000L; // 5us
@ -12356,7 +12432,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
// it's shown to be bad to constantly hit the queue (chunk loads slow to a crawl), even if no tasks are executed. // it's shown to be bad to constantly hit the queue (chunk loads slow to a crawl), even if no tasks are executed.
// so, backoff to prevent this // so, backoff to prevent this
return; return;
@@ -2775,13 +2921,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -2775,13 +2896,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
co.aikar.timings.MinecraftTimings.midTickChunkTasks.startTiming(); co.aikar.timings.MinecraftTimings.midTickChunkTasks.startTiming();
try { try {
for (;;) { for (;;) {
@ -12372,7 +12448,7 @@ index 3219482b96cab8262e393a790c88d903d7de5166..f5977082a31d44088ab5ba31fad88e82
} }
// note: negative values reduce the time // note: negative values reduce the time
@@ -2794,7 +2940,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -2794,7 +2915,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
double overuseCount = (double)overuse/(double)MAX_CHUNK_EXEC_TIME; double overuseCount = (double)overuse/(double)MAX_CHUNK_EXEC_TIME;
long extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME); long extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
@ -19109,7 +19185,7 @@ index dcfb71b5a53df789e366fea2080921d677549a2e..4f8062432cfe6480664e674fde0255f0
while (!flag2 && blockposition.getY() > world.getMinBuildHeight()) { while (!flag2 && blockposition.getY() > world.getMinBuildHeight()) {
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 02cb6b8c1d59855ff4a8aad3024fe12007eca0ee..a719dc69b48ae867ce0b508d3d640e65d2863068 100644 index 02cb6b8c1d59855ff4a8aad3024fe12007eca0ee..8ea463720fde25954c208d1e91571f1494d24aea 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java --- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -135,6 +135,14 @@ public abstract class Mob extends LivingEntity implements Targeting { @@ -135,6 +135,14 @@ public abstract class Mob extends LivingEntity implements Targeting {
@ -19172,6 +19248,15 @@ index 02cb6b8c1d59855ff4a8aad3024fe12007eca0ee..a719dc69b48ae867ce0b508d3d640e65
if (entityhuman != null) { if (entityhuman != null) {
double d0 = entityhuman.distanceToSqr((Entity) this); double d0 = entityhuman.distanceToSqr((Entity) this);
@@ -903,7 +918,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
this.level.getProfiler().push("sensing");
this.sensing.tick();
this.level.getProfiler().pop();
- int i = this.level.getServer().getTickCount() + this.getId();
+ int i = this.tickCount + this.getId(); // Folia - region threading
if (i % 2 != 0 && this.tickCount > 1) {
this.level.getProfiler().push("targetSelector");
@@ -1728,6 +1743,15 @@ public abstract class Mob extends LivingEntity implements Targeting { @@ -1728,6 +1743,15 @@ public abstract class Mob extends LivingEntity implements Targeting {
this.goalSelector.removeAllGoals(predicate); this.goalSelector.removeAllGoals(predicate);
} }

View File

@ -10,10 +10,10 @@ the impact from scaling the region threads, but is not a fix
to the underlying issue. to the underlying issue.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index f5977082a31d44088ab5ba31fad88e823cfe56e0..f5721f6d719b7055fdccc81d5e67ed758e90cb10 100644 index 3478d9c1db9acf19165df7308b6ae4461fa8fef7..61bac6fda2d2f4b3db8a3f7e3003f47c84d5c4cd 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2909,6 +2909,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -2884,6 +2884,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
} }
public final void executeMidTickTasks() { public final void executeMidTickTasks() {

View File

@ -9,7 +9,7 @@ raid before it's completion, it would throw an exception due to not being on the
same region thread anymore. same region thread anymore.
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
index 359f1690497eac00899eb26c17308e0a6fe943ad..66af0e067abdcea8b4116c23c6adb45aeeec0273 100644 index 359f1690497eac00899eb26c17308e0a6fe943ad..2289de057dd3c09cbe76f114e4bcc78b737bb6a3 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java --- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java +++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
@@ -407,12 +407,25 @@ public class Raid { @@ -407,12 +407,25 @@ public class Raid {