moar client-server tick speed separation
This commit is contained in:
1 parent
e0a3060339
commit
df786605c2
23 files changed
+166
-148
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
minecraft_version=1.20-pre1
|
||||
loader_version=0.14.19
|
||||
jsr305_version=3.0.2
|
||||
fabric_version=0.80.2+1.20
|
||||
fabric_version=0.81.1+1.20
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.4.108
|
||||
|
||||
@@ -14,6 +14,8 @@ import carpet.commands.MobAICommand;
|
||||
import carpet.commands.PerimeterInfoCommand;
|
||||
import carpet.commands.PlayerCommand;
|
||||
import carpet.commands.ProfileCommand;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.script.ScriptCommand;
|
||||
import carpet.commands.SpawnCommand;
|
||||
import carpet.commands.TestCommand;
|
||||
@@ -127,7 +129,8 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
|
||||
public static void tick(MinecraftServer server)
|
||||
{
|
||||
TickSpeed.tick();
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
trm.tick();
|
||||
HUDController.update_hud(server, null);
|
||||
if (scriptServer != null) scriptServer.tick();
|
||||
|
||||
@@ -228,7 +231,7 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
}
|
||||
|
||||
// this for whatever reason gets called multiple times even when joining;
|
||||
TickSpeed.reset();
|
||||
TickSpeed.resetClient();
|
||||
}
|
||||
public static void onServerDoneClosing(MinecraftServer server)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.SpawnGroupInterface;
|
||||
import carpet.helpers.HopperCounter;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CommandHelper;
|
||||
import carpet.utils.Messenger;
|
||||
import carpet.utils.SpawnReporter;
|
||||
@@ -198,7 +199,8 @@ public class SpawnCommand
|
||||
|
||||
|
||||
// tick warp 0
|
||||
TickSpeed.tickrate_advance(null, 0, null, null);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.tickrate_advance(null, 0, null, null);
|
||||
// tick warp given player
|
||||
CommandSourceStack csource = null;
|
||||
ServerPlayer player = null;
|
||||
@@ -210,7 +212,7 @@ public class SpawnCommand
|
||||
catch (CommandSyntaxException ignored)
|
||||
{
|
||||
}
|
||||
TickSpeed.tickrate_advance(player, ticks, null, csource);
|
||||
trm.tickrate_advance(player, ticks, null, csource);
|
||||
Messenger.m(source, String.format("gi Started spawn test for %d ticks", ticks));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import carpet.utils.CommandHelper;
|
||||
@@ -72,30 +73,35 @@ public class TickCommand
|
||||
|
||||
private static int setTps(CommandSourceStack source, float tps)
|
||||
{
|
||||
TickSpeed.tickrate(tps, true);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.tickrate(tps, true);
|
||||
queryTps(source);
|
||||
return (int)tps;
|
||||
}
|
||||
|
||||
private static int queryTps(CommandSourceStack source)
|
||||
{
|
||||
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f)));
|
||||
return (int)(float)TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
|
||||
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", trm.tickrate));
|
||||
return (int) trm.tickrate;
|
||||
}
|
||||
|
||||
private static int setWarp(CommandSourceStack source, int advance, String tail_command)
|
||||
{
|
||||
ServerPlayer player = source.getPlayer(); // may be null
|
||||
Component message = TickSpeed.tickrate_advance(player, advance, tail_command, source);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
Component message = trm.tickrate_advance(player, advance, tail_command, source);
|
||||
source.sendSuccess(message, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int freezeStatus(CommandSourceStack source)
|
||||
{
|
||||
if(TickSpeed.isPaused())
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
if(trm.isPaused())
|
||||
{
|
||||
Messenger.m(source, "gi Freeze Status: Game is "+(TickSpeed.deeplyFrozen()?"deeply ":"")+"frozen");
|
||||
Messenger.m(source, "gi Freeze Status: Game is "+(trm.deeplyFrozen()?"deeply ":"")+"frozen");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,8 +112,9 @@ public class TickCommand
|
||||
|
||||
private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean freeze)
|
||||
{
|
||||
TickSpeed.setFrozenState(freeze, isDeep);
|
||||
if (TickSpeed.isPaused())
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.setFrozenState(freeze, isDeep);
|
||||
if (trm.isPaused())
|
||||
{
|
||||
Messenger.m(source, "gi Game is "+(isDeep?"deeply ":"")+"frozen");
|
||||
}
|
||||
@@ -120,21 +127,24 @@ public class TickCommand
|
||||
|
||||
private static int toggleFreeze(CommandSourceStack source, boolean isDeep)
|
||||
{
|
||||
return setFreeze(source, isDeep, !TickSpeed.isPaused());
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
return setFreeze(source, isDeep, !trm.isPaused());
|
||||
}
|
||||
|
||||
private static int step(CommandSourceStack source, int advance)
|
||||
{
|
||||
TickSpeed.add_ticks_to_run_in_pause(advance);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.add_ticks_to_run_in_pause(advance);
|
||||
Messenger.m(source, "gi Stepping " + advance + " tick" + (advance != 1 ? "s" : ""));
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleSuperHot(CommandSourceStack source)
|
||||
{
|
||||
TickSpeed.gTRM().ifPresent(trm -> trm.is_superHot = !trm.is_superHot);
|
||||
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.is_superHot = !trm.is_superHot;
|
||||
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers(source.getServer());
|
||||
if (TickSpeed.gTRM().map(trm -> trm.is_superHot).orElse(false))
|
||||
if (trm.is_superHot)
|
||||
{
|
||||
Messenger.m(source, "gi Superhot enabled");
|
||||
}
|
||||
|
||||
@@ -47,6 +47,11 @@ public class TickRateManager
|
||||
return is_paused;
|
||||
}
|
||||
|
||||
public boolean process_entities()
|
||||
{
|
||||
return process_entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the game is deeply frozen.
|
||||
* This can be used for things that you may not normally want
|
||||
@@ -85,24 +90,6 @@ public class TickRateManager
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() // do we need reset?
|
||||
{
|
||||
tickrate = 20.0f;
|
||||
mspt = 50.0f;
|
||||
time_bias = 0;
|
||||
time_warp_start_time = 0;
|
||||
time_warp_scheduled_ticks = 0;
|
||||
time_advancerer = null;
|
||||
tick_warp_callback = null;
|
||||
tick_warp_sender = null;
|
||||
player_active_timeout = 0;
|
||||
process_entities = true;
|
||||
deepFreeze = false;
|
||||
is_paused = false;
|
||||
is_superHot = false;
|
||||
notifyTickrateListeners("carpet");
|
||||
}
|
||||
|
||||
public void add_ticks_to_run_in_pause(int ticks)
|
||||
{
|
||||
player_active_timeout = PLAYER_GRACE + ticks;
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.utils.Messenger;
|
||||
|
||||
public class TickSpeed
|
||||
{
|
||||
public static Optional<TickRateManager> gTRM() {
|
||||
private static Optional<TickRateManager> gTRM() {
|
||||
if (CarpetServer.minecraft_server == null) return Optional.empty();
|
||||
return Optional.of(((MinecraftServerInterface)CarpetServer.minecraft_server).getTickRateManager());
|
||||
}
|
||||
@@ -29,44 +25,18 @@ public class TickSpeed
|
||||
return gTRM().map(trm -> trm.mspt).orElse(50.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not the game is in a frozen state.
|
||||
* You should normally use {@link #process_entities()} instead,
|
||||
* since that one accounts for tick steps and superhot
|
||||
*/
|
||||
public static boolean isPaused() {
|
||||
return gTRM().map(TickRateManager::isPaused).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the game is deeply frozen.
|
||||
* This can be used for things that you may not normally want
|
||||
* to freeze, but may need to in some situations.
|
||||
* This should be checked with {@link #process_entities()} to make sure the
|
||||
* current tick is actually frozen, not only the game
|
||||
* @return Whether or not the game is deeply frozen.
|
||||
*/
|
||||
public static boolean deeplyFrozen() {
|
||||
return gTRM().map(TickRateManager::deeplyFrozen).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to update the frozen state of the game.
|
||||
* Handles connected clients as well.
|
||||
* @param isPaused Whether or not the game is paused
|
||||
* @param isDeepFreeze Whether or not the game is deeply frozen
|
||||
*/
|
||||
public static void setFrozenState(boolean isPaused, boolean isDeepFreeze) {
|
||||
gTRM().ifPresent(trm -> trm.setFrozenState(isPaused, isDeepFreeze));
|
||||
}
|
||||
|
||||
/**
|
||||
* Functional interface that listens for tickrate changes. This is
|
||||
* implemented to allow tickrate compatibility with other mods etc.
|
||||
*/
|
||||
private static final Map<String, BiConsumer<String, Float>> tickrateListeners = new HashMap<>();
|
||||
private static final float MIN_TICKRATE = 0.01f;
|
||||
|
||||
public static void reset_player_active_timeout()
|
||||
{
|
||||
gTRM().ifPresent(TickRateManager::reset_player_active_timeout);
|
||||
@@ -74,7 +44,7 @@ public class TickSpeed
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
gTRM().ifPresent(TickRateManager::reset);
|
||||
// noop - called on server to reset client
|
||||
}
|
||||
|
||||
public static void add_ticks_to_run_in_pause(int ticks)
|
||||
@@ -109,16 +79,12 @@ public class TickSpeed
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static BiConsumer<String, Float> addTickrateListener(String modId, BiConsumer<String, Float> tickrateListener)
|
||||
{
|
||||
return gTRM().map(trm -> trm.addTickrateListener(modId, tickrateListener)).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// client only
|
||||
|
||||
private static float tickrate = 20.0f;
|
||||
@@ -193,5 +159,16 @@ public class TickSpeed
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetClient()
|
||||
{
|
||||
tickrate = 20.0f;
|
||||
mspt = 50.0f;
|
||||
player_active_timeout = 0;
|
||||
process_entities = true;
|
||||
deepFreeze = false;
|
||||
is_paused = false;
|
||||
is_superHot = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class HUDController
|
||||
}
|
||||
double MSPT = Arrays.stream(server.tickTimes).average().getAsDouble() * 1.0E-6D;
|
||||
double TPS = 1000.0D / Math.max((trm.time_warp_start_time != 0)?0.0:trm.mspt, MSPT);
|
||||
if (TickSpeed.isPaused()) {
|
||||
if (trm.isPaused()) {
|
||||
TPS = 0;
|
||||
}
|
||||
String color = Messenger.heatmap_color(MSPT,trm.mspt);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
@@ -34,7 +37,15 @@ public class BoundTickingBlockEntity_tickMixin<T extends BlockEntity>
|
||||
))
|
||||
private void checkProcessBEs(BlockEntityTicker<T> blockEntityTicker, Level world, BlockPos pos, BlockState state, T blockEntity)
|
||||
{
|
||||
if (TickSpeed.process_entities()) blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||
if (world.isClientSide()) {
|
||||
// client
|
||||
if (TickSpeed.process_entitiesClient()) blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||
} else {
|
||||
// server
|
||||
ServerLevel serverWorld = (ServerLevel) world;
|
||||
TickRateManager tickRateManager = ((MinecraftServerInterface)serverWorld.getServer()).getTickRateManager();
|
||||
if (tickRateManager.process_entities()) blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.network.CarpetClient;
|
||||
import carpet.network.ClientNetworkHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -33,11 +34,13 @@ public abstract class ClientPacketListener_customPacketsMixin
|
||||
private void onGameJoined(ClientboundLoginPacket packet, CallbackInfo info)
|
||||
{
|
||||
CarpetClient.gameJoined(minecraft.player);
|
||||
TickSpeed.resetClient();
|
||||
}
|
||||
|
||||
@Inject(method = "onDisconnect", at = @At("HEAD"))
|
||||
private void onCMDisconnected(Component reason, CallbackInfo ci)
|
||||
{
|
||||
CarpetClient.disconnect();
|
||||
TickSpeed.resetClient();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.TickSpeed;
|
||||
import net.minecraft.server.level.DistanceManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(DistanceManager.class)
|
||||
public class DistanceManager_tickMixin
|
||||
{
|
||||
@Shadow private long ticketTickCounter;
|
||||
|
||||
@Inject(method = "purgeStaleTickets", at = @At("HEAD"))
|
||||
private void pauseTicketSystem(CallbackInfo ci)
|
||||
{
|
||||
// pausing expiry of tickets
|
||||
// that will prevent also chunks from unloading, so require a deep frozen state
|
||||
if (!TickSpeed.process_entities() && TickSpeed.deeplyFrozen()) ticketTickCounter--;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.redstone.NeighborUpdater;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -87,13 +90,18 @@ public abstract class Level_tickMixin implements LevelInterface
|
||||
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
|
||||
{
|
||||
// this shows that probably tick speed controller needs to be accessible through level referring to servers on server and client on clientLevel
|
||||
if (isClientSide) {
|
||||
if (!(TickSpeed.process_entitiesClient() || (e instanceof Player) || TickSpeed.isIs_superHotClient() && e.getControllingPassenger() instanceof Player))
|
||||
if (!isClientSide)
|
||||
{
|
||||
ServerLevel serverLevel = (ServerLevel) (Object) this;
|
||||
TickRateManager trm = ((MinecraftServerInterface)serverLevel.getServer()).getTickRateManager();
|
||||
if (!(trm.process_entities() || (e instanceof Player)))
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
} else {
|
||||
if (!(TickSpeed.gTRM().map(trm -> trm.process_entities).orElse(true) || (e instanceof Player)))
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(TickSpeed.process_entitiesClient() || (e instanceof Player) || TickSpeed.isIs_superHotClient() && e.getControllingPassenger() instanceof Player))
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
@@ -89,8 +88,10 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
|
||||
))
|
||||
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
|
||||
{
|
||||
if (!TickSpeed.process_entities())
|
||||
if (!getTickRateManager().process_entities())
|
||||
{
|
||||
return;
|
||||
}
|
||||
TICK.onTick((MinecraftServer) (Object) this);
|
||||
NETHER_TICK.onTick((MinecraftServer) (Object) this);
|
||||
ENDER_TICK.onTick((MinecraftServer) (Object) this);
|
||||
|
||||
@@ -112,7 +112,7 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
||||
long msThisTick = 0L;
|
||||
long long_1 = 0L;
|
||||
float mspt = tickRateManager.mspt;
|
||||
if (tickRateManager.time_warp_start_time != 0 && TickSpeed.continueWarp())
|
||||
if (tickRateManager.time_warp_start_time != 0 && tickRateManager.continueWarp())
|
||||
{
|
||||
//making sure server won't flop after the warp or if the warp is interrupted
|
||||
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
|
||||
@@ -151,9 +151,9 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
||||
//this.startMonitor(tickDurationMonitor);
|
||||
this.startMetricsRecordingTick();
|
||||
this.profiler.push("tick");
|
||||
this.tickServer(TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0 ? ()->true : this::haveTime);
|
||||
this.tickServer(tickRateManager.time_warp_start_time != 0 ? ()->true : this::haveTime);
|
||||
this.profiler.popPush("nextTickWait");
|
||||
if (TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0) // clearing all hanging tasks no matter what when warping
|
||||
if (tickRateManager.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
|
||||
{
|
||||
while(this.runEveryTask()) {Thread.yield();}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.server.level.DistanceManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -78,7 +80,7 @@ public abstract class ServerChunkCache_tickMixin
|
||||
private boolean skipChunkTicking(ServerLevel serverWorld)
|
||||
{
|
||||
boolean debug = serverWorld.isDebug();
|
||||
if (!TickSpeed.process_entities())
|
||||
if (!((MinecraftServerInterface)serverWorld.getServer()).getTickRateManager().process_entities())
|
||||
{
|
||||
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
|
||||
// to be kept in sync with the original injection source
|
||||
@@ -97,4 +99,17 @@ public abstract class ServerChunkCache_tickMixin
|
||||
return debug;
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/DistanceManager;purgeStaleTickets()V"
|
||||
))
|
||||
private void pauseTicketSystem(DistanceManager distanceManager)
|
||||
{
|
||||
// pausing expiry of tickets
|
||||
// that will prevent also chunks from unloading, so require a deep frozen state
|
||||
TickRateManager trm = ((MinecraftServerInterface) level.getServer()).getTickRateManager();
|
||||
if (!trm.process_entities() && trm.deeplyFrozen()) return;
|
||||
distanceManager.purgeStaleTickets();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerFunctionManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@@ -11,14 +14,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ServerFunctionManager.class)
|
||||
public class ServerFunctionManager_tickMixin
|
||||
{
|
||||
@Shadow @Final MinecraftServer server;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
private void beforeDatapacks(CallbackInfo ci)
|
||||
{
|
||||
if (!TickSpeed.process_entities()) ci.cancel();
|
||||
else
|
||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||
if (! ((MinecraftServerInterface)server).getTickRateManager().process_entities())
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -27,7 +27,7 @@ public class ServerGamePacketListenerImpl_tickMixin
|
||||
{
|
||||
if (p.getXxa() != 0.0F || p.getZza() != 0.0F || p.isJumping() || p.isShiftKeyDown())
|
||||
{
|
||||
TickSpeed.reset_player_active_timeout();
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().reset_player_active_timeout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ServerGamePacketListenerImpl_tickMixin
|
||||
{
|
||||
lastMoved = movedBy;
|
||||
lastMovedTick = player.getServer().getTickCount();
|
||||
TickSpeed.reset_player_active_timeout();
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().reset_player_active_timeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
@@ -159,13 +159,13 @@ public abstract class ServerLevel_tickMixin extends Level
|
||||
))
|
||||
private void tickWorldBorder(WorldBorder worldBorder)
|
||||
{
|
||||
if (TickSpeed.process_entities()) worldBorder.tick();
|
||||
if (((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) worldBorder.tick();
|
||||
}
|
||||
|
||||
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
|
||||
private void tickWeather(CallbackInfo ci)
|
||||
{
|
||||
if (!TickSpeed.process_entities()) ci.cancel();
|
||||
if (!((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) ci.cancel();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
@@ -174,7 +174,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
||||
))
|
||||
private void tickTimeConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (TickSpeed.process_entities()) tickTime();
|
||||
if (((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) tickTime();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
@@ -183,7 +183,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
||||
))
|
||||
private boolean tickPendingBlocks(ServerLevel serverWorld)
|
||||
{
|
||||
if (!TickSpeed.process_entities()) return true;
|
||||
if (!((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) return true;
|
||||
return serverWorld.isDebug(); // isDebug()
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
||||
))
|
||||
private void tickConditionally(Raids raidManager)
|
||||
{
|
||||
if (TickSpeed.process_entities()) raidManager.tick();
|
||||
if (((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) raidManager.tick();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
@@ -202,6 +202,6 @@ public abstract class ServerLevel_tickMixin extends Level
|
||||
))
|
||||
private void tickConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (TickSpeed.process_entities()) runBlockEvents();
|
||||
if (((MinecraftServerInterface)getServer()).getTickRateManager().process_entities()) runBlockEvents();
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import carpet.CarpetServer;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.api.settings.CarpetRule;
|
||||
import carpet.api.settings.RuleHelper;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ServerGamePacketListenerImplInterface;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.script.utils.SnoopyCommandSource;
|
||||
import carpet.api.settings.SettingsManager;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -77,7 +78,7 @@ public class ServerNetworkHandler
|
||||
CarpetSettings.LOG.info("Player "+playerEntity.getName().getString()+" joined with a matching carpet client");
|
||||
else
|
||||
CarpetSettings.LOG.warn("Player "+playerEntity.getName().getString()+" joined with another carpet version: "+clientVersion);
|
||||
DataBuilder data = DataBuilder.create().withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||
DataBuilder data = DataBuilder.create(playerEntity.server).withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||
CarpetServer.settingsManager.getCarpetRules().forEach(data::withRule);
|
||||
CarpetServer.extensions.forEach(e -> {
|
||||
SettingsManager eManager = e.extensionSettingsManager();
|
||||
@@ -114,7 +115,7 @@ public class ServerNetworkHandler
|
||||
if (!output.isEmpty()) result.put("output", outputResult);
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withCustomNbt("clientCommand", result).build()
|
||||
DataBuilder.create(player.server).withCustomNbt("clientCommand", result).build()
|
||||
));
|
||||
// run command plug to command output,
|
||||
}
|
||||
@@ -140,7 +141,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withRule(rule).build()
|
||||
DataBuilder.create(player.server).withRule(rule).build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -152,7 +153,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withTickRate().build()
|
||||
DataBuilder.create(player.server).withTickRate().build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -164,7 +165,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withFrozenState().build()
|
||||
DataBuilder.create(player.server).withFrozenState().build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -176,7 +177,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withSuperHotState().build()
|
||||
DataBuilder.create(player.server).withSuperHotState().build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -188,7 +189,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withTickPlayerActiveTimeout().build()
|
||||
DataBuilder.create(player.server).withTickPlayerActiveTimeout().build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -200,7 +201,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withCustomNbt(command, data).build()
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -211,7 +212,7 @@ public class ServerNetworkHandler
|
||||
{
|
||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||
CarpetClient.CARPET_CHANNEL,
|
||||
DataBuilder.create().withCustomNbt(command, data).build()
|
||||
DataBuilder.create(player.server).withCustomNbt(command, data).build()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -247,35 +248,41 @@ public class ServerNetworkHandler
|
||||
private static class DataBuilder
|
||||
{
|
||||
private CompoundTag tag;
|
||||
private static DataBuilder create()
|
||||
private MinecraftServer server;
|
||||
private static DataBuilder create(final MinecraftServer server)
|
||||
{
|
||||
return new DataBuilder();
|
||||
return new DataBuilder(server);
|
||||
}
|
||||
private DataBuilder()
|
||||
private DataBuilder(MinecraftServer server)
|
||||
{
|
||||
tag = new CompoundTag();
|
||||
this.server = server;
|
||||
}
|
||||
private DataBuilder withTickRate()
|
||||
{
|
||||
tag.putFloat("TickRate", TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f));
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
tag.putFloat("TickRate", trm.tickrate);
|
||||
return this;
|
||||
}
|
||||
private DataBuilder withFrozenState()
|
||||
{
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
CompoundTag tickingState = new CompoundTag();
|
||||
tickingState.putBoolean("is_paused", TickSpeed.isPaused());
|
||||
tickingState.putBoolean("deepFreeze", TickSpeed.deeplyFrozen());
|
||||
tickingState.putBoolean("is_paused", trm.isPaused());
|
||||
tickingState.putBoolean("deepFreeze", trm.deeplyFrozen());
|
||||
tag.put("TickingState", tickingState);
|
||||
return this;
|
||||
}
|
||||
private DataBuilder withSuperHotState()
|
||||
{
|
||||
tag.putBoolean("SuperHotState", TickSpeed.gTRM().map(trm -> trm.is_superHot).orElse(false));
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
tag.putBoolean("SuperHotState", trm.is_superHot);
|
||||
return this;
|
||||
}
|
||||
private DataBuilder withTickPlayerActiveTimeout()
|
||||
{
|
||||
tag.putInt("TickPlayerActiveTimeout", TickSpeed.gTRM().map(trm -> trm.player_active_timeout).orElse(0));
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
tag.putInt("TickPlayerActiveTimeout", trm.player_active_timeout);
|
||||
return this;
|
||||
}
|
||||
private DataBuilder withRule(CarpetRule<?> rule)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package carpet.patches;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.helpers.TickSpeed;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.border.BorderChangeListener;
|
||||
@@ -89,13 +90,19 @@ public class TickSyncedBorderExtent implements WorldBorder.BorderExtent
|
||||
double ms;
|
||||
if (server == null)
|
||||
{
|
||||
ms = TickSpeed.mspt();
|
||||
// can this even happen?
|
||||
ms = 50.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ms = Arrays.stream(server.tickTimes).average().orElseThrow(IllegalStateException::new) * 1.0E-6D;
|
||||
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
if (trm.time_warp_start_time == 0) // not in time warp
|
||||
{
|
||||
ms = Math.max(ms, trm.mspt);
|
||||
}
|
||||
}
|
||||
double tps = 1_000.0D / Math.max((TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0) ? 0.0 : TickSpeed.mspt(), ms);
|
||||
double tps = 1_000.0D / ms;
|
||||
return (long) ((this.tickDuration - this.ticks) / tps * 1_000);
|
||||
}
|
||||
|
||||
|
||||
@@ -1369,7 +1369,7 @@ public class CarpetEventServer
|
||||
|
||||
public void tick()
|
||||
{
|
||||
if (Carpet.isTickProcessingPaused())
|
||||
if (Carpet.isTickProcessingPaused(scriptServer.server))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -134,9 +134,9 @@ public class Carpet
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isTickProcessingPaused()
|
||||
public static boolean isTickProcessingPaused(MinecraftServer server)
|
||||
{
|
||||
return !TickSpeed.process_entities();
|
||||
return !((MinecraftServerInterface)server).getTickRateManager().process_entities();
|
||||
}
|
||||
|
||||
public static void handleExtensionsAPI(CarpetExpression expression)
|
||||
|
||||
@@ -12,4 +12,6 @@ accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$V
|
||||
|
||||
accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List;
|
||||
|
||||
accessible method net/minecraft/server/level/DistanceManager purgeStaleTickets ()V
|
||||
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour UPDATE_SHAPE_ORDER [Lnet/minecraft/core/Direction;
|
||||
@@ -36,7 +36,6 @@
|
||||
"BoundTickingBlockEntity_tickMixin",
|
||||
"ServerChunkCache_tickMixin",
|
||||
"ChunkMap_tickMixin",
|
||||
"DistanceManager_tickMixin",
|
||||
"ServerFunctionManager_tickMixin",
|
||||
"WorldBorder_tickMixin",
|
||||
"ChunkMap_scarpetChunkCreationMixin",
|
||||
|
||||
Reference in new issue
Block a user