168 lines
9.3 KiB
Diff
168 lines
9.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Thu, 1 May 2025 22:43:08 +0800
|
|
Subject: [PATCH] Add config to enable tick command
|
|
|
|
|
|
diff --git a/io/papermc/paper/threadedregions/RegionizedServer.java b/io/papermc/paper/threadedregions/RegionizedServer.java
|
|
index e1842ab8f20271a8b20ab8462b09a4745a612a9a..8405157ec35a443e238fa6866772c839621d73d7 100644
|
|
--- a/io/papermc/paper/threadedregions/RegionizedServer.java
|
|
+++ b/io/papermc/paper/threadedregions/RegionizedServer.java
|
|
@@ -299,6 +299,11 @@ public final class RegionizedServer {
|
|
this.randomWalk();
|
|
*/
|
|
++this.tickCount;
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.tick) {
|
|
+ MinecraftServer.tickRateManager.tick();
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
// expire invalid click command callbacks
|
|
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.ADVENTURE_CLICK_MANAGER.handleQueue((int)this.tickCount); // Paper // Folia - region threading - moved to global tick
|
|
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue((int)this.tickCount); // Paper // Folia - region threading - moved to global tick
|
|
@@ -322,6 +327,13 @@ public final class RegionizedServer {
|
|
this.globalTick(world, tickCount);
|
|
}
|
|
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.tick) {
|
|
+ MinecraftServer.tickRateManager.reduceSprintTicks();
|
|
+ MinecraftServer.tickRateManager.endTickWork();
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
+
|
|
// tick connections
|
|
this.tickConnections();
|
|
|
|
@@ -455,7 +467,7 @@ public final class RegionizedServer {
|
|
}
|
|
|
|
private void tickTime(final ServerLevel world, final int tickCount) {
|
|
- if (world.tickTime) {
|
|
+ if ((!fun.bm.lophine.config.modules.experiment.CommandConfig.tick || world.tickRateManager().runsNormally()) && world.tickTime) { // Luminol - Add a config to enable tick command
|
|
if (world.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)) {
|
|
world.setDayTime(world.levelData.getDayTime() + (long)tickCount);
|
|
}
|
|
diff --git a/io/papermc/paper/threadedregions/TickRegionScheduler.java b/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
|
index c485d5b3ba95f2a969bdf0dab9654ac284976f8d..b957585cf7cf7f845e20f59c7b355722880f3b4e 100644
|
|
--- a/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
|
+++ b/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
|
@@ -31,8 +31,8 @@ public final class TickRegionScheduler {
|
|
}
|
|
}
|
|
|
|
- public static final int TICK_RATE = 20;
|
|
- public static final long TIME_BETWEEN_TICKS = 1_000_000_000L / TICK_RATE; // ns
|
|
+ public static float TICK_RATE = 20; // Luminol - Add tick command support
|
|
+ public static long TIME_BETWEEN_TICKS = (long) (1_000_000_000L / TICK_RATE); // ns // Luminol - Add tick command support
|
|
|
|
// Folia start - watchdog
|
|
public static final FoliaWatchdogThread WATCHDOG_THREAD = new FoliaWatchdogThread();
|
|
@@ -394,8 +394,23 @@ public final class TickRegionScheduler {
|
|
final long cpuStart = MEASURE_CPU_TIME ? THREAD_MX_BEAN.getCurrentThreadCpuTime() : 0L;
|
|
final long tickStart = System.nanoTime();
|
|
|
|
- // use max(), don't assume that tickStart >= scheduledStart
|
|
- final int tickCount = Math.max(1, this.tickSchedule.getPeriodsAhead(TIME_BETWEEN_TICKS, tickStart));
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ final int tickCount;
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.tick) {
|
|
+ if (MinecraftServer.tickRateManager.isSprinting() && MinecraftServer.tickRateManager.checkShouldSprintThisTick()) {
|
|
+ TICK_RATE = net.minecraft.server.commands.TickCommand.MAX_TICKRATE;
|
|
+ TIME_BETWEEN_TICKS = (long) (1_000_000_000L / TICK_RATE);
|
|
+ tickCount = 1;
|
|
+ } else {
|
|
+ TICK_RATE = MinecraftServer.tickRateManager.tickrate();
|
|
+ TIME_BETWEEN_TICKS = (long) (1_000_000_000L / TICK_RATE);
|
|
+ tickCount = Math.max(1, this.tickSchedule.getPeriodsAhead(TIME_BETWEEN_TICKS, tickStart));
|
|
+ }
|
|
+ } else {
|
|
+ // use max(), don't assume that tickStart >= scheduledStart
|
|
+ tickCount = Math.max(1, this.tickSchedule.getPeriodsAhead(TIME_BETWEEN_TICKS, tickStart));
|
|
+ }
|
|
+ // Luminol end - Add tick command support
|
|
|
|
if (!this.tryMarkTicking()) {
|
|
if (!this.cancelled.get()) {
|
|
@@ -435,6 +450,11 @@ public final class TickRegionScheduler {
|
|
try {
|
|
// next start isn't updated until the end of this tick
|
|
this.tickRegion(tickCount, tickStart, scheduledEnd);
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.tick) {
|
|
+ MinecraftServer.tickRateManager.endTickWork();
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
} catch (final Throwable thr) {
|
|
this.scheduler.regionFailed(this, false, thr);
|
|
// regionFailed will schedule a shutdown, so we should avoid letting this region tick further
|
|
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
|
|
index e0e9fcf3224f55f2ef31c8afca3154a5992f761b..a5b59eb79c014ef7a48ff305ed554fc33a184d87 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -247,7 +247,11 @@ public class Commands {
|
|
TeleportCommand.register(this.dispatcher);
|
|
TellRawCommand.register(this.dispatcher, context);
|
|
//TestCommand.register(this.dispatcher, context); // Folia - region threading
|
|
- //TickCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (fun.bm.lophine.config.modules.experiment.CommandConfig.tick) {
|
|
+ TickCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
TimeCommand.register(this.dispatcher);
|
|
TitleCommand.register(this.dispatcher, context);
|
|
//TriggerCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index b4b3ff86f7c4afb94fc4da5133746391a078a7fb..b156b5c635f931a3d4abc0584591f90476d011a6 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -267,7 +267,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
private String serverId;
|
|
public MinecraftServer.ReloadableResources resources;
|
|
private final StructureTemplateManager structureTemplateManager;
|
|
- private final ServerTickRateManager tickRateManager;
|
|
+ public static ServerTickRateManager tickRateManager; // Luminol - Add tick command support
|
|
protected WorldData worldData;
|
|
public PotionBrewing potionBrewing;
|
|
private FuelValues fuelValues;
|
|
diff --git a/net/minecraft/server/ServerTickRateManager.java b/net/minecraft/server/ServerTickRateManager.java
|
|
index 40338efd1c0e56d869d03f1d0687e7ff0fcbf11a..d0d90a25a10bbecfffceee1992af88c60d14fd87 100644
|
|
--- a/net/minecraft/server/ServerTickRateManager.java
|
|
+++ b/net/minecraft/server/ServerTickRateManager.java
|
|
@@ -105,7 +105,7 @@ public class ServerTickRateManager extends TickRateManager {
|
|
return false;
|
|
} else if (this.remainingSprintTicks > 0L) {
|
|
this.sprintTickStartTime = System.nanoTime();
|
|
- this.remainingSprintTicks--;
|
|
+ // this.remainingSprintTicks--; // Luminol - Add tick command support
|
|
return true;
|
|
} else {
|
|
this.finishTickSprint();
|
|
@@ -113,6 +113,12 @@ public class ServerTickRateManager extends TickRateManager {
|
|
}
|
|
}
|
|
|
|
+ // Luminol start - Add tick command support
|
|
+ public void reduceSprintTicks() {
|
|
+ this.remainingSprintTicks--;
|
|
+ }
|
|
+ // Luminol end - Add tick command support
|
|
+
|
|
public void endTickWork() {
|
|
this.sprintTimeSpend = this.sprintTimeSpend + (System.nanoTime() - this.sprintTickStartTime);
|
|
}
|
|
diff --git a/net/minecraft/server/commands/TickCommand.java b/net/minecraft/server/commands/TickCommand.java
|
|
index 126685fb266692082b432ed297a499149e921dfb..9d8f6025c420e651611da17e77a362c738228b72 100644
|
|
--- a/net/minecraft/server/commands/TickCommand.java
|
|
+++ b/net/minecraft/server/commands/TickCommand.java
|
|
@@ -14,7 +14,7 @@ import net.minecraft.server.ServerTickRateManager;
|
|
import net.minecraft.util.TimeUtil;
|
|
|
|
public class TickCommand {
|
|
- private static final float MAX_TICKRATE = 10000.0F;
|
|
+ public static final float MAX_TICKRATE = 10000.0F; // Luminol - Add tick command support
|
|
private static final String DEFAULT_TICKRATE = String.valueOf(20);
|
|
|
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|