yeet most of tick
This commit is contained in:
1 parent
2c01a98216
commit
1a7e8b6875
30 files changed
+152
-1416
No files matched your search
@@ -15,12 +15,9 @@ import carpet.commands.MobAICommand;
|
||||
import carpet.commands.PerimeterInfoCommand;
|
||||
import carpet.commands.PlayerCommand;
|
||||
import carpet.commands.ProfileCommand;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
import carpet.script.ScriptCommand;
|
||||
import carpet.commands.SpawnCommand;
|
||||
import carpet.commands.TestCommand;
|
||||
import carpet.commands.TickCommand;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.helpers.HopperCounter;
|
||||
import carpet.logging.LoggerRegistry;
|
||||
@@ -107,8 +104,6 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
|
||||
public static void tick(MinecraftServer server)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||
trm.tick();
|
||||
HUDController.update_hud(server, null);
|
||||
if (scriptServer != null) scriptServer.tick();
|
||||
|
||||
@@ -126,7 +121,6 @@ public class CarpetServer // static for now - easier to handle all around the co
|
||||
}
|
||||
forEachManager(sm -> sm.registerCommand(dispatcher, commandBuildContext));
|
||||
|
||||
TickCommand.register(dispatcher, commandBuildContext);
|
||||
ProfileCommand.register(dispatcher, commandBuildContext);
|
||||
CounterCommand.register(dispatcher, commandBuildContext);
|
||||
LogCommand.register(dispatcher, commandBuildContext);
|
||||
|
||||
@@ -593,6 +593,7 @@ public class CarpetSettings
|
||||
@Rule(desc = "Disables breaking of blocks caused by flowing liquids", category = CREATIVE)
|
||||
public static boolean liquidDamageDisabled = false;
|
||||
|
||||
|
||||
@Rule(
|
||||
desc = "smooth client animations with low tps settings",
|
||||
extra = "works only in SP, and will slow down players",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import carpet.utils.CommandHelper;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
@@ -8,8 +9,6 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import static carpet.commands.TickCommand.healthEntities;
|
||||
import static carpet.commands.TickCommand.healthReport;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
@@ -32,4 +31,16 @@ public class ProfileCommand
|
||||
executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks")))));
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
|
||||
public static int healthReport(CommandSourceStack source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_tick_report(source, ticks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int healthEntities(CommandSourceStack source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_entity_report(source, ticks);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
||||
@@ -181,19 +180,10 @@ public class SpawnCommand
|
||||
|
||||
// tick warp 0
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.requestGameToWarpSpeed(null, 0, null, null);
|
||||
// tick warp given player
|
||||
CommandSourceStack csource = null;
|
||||
ServerPlayer player = null;
|
||||
try
|
||||
{
|
||||
player = source.getPlayerOrException();
|
||||
csource = source;
|
||||
}
|
||||
catch (CommandSyntaxException ignored)
|
||||
{
|
||||
}
|
||||
trm.requestGameToWarpSpeed(player, ticks, null, csource);
|
||||
// stop warp
|
||||
// unnecessary
|
||||
// start warp
|
||||
trm.requestGameToSprint(ticks);
|
||||
Messenger.m(source, String.format("gi Started spawn test for %d ticks", ticks));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
package carpet.commands;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import carpet.utils.CommandHelper;
|
||||
import carpet.utils.Messenger;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg;
|
||||
import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
import static net.minecraft.commands.SharedSuggestionProvider.suggest;
|
||||
|
||||
public class TickCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext commandBuildContext)
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> literalargumentbuilder = literal("tick").
|
||||
requires((player) -> CommandHelper.canUseCommand(player, CarpetSettings.commandTick)).
|
||||
then(literal("rate").
|
||||
executes((c) -> queryTps(c.getSource())).
|
||||
then(argument("rate", floatArg(0.1F, 500.0F)).
|
||||
suggests( (c, b) -> suggest(new String[]{"20.0"},b)).
|
||||
executes((c) -> setTps(c.getSource(), getFloat(c, "rate"))))).
|
||||
then(literal("warp").
|
||||
executes( (c)-> setWarp(c.getSource(), 0, null)).
|
||||
then(argument("ticks", integer(0)).
|
||||
suggests( (c, b) -> suggest(new String[]{"3600","72000"},b)).
|
||||
executes((c) -> setWarp(c.getSource(), getInteger(c,"ticks"), null)).
|
||||
then(argument("tail command", greedyString()).
|
||||
executes( (c) -> setWarp(
|
||||
c.getSource(),
|
||||
getInteger(c,"ticks"),
|
||||
getString(c, "tail command")))))).
|
||||
then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource(), false)).
|
||||
then(literal("status").executes( (c) -> freezeStatus(c.getSource()))).
|
||||
then(literal("deep").executes( (c) -> toggleFreeze(c.getSource(), true))).
|
||||
then(literal("on").executes( (c) -> setFreeze(c.getSource(), false, true)).
|
||||
then(literal("deep").executes( (c)-> setFreeze(c.getSource(), true, true)))).
|
||||
then(literal("off").executes( (c) -> setFreeze(c.getSource(), false, false)))).
|
||||
then(literal("step").
|
||||
executes((c) -> step(c.getSource(), 1)).
|
||||
then(argument("ticks", integer(1,72000)).
|
||||
suggests( (c, b) -> suggest(new String[]{"20"},b)).
|
||||
executes((c) -> step(c.getSource(), getInteger(c,"ticks"))))).
|
||||
then(literal("superHot").executes( (c)-> toggleSuperHot(c.getSource()))).
|
||||
then(literal("health").
|
||||
executes( (c) -> healthReport(c.getSource(), 100)).
|
||||
then(argument("ticks", integer(20,24000)).
|
||||
executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))).
|
||||
then(literal("entities").
|
||||
executes((c) -> healthEntities(c.getSource(), 100)).
|
||||
then(argument("ticks", integer(20,24000)).
|
||||
executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks")))));
|
||||
|
||||
|
||||
dispatcher.register(literalargumentbuilder);
|
||||
}
|
||||
|
||||
|
||||
private static int setTps(CommandSourceStack source, float tps)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.setTickRate(tps, true);
|
||||
queryTps(source);
|
||||
return (int)tps;
|
||||
}
|
||||
|
||||
private static int queryTps(CommandSourceStack source)
|
||||
{
|
||||
ServerTickRateManager 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
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
Component message = trm.requestGameToWarpSpeed(player, advance, tail_command, source);
|
||||
source.sendSuccess(() -> message, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int freezeStatus(CommandSourceStack source)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
if(trm.gameIsPaused())
|
||||
{
|
||||
Messenger.m(source, "gi Freeze Status: Game is "+(trm.deeplyFrozen()?"deeply ":"")+"frozen");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Freeze Status: Game runs normally");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean freeze)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.setFrozenState(freeze, isDeep);
|
||||
if (trm.gameIsPaused())
|
||||
{
|
||||
Messenger.m(source, "gi Game is "+(isDeep?"deeply ":"")+"frozen");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Game runs normally");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleFreeze(CommandSourceStack source, boolean isDeep)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
return setFreeze(source, isDeep, !trm.gameIsPaused());
|
||||
}
|
||||
|
||||
private static int step(CommandSourceStack source, int advance)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.stepGameIfPaused(advance);
|
||||
Messenger.m(source, "gi Stepping " + advance + " tick" + (advance != 1 ? "s" : ""));
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static int toggleSuperHot(CommandSourceStack source)
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
|
||||
trm.setSuperHot(!trm.isSuperHot());
|
||||
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers(source.getServer());
|
||||
if (trm.isSuperHot())
|
||||
{
|
||||
Messenger.m(source, "gi Superhot enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.m(source, "gi Superhot disabled");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int healthReport(CommandSourceStack source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_tick_report(source, ticks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static int healthEntities(CommandSourceStack source, int ticks)
|
||||
{
|
||||
CarpetProfiler.prepare_entity_report(source, ticks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package carpet.fakes;
|
||||
|
||||
import carpet.helpers.TickRateManager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface MinecraftInterface
|
||||
{
|
||||
Optional<TickRateManager> getTickRateManager();
|
||||
}
|
||||
@@ -1,255 +1,20 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
|
||||
public class ServerTickRateManager extends TickRateManager
|
||||
{
|
||||
private long remainingWarpTicks = 0;
|
||||
private long tickWarpStartTime = 0;
|
||||
private long scheduledCurrentWarpTicks = 0;
|
||||
private ServerPlayer warpResponsiblePlayer = null;
|
||||
private String tickWarpCallback = null;
|
||||
private CommandSourceStack warpResponsibleSource = null;
|
||||
|
||||
private MinecraftServer server;
|
||||
|
||||
public ServerTickRateManager(MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public boolean isInWarpSpeed()
|
||||
{
|
||||
return tickWarpStartTime != 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldEntityTick(Entity e)
|
||||
{
|
||||
return (runsNormally() || (e instanceof Player));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 #runGameElements} to make sure the
|
||||
* current tick is actually frozen, not only the game
|
||||
*
|
||||
* @return Whether or not the game is deeply frozen.
|
||||
*/
|
||||
public boolean deeplyFrozen()
|
||||
{
|
||||
return deepFreeze;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public void setFrozenState(boolean isPaused, boolean isDeepFreeze)
|
||||
{
|
||||
super.setFrozenState(isPaused, isDeepFreeze);
|
||||
ServerNetworkHandler.updateFrozenStateToConnectedPlayers(server);
|
||||
}
|
||||
|
||||
|
||||
public void resetPlayerActivity()
|
||||
{
|
||||
if (playerActivityTimeout < PLAYER_GRACE)
|
||||
{
|
||||
playerActivityTimeout = PLAYER_GRACE;
|
||||
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers(server);
|
||||
}
|
||||
}
|
||||
|
||||
public void stepGameIfPaused(int ticks)
|
||||
{
|
||||
playerActivityTimeout = PLAYER_GRACE + ticks;
|
||||
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers(server);
|
||||
}
|
||||
|
||||
public Component requestGameToWarpSpeed(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
||||
{
|
||||
if (0 == advance)
|
||||
{
|
||||
tickWarpCallback = null;
|
||||
if (source != warpResponsibleSource)
|
||||
{
|
||||
warpResponsibleSource = null;
|
||||
}
|
||||
if (remainingWarpTicks > 0)
|
||||
{
|
||||
finishTickWarp();
|
||||
warpResponsibleSource = null;
|
||||
return Messenger.c("gi Warp interrupted");
|
||||
}
|
||||
return Messenger.c("ri No warp in progress");
|
||||
}
|
||||
if (remainingWarpTicks > 0)
|
||||
{
|
||||
String who = "Another player";
|
||||
if (warpResponsiblePlayer != null)
|
||||
{
|
||||
who = warpResponsiblePlayer.getScoreboardName();
|
||||
}
|
||||
return Messenger.c("l " + who + " is already advancing time at the moment. Try later or ask them");
|
||||
}
|
||||
warpResponsiblePlayer = player;
|
||||
tickWarpStartTime = System.nanoTime();
|
||||
scheduledCurrentWarpTicks = advance;
|
||||
remainingWarpTicks = advance;
|
||||
tickWarpCallback = callback;
|
||||
warpResponsibleSource = source;
|
||||
return Messenger.c("gi Warp speed ....");
|
||||
}
|
||||
|
||||
// should be private
|
||||
public void finishTickWarp()
|
||||
{
|
||||
|
||||
long completed_ticks = scheduledCurrentWarpTicks - remainingWarpTicks;
|
||||
double milis_to_complete = System.nanoTime() - tickWarpStartTime;
|
||||
if (milis_to_complete == 0.0)
|
||||
{
|
||||
milis_to_complete = 1.0;
|
||||
}
|
||||
milis_to_complete /= 1000000.0;
|
||||
int tps = (int) (1000.0D * completed_ticks / milis_to_complete);
|
||||
double mspt = (1.0 * milis_to_complete) / completed_ticks;
|
||||
scheduledCurrentWarpTicks = 0;
|
||||
tickWarpStartTime = 0;
|
||||
if (tickWarpCallback != null)
|
||||
{
|
||||
Commands icommandmanager = warpResponsibleSource.getServer().getCommands();
|
||||
try
|
||||
{
|
||||
icommandmanager.performPrefixedCommand(warpResponsibleSource, tickWarpCallback);
|
||||
}
|
||||
catch (Throwable var23)
|
||||
{
|
||||
if (warpResponsiblePlayer != null)
|
||||
{
|
||||
Messenger.m(warpResponsiblePlayer, "r Command Callback failed - unknown error: ", "rb /" + tickWarpCallback, "/" + tickWarpCallback);
|
||||
}
|
||||
}
|
||||
tickWarpCallback = null;
|
||||
warpResponsibleSource = null;
|
||||
}
|
||||
if (warpResponsiblePlayer != null)
|
||||
{
|
||||
Messenger.m(warpResponsiblePlayer, String.format("gi ... Time warp completed with %d tps, or %.2f mspt", tps, mspt));
|
||||
warpResponsiblePlayer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Messenger.print_server_message(CarpetServer.minecraft_server, String.format("... Time warp completed with %d tps, or %.2f mspt", tps, mspt));
|
||||
}
|
||||
remainingWarpTicks = 0;
|
||||
|
||||
}
|
||||
|
||||
public boolean continueWarp()
|
||||
{
|
||||
if (!runGameElements)
|
||||
// Returning false so we don't have to run at max speed when doing nothing
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (remainingWarpTicks > 0)
|
||||
{
|
||||
if (remainingWarpTicks == scheduledCurrentWarpTicks) //first call after previous tick, adjust start time
|
||||
{
|
||||
tickWarpStartTime = System.nanoTime();
|
||||
}
|
||||
remainingWarpTicks -= 1;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
finishTickWarp();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Functional interface that listens for tickrate changes. This is
|
||||
* implemented to allow tickrate compatibility with other mods etc.
|
||||
*/
|
||||
private final Map<String, BiConsumer<String, Float>> tickrateListeners = new HashMap<>();
|
||||
private static final float MIN_TICKRATE = 0.01f;
|
||||
|
||||
//unused - mod compat reasons
|
||||
@Override
|
||||
public void setTickRate(float rate)
|
||||
{
|
||||
setTickRate(rate, true);
|
||||
}
|
||||
|
||||
public void setTickRate(float rate, boolean update)
|
||||
{
|
||||
super.setTickRate(rate);
|
||||
if (update)
|
||||
{
|
||||
notifyTickrateListeners("carpet");
|
||||
}
|
||||
}
|
||||
|
||||
private void tickrateChanged(String modId, float rate)
|
||||
{
|
||||
// Other mods might change the tickrate in a slightly
|
||||
// different way. Also allow for tickrates that don't
|
||||
// divide into 1000 here.
|
||||
|
||||
if (rate < MIN_TICKRATE)
|
||||
{
|
||||
rate = MIN_TICKRATE;
|
||||
}
|
||||
|
||||
tickrate = rate;
|
||||
mspt = 1000.0f / tickrate;
|
||||
|
||||
notifyTickrateListeners(modId);
|
||||
}
|
||||
|
||||
private void notifyTickrateListeners(String originModId)
|
||||
{
|
||||
synchronized (tickrateListeners)
|
||||
{
|
||||
for (Map.Entry<String, BiConsumer<String, Float>> listenerEntry : tickrateListeners.entrySet())
|
||||
{
|
||||
if (originModId == null || !originModId.equals(listenerEntry.getKey()))
|
||||
{
|
||||
listenerEntry.getValue().accept(originModId, tickrate);
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerNetworkHandler.updateTickSpeedToConnectedPlayers(server);
|
||||
}
|
||||
|
||||
public BiConsumer<String, Float> addTickrateListener(String modId, BiConsumer<String, Float> tickrateListener)
|
||||
{
|
||||
synchronized (tickrateListeners)
|
||||
{
|
||||
tickrateListeners.put(modId, tickrateListener);
|
||||
}
|
||||
return this::tickrateChanged;
|
||||
public void requestGameToSprint(final int ticks)
|
||||
{ // noop
|
||||
}
|
||||
}
|
||||
@@ -1,105 +1,19 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class TickRateManager
|
||||
{
|
||||
public static final int PLAYER_GRACE = 2;
|
||||
protected float tickrate = 20.0f;
|
||||
protected float mspt = 50.0f;
|
||||
protected int playerActivityTimeout = 0;
|
||||
protected boolean runGameElements = true;
|
||||
// deep freeze is onlyu used serverside
|
||||
protected boolean deepFreeze = false;
|
||||
protected boolean isGamePaused = false;
|
||||
protected boolean isSuperHot = false;
|
||||
|
||||
public void setTickRate(float rate)
|
||||
{
|
||||
tickrate = rate;
|
||||
long msptt = (long) (1000.0 / tickrate);
|
||||
if (msptt <= 0L)
|
||||
{
|
||||
msptt = 1L;
|
||||
tickrate = 1000.0f;
|
||||
}
|
||||
mspt = msptt;
|
||||
}
|
||||
|
||||
public float tickrate()
|
||||
{
|
||||
return tickrate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not the game is in a frozen state.
|
||||
* You should normally use {@link #runGameElements} instead,
|
||||
* since that one accounts for tick steps and superhot
|
||||
*/
|
||||
public boolean gameIsPaused()
|
||||
{
|
||||
return isGamePaused;
|
||||
return false;
|
||||
}
|
||||
|
||||
public float mspt() {
|
||||
return mspt;
|
||||
public float mspt()
|
||||
{
|
||||
return 50.0f;
|
||||
}
|
||||
|
||||
public boolean runsNormally()
|
||||
{
|
||||
return runGameElements;
|
||||
}
|
||||
|
||||
public boolean isSuperHot()
|
||||
{
|
||||
return isSuperHot;
|
||||
}
|
||||
|
||||
public void setPlayerActiveTimeout(int timeout)
|
||||
{
|
||||
playerActivityTimeout = timeout;
|
||||
}
|
||||
|
||||
public int getPlayerActiveTimeout()
|
||||
{
|
||||
return playerActivityTimeout;
|
||||
}
|
||||
|
||||
public void setFrozenState(boolean isPaused, boolean isDeepFreeze)
|
||||
{
|
||||
isGamePaused = isPaused;
|
||||
deepFreeze = isPaused && isDeepFreeze;
|
||||
}
|
||||
|
||||
public void setSuperHot(boolean isSuperHot)
|
||||
{
|
||||
this.isSuperHot = isSuperHot;
|
||||
}
|
||||
|
||||
public void tick()
|
||||
{
|
||||
if (playerActivityTimeout > 0)
|
||||
{
|
||||
playerActivityTimeout--;
|
||||
}
|
||||
if (isGamePaused)
|
||||
{
|
||||
runGameElements = playerActivityTimeout >= PLAYER_GRACE;
|
||||
}
|
||||
else if (isSuperHot)
|
||||
{
|
||||
runGameElements = playerActivityTimeout > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
runGameElements = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldEntityTick(Entity e)
|
||||
{
|
||||
// client
|
||||
return (runsNormally() || (e instanceof Player) || isSuperHot() && e.getControllingPassenger() instanceof Player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.utils.Messenger;
|
||||
|
||||
@Deprecated(forRemoval = true, since = "now")
|
||||
public class TickSpeed
|
||||
{
|
||||
private static Optional<ServerTickRateManager> gTRM() {
|
||||
if (CarpetServer.minecraft_server == null) return Optional.empty();
|
||||
return Optional.of(((MinecraftServerInterface)CarpetServer.minecraft_server).getTickRateManager());
|
||||
}
|
||||
|
||||
public static boolean process_entities() {
|
||||
return gTRM().map(ServerTickRateManager::runsNormally).orElse(true);
|
||||
}
|
||||
|
||||
public static float mspt() {
|
||||
return gTRM().map(ServerTickRateManager::mspt).orElse(50.0f);
|
||||
}
|
||||
|
||||
public static boolean isPaused() {
|
||||
return gTRM().map(ServerTickRateManager::gameIsPaused).orElse(false);
|
||||
}
|
||||
|
||||
public static boolean deeplyFrozen() {
|
||||
return gTRM().map(ServerTickRateManager::deeplyFrozen).orElse(false);
|
||||
}
|
||||
|
||||
public static void setFrozenState(boolean isPaused, boolean isDeepFreeze) {
|
||||
gTRM().ifPresent(trm -> trm.setFrozenState(isPaused, isDeepFreeze));
|
||||
}
|
||||
|
||||
public static void reset_player_active_timeout()
|
||||
{
|
||||
gTRM().ifPresent(ServerTickRateManager::resetPlayerActivity);
|
||||
}
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
// noop - called on server to reset client
|
||||
}
|
||||
|
||||
public static void add_ticks_to_run_in_pause(int ticks)
|
||||
{
|
||||
gTRM().ifPresent(trm -> trm.stepGameIfPaused(ticks));
|
||||
}
|
||||
|
||||
public static Component tickrate_advance(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
||||
{
|
||||
return gTRM().map(trm -> trm.requestGameToWarpSpeed(player, advance, callback, source)).orElse(Messenger.c("ri Tickrate management not enabled"));
|
||||
}
|
||||
|
||||
public static void finish_time_warp()
|
||||
{
|
||||
gTRM().ifPresent(ServerTickRateManager::finishTickWarp);
|
||||
}
|
||||
|
||||
public static boolean continueWarp()
|
||||
{
|
||||
return gTRM().map(ServerTickRateManager::continueWarp).orElse(false);
|
||||
}
|
||||
|
||||
public static void tick()
|
||||
{
|
||||
gTRM().ifPresent(ServerTickRateManager::tick);
|
||||
}
|
||||
//unused - mod compat reasons
|
||||
public static void tickrate(float rate) {tickrate(rate, true);}
|
||||
public static void tickrate(float rate, boolean update)
|
||||
{
|
||||
gTRM().ifPresent(trm -> trm.setTickRate(rate, update));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
private static float mspt = 50.0f;
|
||||
private static int player_active_timeout = 0;
|
||||
private static boolean process_entities = true;
|
||||
private static boolean deepFreeze = false;
|
||||
private static boolean is_paused = false;
|
||||
private static boolean is_superHot = false;
|
||||
|
||||
public static void tickrateClient(float rate)
|
||||
{
|
||||
tickrate = rate;
|
||||
long msptt = (long) (1000.0 / tickrate);
|
||||
if (msptt <= 0L)
|
||||
{
|
||||
msptt = 1L;
|
||||
tickrate = 1000.0f;
|
||||
}
|
||||
|
||||
mspt = msptt;
|
||||
}
|
||||
|
||||
public static float msptClient() {
|
||||
return mspt;
|
||||
}
|
||||
|
||||
public static boolean process_entitiesClient()
|
||||
{
|
||||
return process_entities;
|
||||
}
|
||||
|
||||
public static boolean isIs_superHotClient()
|
||||
{
|
||||
return is_superHot;
|
||||
}
|
||||
|
||||
public static void setPlayer_active_timeoutClient(int timeout)
|
||||
{
|
||||
player_active_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
public static void setFrozenStateClient(boolean isPaused, boolean isDeepFreeze)
|
||||
{
|
||||
is_paused = isPaused;
|
||||
deepFreeze = isPaused ? isDeepFreeze : false;
|
||||
}
|
||||
|
||||
public static void setSuperHotClient(boolean isSuperHot)
|
||||
{
|
||||
is_superHot = isSuperHot;
|
||||
}
|
||||
|
||||
public static void tickClient()
|
||||
{
|
||||
if (player_active_timeout > 0)
|
||||
{
|
||||
player_active_timeout--;
|
||||
}
|
||||
if (is_paused)
|
||||
{
|
||||
process_entities = player_active_timeout >= ServerTickRateManager.PLAYER_GRACE;
|
||||
}
|
||||
else if (is_superHot)
|
||||
{
|
||||
process_entities = player_active_timeout > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
process_entities = true;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
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;
|
||||
|
||||
@Mixin(targets = "net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity")
|
||||
public class BoundTickingBlockEntity_profilerMixin<T extends BlockEntity>
|
||||
{
|
||||
@Shadow @Final private T blockEntity;
|
||||
CarpetProfiler.ProfilerToken entitySection;
|
||||
|
||||
@Inject(method = "tick()V", at = @At("HEAD"))
|
||||
private void startTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
entitySection = CarpetProfiler.start_block_entity_section(blockEntity.getLevel(), blockEntity, CarpetProfiler.TYPE.TILEENTITY);
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||
private void endTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
CarpetProfiler.end_current_entity_section(entitySection);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(targets = "net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity")
|
||||
public class BoundTickingBlockEntity_tickMixin<T extends BlockEntity>
|
||||
{
|
||||
@Shadow @Final private T blockEntity;
|
||||
CarpetProfiler.ProfilerToken entitySection;
|
||||
|
||||
|
||||
@Inject(method = "tick()V", at = @At("HEAD"))
|
||||
private void startTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
entitySection = CarpetProfiler.start_block_entity_section(blockEntity.getLevel(), blockEntity, CarpetProfiler.TYPE.TILEENTITY);
|
||||
}
|
||||
|
||||
@Redirect(method = "tick()V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/level/block/entity/BlockEntityTicker;tick(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/BlockEntity;)V"
|
||||
))
|
||||
private void checkProcessBEs(BlockEntityTicker<T> blockEntityTicker, Level world, BlockPos pos, BlockState state, T blockEntity)
|
||||
{
|
||||
TickRateManager tickRateManager = ((LevelInterface)world).tickRateManager();
|
||||
if (tickRateManager.runsNormally())
|
||||
{
|
||||
blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||
private void endTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
CarpetProfiler.end_current_entity_section(entitySection);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@Mixin(ChunkMap.class)
|
||||
public class ChunkMap_tickMixin
|
||||
public class ChunkMap_profilerMixin
|
||||
{
|
||||
@Shadow @Final ServerLevel level;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
@@ -1,7 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.world.level.redstone.NeighborUpdater;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -54,12 +53,6 @@ public abstract class Level_tickMixin implements LevelInterface
|
||||
@Inject(method = "guardEntityTick", at = @At("HEAD"), cancellable = true)
|
||||
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
|
||||
{
|
||||
TickRateManager trm = tickRateManager();
|
||||
if (!trm.shouldEntityTick(e))
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
entitySection = CarpetProfiler.start_entity_section((Level) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntity_tickSpeedMixin
|
||||
{
|
||||
@Inject(method = "pushEntities", at = @At("HEAD"), cancellable = true)
|
||||
private void onPushEntities(CallbackInfo ci)
|
||||
{
|
||||
if ((LivingEntity)(Object)this instanceof ServerPlayer) {
|
||||
var server = (MinecraftServerInterface)((LivingEntity)(Object)this).level().getServer();
|
||||
if(server.getTickRateManager().gameIsPaused()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.fakes.MinecraftInterface;
|
||||
import carpet.network.CarpetClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -13,10 +11,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin implements MinecraftInterface
|
||||
public class MinecraftMixin
|
||||
{
|
||||
@Shadow public ClientLevel level;
|
||||
|
||||
@@ -29,19 +25,10 @@ public class MinecraftMixin implements MinecraftInterface
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void onClientTick(CallbackInfo info) {
|
||||
if (this.level != null) {
|
||||
getTickRateManager().ifPresent(TickRateManager::tick);
|
||||
boolean runsNormally = ((LevelInterface)this.level).tickRateManager().runsNormally();
|
||||
// hope server doesn't need to tick - should be handled by the server on its own
|
||||
if (!getTickRateManager().map(TickRateManager::runsNormally).orElse(true))
|
||||
if (!runsNormally)
|
||||
CarpetClient.shapes.renewShapes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TickRateManager> getTickRateManager()
|
||||
{
|
||||
if (this.level != null) {
|
||||
return Optional.of(((LevelInterface)this.level).tickRateManager());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -2,72 +2,27 @@ package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
import carpet.patches.CopyProfilerResult;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.profiling.EmptyProfileResults;
|
||||
import net.minecraft.util.profiling.ProfileResults;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(value = MinecraftServer.class, priority = Integer.MAX_VALUE - 10)
|
||||
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask> implements MinecraftServerInterface
|
||||
{
|
||||
@Shadow private volatile boolean running;
|
||||
|
||||
@Shadow private long nextTickTime;
|
||||
|
||||
@Shadow @Final private static Logger LOGGER;
|
||||
|
||||
@Shadow private ProfilerFiller profiler;
|
||||
|
||||
public MinecraftServer_tickspeedMixin(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Shadow protected abstract void tickServer(BooleanSupplier booleanSupplier_1);
|
||||
|
||||
@Shadow protected abstract boolean haveTime();
|
||||
|
||||
@Shadow private long delayedTasksMaxNextTickTime;
|
||||
|
||||
@Shadow private volatile boolean isReady;
|
||||
|
||||
@Shadow private long lastOverloadWarning;
|
||||
|
||||
@Shadow private boolean mayHaveDelayedTasks;
|
||||
|
||||
@Shadow public abstract Iterable<ServerLevel> getAllLevels();
|
||||
|
||||
@Shadow private int tickCount;
|
||||
|
||||
@Shadow protected abstract void waitUntilNextTick();
|
||||
|
||||
@Shadow protected abstract void startMetricsRecordingTick();
|
||||
|
||||
@Shadow protected abstract void endMetricsRecordingTick();
|
||||
|
||||
@Shadow private boolean debugCommandProfilerDelayStart;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
private float carpetMsptAccum = 0.0f;
|
||||
|
||||
private ServerTickRateManager serverTickRateManager;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
@@ -82,130 +37,19 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
||||
return serverTickRateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* To ensure compatibility with other mods we should allow milliseconds
|
||||
*/
|
||||
|
||||
// Cancel a while statement
|
||||
@Redirect(method = "runServer", at = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;running:Z"))
|
||||
private boolean cancelRunLoop(MinecraftServer server)
|
||||
{
|
||||
return false;
|
||||
} // target run()
|
||||
|
||||
// Replaced the above cancelled while statement with this one
|
||||
// could possibly just inject that mspt selection at the beginning of the loop, but then adding all mspt's to
|
||||
// replace 50L will be a hassle
|
||||
@Inject(method = "runServer", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
|
||||
target = "Lnet/minecraft/server/MinecraftServer;buildServerStatus()Lnet/minecraft/network/protocol/status/ServerStatus;"))
|
||||
target = "Lnet/minecraft/server/MinecraftServer;startMetricsRecordingTick()V"))
|
||||
private void modifiedRunLoop(CallbackInfo ci)
|
||||
{
|
||||
while (this.running)
|
||||
{
|
||||
//long long_1 = Util.getMeasuringTimeMs() - this.timeReference;
|
||||
//CM deciding on tick speed
|
||||
if (CarpetProfiler.tick_health_requested != 0L)
|
||||
{
|
||||
CarpetProfiler.start_tick_profiling();
|
||||
}
|
||||
long msThisTick = 0L;
|
||||
long long_1 = 0L;
|
||||
float mspt = serverTickRateManager.mspt();
|
||||
if (serverTickRateManager.isInWarpSpeed() && serverTickRateManager.continueWarp())
|
||||
{
|
||||
//making sure server won't flop after the warp or if the warp is interrupted
|
||||
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
|
||||
carpetMsptAccum = mspt;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Math.abs(carpetMsptAccum - mspt) > 1.0f)
|
||||
{
|
||||
// Tickrate changed. Ensure that we use the correct value.
|
||||
carpetMsptAccum = mspt;
|
||||
}
|
||||
|
||||
msThisTick = (long)carpetMsptAccum; // regular tick
|
||||
carpetMsptAccum += mspt - msThisTick;
|
||||
|
||||
long_1 = Util.getMillis() - this.nextTickTime;
|
||||
}
|
||||
//end tick deciding
|
||||
//smoothed out delay to include mcpt component. With 50L gives defaults.
|
||||
if (long_1 > /*2000L*/1000L+20*mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*mspt)
|
||||
{
|
||||
long long_2 = (long)(long_1 / mspt);//50L;
|
||||
LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", long_1, long_2);
|
||||
this.nextTickTime += (long)(long_2 * mspt);//50L;
|
||||
this.lastOverloadWarning = this.nextTickTime;
|
||||
}
|
||||
|
||||
if (this.debugCommandProfilerDelayStart) {
|
||||
this.debugCommandProfilerDelayStart = false;
|
||||
this.profilerTimings = Pair.of(Util.getNanos(), tickCount);
|
||||
//this.field_33978 = new MinecraftServer.class_6414(Util.getMeasuringTimeNano(), this.ticks);
|
||||
}
|
||||
this.nextTickTime += msThisTick;//50L;
|
||||
//TickDurationMonitor tickDurationMonitor = TickDurationMonitor.create("Server");
|
||||
//this.startMonitor(tickDurationMonitor);
|
||||
this.startMetricsRecordingTick();
|
||||
this.profiler.push("tick");
|
||||
this.tickServer(serverTickRateManager.isInWarpSpeed() ? ()->true : this::haveTime);
|
||||
this.profiler.popPush("nextTickWait");
|
||||
if (serverTickRateManager.isInWarpSpeed()) // clearing all hanging tasks no matter what when warping
|
||||
{
|
||||
while(this.runEveryTask()) {Thread.yield();}
|
||||
}
|
||||
this.mayHaveDelayedTasks = true;
|
||||
this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + /*50L*/ msThisTick, this.nextTickTime);
|
||||
// run all tasks (this will not do a lot when warping), but that's fine since we already run them
|
||||
this.waitUntilNextTick();
|
||||
this.profiler.pop();
|
||||
this.endMetricsRecordingTick();
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// just because profilerTimings class is public
|
||||
Pair<Long,Integer> profilerTimings = null;
|
||||
/// overworld around profiler timings
|
||||
@Inject(method = "isTimeProfilerRunning", at = @At("HEAD"), cancellable = true)
|
||||
public void isCMDebugRunning(CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
cir.setReturnValue(debugCommandProfilerDelayStart || profilerTimings != null);
|
||||
}
|
||||
@Inject(method = "stopTimeProfiler", at = @At("HEAD"), cancellable = true)
|
||||
public void stopCMDebug(CallbackInfoReturnable<ProfileResults> cir)
|
||||
{
|
||||
if (this.profilerTimings == null) {
|
||||
cir.setReturnValue(EmptyProfileResults.EMPTY);
|
||||
} else {
|
||||
ProfileResults profileResult = new CopyProfilerResult(
|
||||
profilerTimings.getRight(), profilerTimings.getLeft(),
|
||||
this.tickCount, Util.getNanos()
|
||||
);
|
||||
this.profilerTimings = null;
|
||||
cir.setReturnValue(profileResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean runEveryTask() {
|
||||
if (super.pollTask()) {
|
||||
return true;
|
||||
} else {
|
||||
if (true) { // unconditionally this time
|
||||
for(ServerLevel serverlevel : getAllLevels()) {
|
||||
if (serverlevel.getChunkSource().pollTask()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickServer", at = @At(
|
||||
value = "INVOKE",
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.utils.CarpetProfiler;
|
||||
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;
|
||||
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@Mixin(ServerChunkCache.class)
|
||||
public abstract class ServerChunkCache_profilerMixin
|
||||
{
|
||||
|
||||
@Shadow @Final ServerLevel level;
|
||||
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("HEAD"))
|
||||
private void startSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "FIELD",
|
||||
target = "net/minecraft/server/level/ServerChunkCache.level:Lnet/minecraft/server/level/ServerLevel;",
|
||||
ordinal = 10
|
||||
))
|
||||
private void skipChunkTicking(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/level/ServerLevel.tickChunk(Lnet/minecraft/world/level/chunk/LevelChunk;I)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void resumeSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("RETURN"))
|
||||
private void stopSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
//@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
|
||||
//ServerTickRateManager trm = ((MinecraftServerInterface) level.getServer()).getTickRateManager();
|
||||
//if (!trm.runsNormally() && trm.deeplyFrozen()) return;
|
||||
//distanceManager.purgeStaleTickets();
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@Mixin(ServerChunkCache.class)
|
||||
public abstract class ServerChunkCache_tickMixin
|
||||
{
|
||||
|
||||
@Shadow @Final ServerLevel level;
|
||||
|
||||
@Shadow @Final
|
||||
public ChunkMap chunkMap;
|
||||
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("HEAD"))
|
||||
private void startSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "FIELD",
|
||||
target = "net/minecraft/server/level/ServerChunkCache.level:Lnet/minecraft/server/level/ServerLevel;",
|
||||
ordinal = 10
|
||||
))
|
||||
private void skipChunkTicking(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/level/ServerLevel.tickChunk(Lnet/minecraft/world/level/chunk/LevelChunk;I)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void resumeSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("RETURN"))
|
||||
private void stopSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
//// Tick freeze
|
||||
@Redirect(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;isDebug()Z"
|
||||
))
|
||||
private boolean skipChunkTicking(ServerLevel serverWorld)
|
||||
{
|
||||
boolean debug = serverWorld.isDebug();
|
||||
if (!((MinecraftServerInterface)serverWorld.getServer()).getTickRateManager().runsNormally())
|
||||
{
|
||||
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
|
||||
// to be kept in sync with the original injection source
|
||||
if (!debug){
|
||||
List<ChunkHolder> holders = Lists.newArrayList(((ThreadedAnvilChunkStorageInterface)chunkMap).getChunksCM());
|
||||
Collections.shuffle(holders);
|
||||
for (ChunkHolder holder: holders){
|
||||
Optional<LevelChunk> optional = holder.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK).left();
|
||||
if (optional.isPresent()){
|
||||
holder.broadcastChanges(optional.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) level.getServer()).getTickRateManager();
|
||||
if (!trm.runsNormally() && trm.deeplyFrozen()) return;
|
||||
distanceManager.purgeStaleTickets();
|
||||
}
|
||||
|
||||
}
|
||||
+1
-13
@@ -1,34 +1,22 @@
|
||||
package carpet.mixins;
|
||||
|
||||
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;
|
||||
|
||||
@Mixin(ServerFunctionManager.class)
|
||||
public class ServerFunctionManager_tickMixin
|
||||
public class ServerFunctionManager_profilerMixin
|
||||
{
|
||||
@Shadow @Final MinecraftServer server;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
private void beforeDatapacks(CallbackInfo ci)
|
||||
{
|
||||
if (! ((MinecraftServerInterface)server).getTickRateManager().runsNormally())
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
private void afterDatapacks(CallbackInfo ci)
|
||||
@@ -1,59 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
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(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketListenerImpl_tickMixin
|
||||
{
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Shadow private double firstGoodX;
|
||||
|
||||
@Shadow private double firstGoodY;
|
||||
|
||||
@Shadow private double firstGoodZ;
|
||||
|
||||
@Inject(method = "handlePlayerInput", at = @At(value = "RETURN"))
|
||||
private void checkMoves(ServerboundPlayerInputPacket p, CallbackInfo ci)
|
||||
{
|
||||
if (p.getXxa() != 0.0F || p.getZza() != 0.0F || p.isJumping() || p.isShiftKeyDown())
|
||||
{
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().resetPlayerActivity();
|
||||
}
|
||||
}
|
||||
|
||||
// to skip reposition adjustment check
|
||||
private static long lastMovedTick = 0L;
|
||||
private static double lastMoved = 0.0D;
|
||||
|
||||
@Inject(method = "handleMovePlayer", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerPlayer;isSleeping()Z",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void checkMove(ServerboundMovePlayerPacket p, CallbackInfo ci)
|
||||
{
|
||||
double movedBy = player.position().distanceToSqr(firstGoodX, firstGoodY, firstGoodZ);
|
||||
if (movedBy == 0.0D) return;
|
||||
// corrective tick
|
||||
if (movedBy < 0.0009 && lastMoved > 0.0009 && Math.abs(player.getServer().getTickCount()-lastMovedTick-20)<2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (movedBy > 0.0D)
|
||||
{
|
||||
lastMoved = movedBy;
|
||||
lastMovedTick = player.getServer().getTickCount();
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().resetPlayerActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,8 @@ import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -18,9 +16,7 @@ import java.util.function.Supplier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.entity.raid.Raids;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.border.WorldBorder;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.WritableLevelData;
|
||||
|
||||
@@ -38,10 +34,6 @@ public abstract class ServerLevel_tickMixin extends Level implements LevelInterf
|
||||
return ((MinecraftServerInterface)getServer()).getTickRateManager();
|
||||
}
|
||||
|
||||
@Shadow protected abstract void runBlockEvents();
|
||||
|
||||
@Shadow protected abstract void tickTime();
|
||||
|
||||
private CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tick", at = @At(
|
||||
@@ -159,57 +151,4 @@ public abstract class ServerLevel_tickMixin extends Level implements LevelInterf
|
||||
}
|
||||
}
|
||||
|
||||
//// freeze
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/level/border/WorldBorder;tick()V"
|
||||
))
|
||||
private void tickWorldBorder(WorldBorder worldBorder)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) worldBorder.tick();
|
||||
}
|
||||
|
||||
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
|
||||
private void tickWeather(CallbackInfo ci)
|
||||
{
|
||||
if (!tickRateManager().runsNormally()) ci.cancel();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;tickTime()V"
|
||||
))
|
||||
private void tickTimeConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) tickTime();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;isDebug()Z"
|
||||
))
|
||||
private boolean tickPendingBlocks(ServerLevel serverWorld)
|
||||
{
|
||||
if (!tickRateManager().runsNormally()) return true;
|
||||
return serverWorld.isDebug(); // isDebug()
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/raid/Raids;tick()V"
|
||||
))
|
||||
private void tickConditionally(Raids raidManager)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) raidManager.tick();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;runBlockEvents()V"
|
||||
))
|
||||
private void tickConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) runBlockEvents();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Timer;
|
||||
import carpet.CarpetSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(Timer.class)
|
||||
public class Timer_tickSpeedMixin {
|
||||
@Redirect(method = "advanceTime", at = @At(
|
||||
value = "FIELD",
|
||||
target = "Lnet/minecraft/client/Timer;msPerTick:F"
|
||||
))
|
||||
private float adjustTickSpeed(Timer counter) {
|
||||
if (CarpetSettings.smoothClientAnimations)
|
||||
{
|
||||
Optional<TickRateManager> trm = ((MinecraftInterface)Minecraft.getInstance()).getTickRateManager();
|
||||
if (trm.isPresent() && trm.get().runsNormally())
|
||||
{
|
||||
return Math.max(50.0f, trm.get().mspt());
|
||||
}
|
||||
}
|
||||
return 50f;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(WorldBorder.class)
|
||||
public class WorldBorder_tickMixin
|
||||
public class WorldBorder_syncedWorldBorderMixin
|
||||
{
|
||||
@Shadow private WorldBorder.BorderExtent extent;
|
||||
|
||||
@@ -5,8 +5,6 @@ import carpet.CarpetExtension;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.api.settings.CarpetRule;
|
||||
import carpet.api.settings.InvalidRuleValueException;
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.api.settings.SettingsManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -14,10 +12,8 @@ import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NumericTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
|
||||
@@ -75,23 +71,6 @@ public class ClientNetworkHandler
|
||||
}
|
||||
}
|
||||
});
|
||||
dataHandlers.put("TickRate", (p, t) -> {
|
||||
TickRateManager tickRateManager = ((LevelInterface) p.clientLevel).tickRateManager();
|
||||
tickRateManager.setTickRate(((NumericTag) t).getAsFloat());
|
||||
});
|
||||
dataHandlers.put("TickingState", (p, t) -> {
|
||||
CompoundTag tickingState = (CompoundTag) t;
|
||||
TickRateManager tickRateManager = ((LevelInterface) p.clientLevel).tickRateManager();
|
||||
tickRateManager.setFrozenState(tickingState.getBoolean("is_paused"), tickingState.getBoolean("deepFreeze"));
|
||||
});
|
||||
dataHandlers.put("SuperHotState", (p, t) -> {
|
||||
TickRateManager tickRateManager = ((LevelInterface) p.clientLevel).tickRateManager();
|
||||
tickRateManager.setSuperHot(t.equals(ByteTag.ONE));
|
||||
});
|
||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> {
|
||||
TickRateManager tickRateManager = ((LevelInterface) p.clientLevel).tickRateManager();
|
||||
tickRateManager.setPlayerActiveTimeout(((NumericTag) t).getAsInt());
|
||||
});
|
||||
dataHandlers.put("scShape", (p, t) -> { // deprecated // and unused // should remove for 1.17
|
||||
if (CarpetClient.shapes != null)
|
||||
{
|
||||
|
||||
@@ -4,9 +4,7 @@ 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.ServerTickRateManager;
|
||||
import carpet.script.utils.SnoopyCommandSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -72,10 +70,11 @@ public class ServerNetworkHandler
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting || !validCarpetPlayers.contains(player))
|
||||
{
|
||||
return;
|
||||
//return;
|
||||
}
|
||||
DataBuilder data = DataBuilder.create(player.server).withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||
player.connection.send(data.build());
|
||||
// noop, used to send ticking information
|
||||
//DataBuilder data = DataBuilder.create(player.server);//.withTickRate().withFrozenState().withTickPlayerActiveTimeout(); // .withSuperHotState()
|
||||
//player.connection.send(data.build());
|
||||
}
|
||||
|
||||
private static void handleClientCommand(ServerPlayer player, CompoundTag commandData)
|
||||
@@ -140,54 +139,6 @@ public class ServerNetworkHandler
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateTickSpeedToConnectedPlayers(MinecraftServer server)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(DataBuilder.create(player.server).withTickRate().build());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateFrozenStateToConnectedPlayers(MinecraftServer server)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(DataBuilder.create(player.server).withFrozenState().build());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateSuperHotStateToConnectedPlayers(MinecraftServer server)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(DataBuilder.create(player.server).withSuperHotState().build());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateTickPlayerActiveTimeoutToConnectedPlayers(MinecraftServer server)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (ServerPlayer player : validCarpetPlayers)
|
||||
{
|
||||
player.connection.send(DataBuilder.create(player.server).withTickPlayerActiveTimeout().build());
|
||||
}
|
||||
}
|
||||
|
||||
public static void broadcastCustomCommand(String command, Tag data)
|
||||
{
|
||||
if (CarpetSettings.superSecretSetting)
|
||||
@@ -249,6 +200,7 @@ public class ServerNetworkHandler
|
||||
private static class DataBuilder
|
||||
{
|
||||
private CompoundTag tag;
|
||||
// unused now, but hey
|
||||
private MinecraftServer server;
|
||||
|
||||
private static DataBuilder create(final MinecraftServer server)
|
||||
@@ -262,37 +214,6 @@ public class ServerNetworkHandler
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private DataBuilder withTickRate()
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) server).getTickRateManager();
|
||||
tag.putFloat("TickRate", trm.tickrate());
|
||||
return this;
|
||||
}
|
||||
|
||||
private DataBuilder withFrozenState()
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) server).getTickRateManager();
|
||||
CompoundTag tickingState = new CompoundTag();
|
||||
tickingState.putBoolean("is_paused", trm.gameIsPaused());
|
||||
tickingState.putBoolean("deepFreeze", trm.deeplyFrozen());
|
||||
tag.put("TickingState", tickingState);
|
||||
return this;
|
||||
}
|
||||
|
||||
private DataBuilder withSuperHotState()
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) server).getTickRateManager();
|
||||
tag.putBoolean("SuperHotState", trm.isSuperHot());
|
||||
return this;
|
||||
}
|
||||
|
||||
private DataBuilder withTickPlayerActiveTimeout()
|
||||
{
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) server).getTickRateManager();
|
||||
tag.putInt("TickPlayerActiveTimeout", trm.getPlayerActiveTimeout());
|
||||
return this;
|
||||
}
|
||||
|
||||
private DataBuilder withRule(CarpetRule<?> rule)
|
||||
{
|
||||
CompoundTag rules = (CompoundTag) tag.get("Rules");
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package carpet.patches;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.minecraft.util.profiling.ProfileResults;
|
||||
import net.minecraft.util.profiling.ResultField;
|
||||
|
||||
public class CopyProfilerResult implements ProfileResults {
|
||||
int startI, endI;
|
||||
long startL, endL;
|
||||
public CopyProfilerResult(int startI, long startL, int endI, long endL)
|
||||
{
|
||||
this.startI = startI;
|
||||
this.startL = startL;
|
||||
this.endI = endI;
|
||||
this.endL = endL;
|
||||
}
|
||||
@Override
|
||||
public List<ResultField> getTimes(String parentPath) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveResults(Path path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartTimeNano() {
|
||||
return startL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartTimeTicks() {
|
||||
return startI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndTimeNano() {
|
||||
return endL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEndTimeTicks() {
|
||||
return endI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProfilerResults() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1369,7 +1369,7 @@ public class CarpetEventServer
|
||||
|
||||
public void tick()
|
||||
{
|
||||
if (Carpet.isTickProcessingPaused(scriptServer.server))
|
||||
if (Vanilla.isTickProcessingPaused(scriptServer.server))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,11 +131,6 @@ public class Carpet
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isTickProcessingPaused(MinecraftServer server)
|
||||
{
|
||||
return !((MinecraftServerInterface)server).getTickRateManager().runsNormally();
|
||||
}
|
||||
|
||||
public static void handleExtensionsAPI(CarpetExpression expression)
|
||||
{
|
||||
CarpetServer.extensions.forEach(e -> e.scarpetApi(expression));
|
||||
|
||||
@@ -367,4 +367,9 @@ public class Vanilla
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTickProcessingPaused(MinecraftServer server)
|
||||
{
|
||||
return !((MinecraftServerInterface)server).getTickRateManager().runsNormally();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,11 +32,11 @@
|
||||
"MinecraftServer_tickspeedMixin",
|
||||
"Level_tickMixin",
|
||||
"ServerLevel_tickMixin",
|
||||
"BoundTickingBlockEntity_tickMixin",
|
||||
"ServerChunkCache_tickMixin",
|
||||
"ChunkMap_tickMixin",
|
||||
"ServerFunctionManager_tickMixin",
|
||||
"WorldBorder_tickMixin",
|
||||
"BoundTickingBlockEntity_profilerMixin",
|
||||
"ServerChunkCache_profilerMixin",
|
||||
"ChunkMap_profilerMixin",
|
||||
"ServerFunctionManager_profilerMixin",
|
||||
"WorldBorder_syncedWorldBorderMixin",
|
||||
"ChunkMap_scarpetChunkCreationMixin",
|
||||
"LevelEntityGetterAdapter_scarpetMixin",
|
||||
"ChunkHolder_scarpetChunkCreationMixin",
|
||||
@@ -54,7 +54,6 @@
|
||||
"Villager_aiMixin",
|
||||
"Player_fakePlayersMixin",
|
||||
"ServerGamePacketListenerImpl_coreMixin",
|
||||
"ServerGamePacketListenerImpl_tickMixin",
|
||||
"MinecraftServer_scarpetMixin",
|
||||
"ExperienceOrb_xpNoCooldownMixin",
|
||||
"Player_xpNoCooldownMixin",
|
||||
@@ -67,7 +66,6 @@
|
||||
"PistonStructureResolver_pushLimitMixin",
|
||||
"PoweredRailBlock_powerLimitMixin",
|
||||
"LivingEntity_maxCollisionsMixin",
|
||||
"LivingEntity_tickSpeedMixin",
|
||||
"Level_getOtherEntitiesLimited",
|
||||
"CoralPlantBlock_renewableCoralMixin",
|
||||
"CoralFanBlock_renewableCoralMixin",
|
||||
@@ -191,7 +189,6 @@
|
||||
"client": [
|
||||
"ClientLevel_tickSpeedMixin",
|
||||
"ShulkerBoxAccessMixin",
|
||||
"Timer_tickSpeedMixin",
|
||||
"MinecraftMixin",
|
||||
"Minecraft_pausedShakeMixin",
|
||||
"LevelRenderer_pausedShakeMixin",
|
||||
|
||||
Reference in new issue
Block a user