168 lines
9.2 KiB
Diff
168 lines
9.2 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 1382c695c4991488b113401e231875ddc74f6b01..68280b07a71dcdb42eaee6f62fbda074813a22e4 100644
|
|
--- a/io/papermc/paper/threadedregions/RegionizedServer.java
|
|
+++ b/io/papermc/paper/threadedregions/RegionizedServer.java
|
|
@@ -286,6 +286,11 @@ public final class RegionizedServer {
|
|
this.randomWalk();
|
|
*/
|
|
++this.tickCount;
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled) {
|
|
+ MinecraftServer.tickRateManager.tick();
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
// expire invalid click command callbacks
|
|
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue((int)this.tickCount);
|
|
|
|
@@ -308,6 +313,13 @@ public final class RegionizedServer {
|
|
this.globalTick(world, tickCount);
|
|
}
|
|
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled) {
|
|
+ MinecraftServer.tickRateManager.reduceSprintTicks();
|
|
+ MinecraftServer.tickRateManager.endTickWork();
|
|
+ }
|
|
+ // Luminol end - Add a config to enable tick command
|
|
+
|
|
// tick connections
|
|
this.tickConnections();
|
|
|
|
@@ -441,7 +453,7 @@ public final class RegionizedServer {
|
|
}
|
|
|
|
private void tickTime(final ServerLevel world, final int tickCount) {
|
|
- if (world.tickTime) {
|
|
+ if ((!me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled || 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 7123b3eb2f2e52946b8ef9de993a6828eb0bb6f7..82948984404a183711588932a4a026dc4c241feb 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();
|
|
@@ -375,8 +375,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 (me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled) {
|
|
+ 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()) {
|
|
@@ -416,6 +431,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 (me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled) {
|
|
+ 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 009e6405a11a391adca41a7c4ecafbf3254d799d..779dfa95d91ec4661227c94b012cb63953d4ba96 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -211,7 +211,11 @@ public class Commands {
|
|
//TeamMsgCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
TeleportCommand.register(this.dispatcher);
|
|
TellRawCommand.register(this.dispatcher, context);
|
|
- //TickCommand.register(this.dispatcher); // Folia - region threading - TODO later
|
|
+ // Luminol start - Add a config to enable tick command
|
|
+ if (me.earthme.luminol.config.modules.experiment.CommandTickConfig.enabled) {
|
|
+ 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 46375fa81b36b89b79c22f0a7ac6d610ab1183d4..2f0a1810e3ab4ff4376e893af7ceb2bf5849ba76 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 6b6c8ce49eda6806c8288d70848dd143ba2c4703..5d09d2c8bb45cc10b2a13100793249adc7b5a7e9 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) {
|