tickspeed server - client separation.
This commit is contained in:
1 parent
755ec1daa8
commit
e0a3060339
21 files changed
+503
-235
No files matched your search
@@ -79,8 +79,8 @@ public class TickCommand
|
|||||||
|
|
||||||
private static int queryTps(CommandSourceStack source)
|
private static int queryTps(CommandSourceStack source)
|
||||||
{
|
{
|
||||||
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", TickSpeed.tickrate));
|
Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f)));
|
||||||
return (int)TickSpeed.tickrate;
|
return (int)(float)TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int setWarp(CommandSourceStack source, int advance, String tail_command)
|
private static int setWarp(CommandSourceStack source, int advance, String tail_command)
|
||||||
@@ -132,9 +132,9 @@ public class TickCommand
|
|||||||
|
|
||||||
private static int toggleSuperHot(CommandSourceStack source)
|
private static int toggleSuperHot(CommandSourceStack source)
|
||||||
{
|
{
|
||||||
TickSpeed.is_superHot = !TickSpeed.is_superHot;
|
TickSpeed.gTRM().ifPresent(trm -> trm.is_superHot = !trm.is_superHot);
|
||||||
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers();
|
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers(source.getServer());
|
||||||
if (TickSpeed.is_superHot)
|
if (TickSpeed.gTRM().map(trm -> trm.is_superHot).orElse(false))
|
||||||
{
|
{
|
||||||
Messenger.m(source, "gi Superhot enabled");
|
Messenger.m(source, "gi Superhot enabled");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package carpet.fakes;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
|
import carpet.helpers.TickRateManager;
|
||||||
import carpet.script.CarpetScriptServer;
|
import carpet.script.CarpetScriptServer;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
@@ -23,4 +24,6 @@ public interface MinecraftServerInterface
|
|||||||
|
|
||||||
void addScriptServer(CarpetScriptServer scriptServer);
|
void addScriptServer(CarpetScriptServer scriptServer);
|
||||||
CarpetScriptServer getScriptServer();
|
CarpetScriptServer getScriptServer();
|
||||||
|
|
||||||
|
TickRateManager getTickRateManager();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
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 java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
public class TickRateManager
|
||||||
|
{
|
||||||
|
public static final int PLAYER_GRACE = 2;
|
||||||
|
public float tickrate = 20.0f;
|
||||||
|
public float mspt = 50.0f;
|
||||||
|
public long time_bias = 0;
|
||||||
|
public long time_warp_start_time = 0;
|
||||||
|
public long time_warp_scheduled_ticks = 0;
|
||||||
|
public ServerPlayer time_advancerer = null;
|
||||||
|
public String tick_warp_callback = null;
|
||||||
|
public CommandSourceStack tick_warp_sender = null;
|
||||||
|
public int player_active_timeout = 0;
|
||||||
|
public boolean process_entities = true;
|
||||||
|
private boolean deepFreeze = false;
|
||||||
|
private boolean is_paused = false;
|
||||||
|
public boolean is_superHot = false;
|
||||||
|
|
||||||
|
private MinecraftServer server;
|
||||||
|
|
||||||
|
public TickRateManager(MinecraftServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 boolean isPaused()
|
||||||
|
{
|
||||||
|
return is_paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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
|
||||||
|
*/
|
||||||
|
public void setFrozenState(boolean isPaused, boolean isDeepFreeze)
|
||||||
|
{
|
||||||
|
is_paused = isPaused;
|
||||||
|
deepFreeze = isPaused ? isDeepFreeze : false;
|
||||||
|
ServerNetworkHandler.updateFrozenStateToConnectedPlayers(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void reset_player_active_timeout()
|
||||||
|
{
|
||||||
|
if (player_active_timeout < PLAYER_GRACE)
|
||||||
|
{
|
||||||
|
player_active_timeout = PLAYER_GRACE;
|
||||||
|
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component tickrate_advance(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
||||||
|
{
|
||||||
|
if (0 == advance)
|
||||||
|
{
|
||||||
|
tick_warp_callback = null;
|
||||||
|
if (source != tick_warp_sender)
|
||||||
|
{
|
||||||
|
tick_warp_sender = null;
|
||||||
|
}
|
||||||
|
if (time_bias > 0)
|
||||||
|
{
|
||||||
|
finish_time_warp();
|
||||||
|
tick_warp_sender = null;
|
||||||
|
return Messenger.c("gi Warp interrupted");
|
||||||
|
}
|
||||||
|
return Messenger.c("ri No warp in progress");
|
||||||
|
}
|
||||||
|
if (time_bias > 0)
|
||||||
|
{
|
||||||
|
String who = "Another player";
|
||||||
|
if (time_advancerer != null)
|
||||||
|
{
|
||||||
|
who = time_advancerer.getScoreboardName();
|
||||||
|
}
|
||||||
|
return Messenger.c("l " + who + " is already advancing time at the moment. Try later or ask them");
|
||||||
|
}
|
||||||
|
time_advancerer = player;
|
||||||
|
time_warp_start_time = System.nanoTime();
|
||||||
|
time_warp_scheduled_ticks = advance;
|
||||||
|
time_bias = advance;
|
||||||
|
tick_warp_callback = callback;
|
||||||
|
tick_warp_sender = source;
|
||||||
|
return Messenger.c("gi Warp speed ....");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish_time_warp()
|
||||||
|
{
|
||||||
|
|
||||||
|
long completed_ticks = time_warp_scheduled_ticks - time_bias;
|
||||||
|
double milis_to_complete = System.nanoTime() - time_warp_start_time;
|
||||||
|
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;
|
||||||
|
time_warp_scheduled_ticks = 0;
|
||||||
|
time_warp_start_time = 0;
|
||||||
|
if (tick_warp_callback != null)
|
||||||
|
{
|
||||||
|
Commands icommandmanager = tick_warp_sender.getServer().getCommands();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
icommandmanager.performPrefixedCommand(tick_warp_sender, tick_warp_callback);
|
||||||
|
}
|
||||||
|
catch (Throwable var23)
|
||||||
|
{
|
||||||
|
if (time_advancerer != null)
|
||||||
|
{
|
||||||
|
Messenger.m(time_advancerer, "r Command Callback failed - unknown error: ", "rb /" + tick_warp_callback, "/" + tick_warp_callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tick_warp_callback = null;
|
||||||
|
tick_warp_sender = null;
|
||||||
|
}
|
||||||
|
if (time_advancerer != null)
|
||||||
|
{
|
||||||
|
Messenger.m(time_advancerer, String.format("gi ... Time warp completed with %d tps, or %.2f mspt", tps, mspt));
|
||||||
|
time_advancerer = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Messenger.print_server_message(CarpetServer.minecraft_server, String.format("... Time warp completed with %d tps, or %.2f mspt", tps, mspt));
|
||||||
|
}
|
||||||
|
time_bias = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean continueWarp()
|
||||||
|
{
|
||||||
|
if (!process_entities)
|
||||||
|
// Returning false so we don't have to run at max speed when doing nothing
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (time_bias > 0)
|
||||||
|
{
|
||||||
|
if (time_bias == time_warp_scheduled_ticks) //first call after previous tick, adjust start time
|
||||||
|
{
|
||||||
|
time_warp_start_time = System.nanoTime();
|
||||||
|
}
|
||||||
|
time_bias -= 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
finish_time_warp();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick()
|
||||||
|
{
|
||||||
|
if (player_active_timeout > 0)
|
||||||
|
{
|
||||||
|
player_active_timeout--;
|
||||||
|
}
|
||||||
|
if (is_paused)
|
||||||
|
{
|
||||||
|
process_entities = player_active_timeout >= PLAYER_GRACE;
|
||||||
|
}
|
||||||
|
else if (is_superHot)
|
||||||
|
{
|
||||||
|
process_entities = player_active_timeout > 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
process_entities = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
public void tickrate(float rate)
|
||||||
|
{
|
||||||
|
tickrate(rate, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tickrate(float rate, boolean update)
|
||||||
|
{
|
||||||
|
tickrate = rate;
|
||||||
|
long msptt = (long) (1000.0 / tickrate);
|
||||||
|
if (msptt <= 0L)
|
||||||
|
{
|
||||||
|
msptt = 1L;
|
||||||
|
tickrate = 1000.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mspt = msptt;
|
||||||
|
|
||||||
|
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, Float.valueOf(tickrate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServerNetworkHandler.updateTickSpeedToConnectedPlayers(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BiConsumer<String, Float> addTickrateListener(String modId, BiConsumer<String, Float> tickrateListener)
|
||||||
|
{
|
||||||
|
synchronized (tickrateListeners)
|
||||||
|
{
|
||||||
|
tickrateListeners.put(modId, tickrateListener);
|
||||||
|
}
|
||||||
|
return this::tickrateChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,10 @@ package carpet.helpers;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
import carpet.fakes.MinecraftServerInterface;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -13,40 +16,38 @@ import carpet.utils.Messenger;
|
|||||||
|
|
||||||
public class TickSpeed
|
public class TickSpeed
|
||||||
{
|
{
|
||||||
public static final int PLAYER_GRACE = 2;
|
public static Optional<TickRateManager> gTRM() {
|
||||||
public static float tickrate = 20.0f;
|
if (CarpetServer.minecraft_server == null) return Optional.empty();
|
||||||
public static float mspt = 50.0f;
|
return Optional.of(((MinecraftServerInterface)CarpetServer.minecraft_server).getTickRateManager());
|
||||||
public static long time_bias = 0;
|
}
|
||||||
public static long time_warp_start_time = 0;
|
|
||||||
public static long time_warp_scheduled_ticks = 0;
|
public static boolean process_entities() {
|
||||||
public static ServerPlayer time_advancerer = null;
|
return gTRM().map(trm -> trm.process_entities).orElse(true);
|
||||||
public static String tick_warp_callback = null;
|
}
|
||||||
public static CommandSourceStack tick_warp_sender = null;
|
|
||||||
public static int player_active_timeout = 0;
|
public static float mspt() {
|
||||||
public static boolean process_entities = true;
|
return gTRM().map(trm -> trm.mspt).orElse(50.0f);
|
||||||
private static boolean deepFreeze = false;
|
}
|
||||||
private static boolean is_paused = false;
|
|
||||||
public static boolean is_superHot = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Whether or not the game is in a frozen state.
|
* @return Whether or not the game is in a frozen state.
|
||||||
* You should normally use {@link #process_entities} instead,
|
* You should normally use {@link #process_entities()} instead,
|
||||||
* since that one accounts for tick steps and superhot
|
* since that one accounts for tick steps and superhot
|
||||||
*/
|
*/
|
||||||
public static boolean isPaused() {
|
public static boolean isPaused() {
|
||||||
return is_paused;
|
return gTRM().map(TickRateManager::isPaused).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the game is deeply frozen.
|
* Whether or not the game is deeply frozen.
|
||||||
* This can be used for things that you may not normally want
|
* This can be used for things that you may not normally want
|
||||||
* to freeze, but may need to in some situations.
|
* to freeze, but may need to in some situations.
|
||||||
* This should be checked with {@link #process_entities} to make sure the
|
* This should be checked with {@link #process_entities()} to make sure the
|
||||||
* current tick is actually frozen, not only the game
|
* current tick is actually frozen, not only the game
|
||||||
* @return Whether or not the game is deeply frozen.
|
* @return Whether or not the game is deeply frozen.
|
||||||
*/
|
*/
|
||||||
public static boolean deeplyFrozen() {
|
public static boolean deeplyFrozen() {
|
||||||
return deepFreeze;
|
return gTRM().map(TickRateManager::deeplyFrozen).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,9 +57,7 @@ public class TickSpeed
|
|||||||
* @param isDeepFreeze Whether or not the game is deeply frozen
|
* @param isDeepFreeze Whether or not the game is deeply frozen
|
||||||
*/
|
*/
|
||||||
public static void setFrozenState(boolean isPaused, boolean isDeepFreeze) {
|
public static void setFrozenState(boolean isPaused, boolean isDeepFreeze) {
|
||||||
is_paused = isPaused;
|
gTRM().ifPresent(trm -> trm.setFrozenState(isPaused, isDeepFreeze));
|
||||||
deepFreeze = isPaused ? isDeepFreeze : false;
|
|
||||||
ServerNetworkHandler.updateFrozenStateToConnectedPlayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,132 +69,111 @@ public class TickSpeed
|
|||||||
|
|
||||||
public static void reset_player_active_timeout()
|
public static void reset_player_active_timeout()
|
||||||
{
|
{
|
||||||
if (player_active_timeout < PLAYER_GRACE)
|
gTRM().ifPresent(TickRateManager::reset_player_active_timeout);
|
||||||
{
|
|
||||||
player_active_timeout = PLAYER_GRACE;
|
|
||||||
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset()
|
public static void reset()
|
||||||
{
|
{
|
||||||
tickrate = 20.0f;
|
gTRM().ifPresent(TickRateManager::reset);
|
||||||
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 static void add_ticks_to_run_in_pause(int ticks)
|
public static void add_ticks_to_run_in_pause(int ticks)
|
||||||
{
|
{
|
||||||
player_active_timeout = PLAYER_GRACE+ticks;
|
gTRM().ifPresent(trm -> trm.add_ticks_to_run_in_pause(ticks));
|
||||||
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component tickrate_advance(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
public static Component tickrate_advance(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
||||||
{
|
{
|
||||||
if (0 == advance)
|
return gTRM().map(trm -> trm.tickrate_advance(player, advance, callback, source)).orElse(Messenger.c("ri Tickrate management not enabled"));
|
||||||
{
|
|
||||||
tick_warp_callback = null;
|
|
||||||
if (source != tick_warp_sender) tick_warp_sender = null;
|
|
||||||
if (time_bias > 0)
|
|
||||||
{
|
|
||||||
finish_time_warp();
|
|
||||||
tick_warp_sender = null;
|
|
||||||
return Messenger.c("gi Warp interrupted");
|
|
||||||
}
|
|
||||||
return Messenger.c("ri No warp in progress");
|
|
||||||
}
|
|
||||||
if (time_bias > 0)
|
|
||||||
{
|
|
||||||
String who = "Another player";
|
|
||||||
if (time_advancerer != null) who = time_advancerer.getScoreboardName();
|
|
||||||
return Messenger.c("l "+who+" is already advancing time at the moment. Try later or ask them");
|
|
||||||
}
|
|
||||||
time_advancerer = player;
|
|
||||||
time_warp_start_time = System.nanoTime();
|
|
||||||
time_warp_scheduled_ticks = advance;
|
|
||||||
time_bias = advance;
|
|
||||||
tick_warp_callback = callback;
|
|
||||||
tick_warp_sender = source;
|
|
||||||
return Messenger.c("gi Warp speed ....");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void finish_time_warp()
|
public static void finish_time_warp()
|
||||||
{
|
{
|
||||||
|
gTRM().ifPresent(TickRateManager::finish_time_warp);
|
||||||
long completed_ticks = time_warp_scheduled_ticks - time_bias;
|
|
||||||
double milis_to_complete = System.nanoTime()-time_warp_start_time;
|
|
||||||
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;
|
|
||||||
time_warp_scheduled_ticks = 0;
|
|
||||||
time_warp_start_time = 0;
|
|
||||||
if (tick_warp_callback != null)
|
|
||||||
{
|
|
||||||
Commands icommandmanager = tick_warp_sender.getServer().getCommands();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
icommandmanager.performPrefixedCommand(tick_warp_sender, tick_warp_callback);
|
|
||||||
}
|
|
||||||
catch (Throwable var23)
|
|
||||||
{
|
|
||||||
if (time_advancerer != null)
|
|
||||||
{
|
|
||||||
Messenger.m(time_advancerer, "r Command Callback failed - unknown error: ", "rb /"+tick_warp_callback,"/"+tick_warp_callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tick_warp_callback = null;
|
|
||||||
tick_warp_sender = null;
|
|
||||||
}
|
|
||||||
if (time_advancerer != null)
|
|
||||||
{
|
|
||||||
Messenger.m(time_advancerer, String.format("gi ... Time warp completed with %d tps, or %.2f mspt",tps, mspt ));
|
|
||||||
time_advancerer = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Messenger.print_server_message(CarpetServer.minecraft_server, String.format("... Time warp completed with %d tps, or %.2f mspt",tps, mspt ));
|
|
||||||
}
|
|
||||||
time_bias = 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean continueWarp()
|
public static boolean continueWarp()
|
||||||
{
|
{
|
||||||
if (!process_entities)
|
return gTRM().map(TickRateManager::continueWarp).orElse(false);
|
||||||
// Returning false so we don't have to run at max speed when doing nothing
|
|
||||||
return false;
|
|
||||||
if (time_bias > 0)
|
|
||||||
{
|
|
||||||
if (time_bias == time_warp_scheduled_ticks) //first call after previous tick, adjust start time
|
|
||||||
{
|
|
||||||
time_warp_start_time = System.nanoTime();
|
|
||||||
}
|
|
||||||
time_bias -= 1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
finish_time_warp();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void tick()
|
public static void tick()
|
||||||
|
{
|
||||||
|
gTRM().ifPresent(TickRateManager::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.tickrate(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)
|
if (player_active_timeout > 0)
|
||||||
{
|
{
|
||||||
@@ -203,7 +181,7 @@ public class TickSpeed
|
|||||||
}
|
}
|
||||||
if (is_paused)
|
if (is_paused)
|
||||||
{
|
{
|
||||||
process_entities = player_active_timeout >= PLAYER_GRACE;
|
process_entities = player_active_timeout >= TickRateManager.PLAYER_GRACE;
|
||||||
}
|
}
|
||||||
else if (is_superHot)
|
else if (is_superHot)
|
||||||
{
|
{
|
||||||
@@ -214,62 +192,6 @@ public class TickSpeed
|
|||||||
process_entities = true;
|
process_entities = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//unused - mod compat reasons
|
|
||||||
public static void tickrate(float rate) {tickrate(rate, true);}
|
|
||||||
public static void tickrate(float rate, boolean update)
|
|
||||||
{
|
|
||||||
tickrate = rate;
|
|
||||||
long mspt = (long)(1000.0 / tickrate);
|
|
||||||
if (mspt <= 0L)
|
|
||||||
{
|
|
||||||
mspt = 1L;
|
|
||||||
tickrate = 1000.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
TickSpeed.mspt = mspt;
|
|
||||||
|
|
||||||
if (update) notifyTickrateListeners("carpet");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static 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 static 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, Float.valueOf(tickrate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ServerNetworkHandler.updateTickSpeedToConnectedPlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BiConsumer<String, Float> addTickrateListener(String modId, BiConsumer<String, Float> tickrateListener)
|
|
||||||
{
|
|
||||||
synchronized (tickrateListeners)
|
|
||||||
{
|
|
||||||
tickrateListeners.put(modId, tickrateListener);
|
|
||||||
}
|
|
||||||
return TickSpeed::tickrateChanged;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package carpet.logging;
|
package carpet.logging;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
|
import carpet.fakes.MinecraftServerInterface;
|
||||||
import carpet.helpers.HopperCounter;
|
import carpet.helpers.HopperCounter;
|
||||||
|
import carpet.helpers.TickRateManager;
|
||||||
import carpet.helpers.TickSpeed;
|
import carpet.helpers.TickSpeed;
|
||||||
import carpet.logging.logHelpers.PacketCounter;
|
import carpet.logging.logHelpers.PacketCounter;
|
||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
@@ -117,16 +119,17 @@ public class HUDController
|
|||||||
private static Component [] send_tps_display(MinecraftServer server)
|
private static Component [] send_tps_display(MinecraftServer server)
|
||||||
{
|
{
|
||||||
final OptionalDouble averageTPS = Arrays.stream(server.tickTimes).average();
|
final OptionalDouble averageTPS = Arrays.stream(server.tickTimes).average();
|
||||||
|
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
|
||||||
if (averageTPS.isEmpty())
|
if (averageTPS.isEmpty())
|
||||||
{
|
{
|
||||||
return new Component[]{Component.literal("No TPS data available")};
|
return new Component[]{Component.literal("No TPS data available")};
|
||||||
}
|
}
|
||||||
double MSPT = Arrays.stream(server.tickTimes).average().getAsDouble() * 1.0E-6D;
|
double MSPT = Arrays.stream(server.tickTimes).average().getAsDouble() * 1.0E-6D;
|
||||||
double TPS = 1000.0D / Math.max((TickSpeed.time_warp_start_time != 0)?0.0:TickSpeed.mspt, MSPT);
|
double TPS = 1000.0D / Math.max((trm.time_warp_start_time != 0)?0.0:trm.mspt, MSPT);
|
||||||
if (TickSpeed.isPaused()) {
|
if (TickSpeed.isPaused()) {
|
||||||
TPS = 0;
|
TPS = 0;
|
||||||
}
|
}
|
||||||
String color = Messenger.heatmap_color(MSPT,TickSpeed.mspt);
|
String color = Messenger.heatmap_color(MSPT,trm.mspt);
|
||||||
return new Component[]{Messenger.c(
|
return new Component[]{Messenger.c(
|
||||||
"g TPS: ", String.format(Locale.US, "%s %.1f",color, TPS),
|
"g TPS: ", String.format(Locale.US, "%s %.1f",color, TPS),
|
||||||
"g MSPT: ", String.format(Locale.US,"%s %.1f", color, MSPT))};
|
"g MSPT: ", String.format(Locale.US,"%s %.1f", color, MSPT))};
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class BoundTickingBlockEntity_tickMixin<T extends BlockEntity>
|
|||||||
))
|
))
|
||||||
private void checkProcessBEs(BlockEntityTicker<T> blockEntityTicker, Level world, BlockPos pos, BlockState state, T 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 (TickSpeed.process_entities()) blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ public class DistanceManager_tickMixin
|
|||||||
{
|
{
|
||||||
// pausing expiry of tickets
|
// pausing expiry of tickets
|
||||||
// that will prevent also chunks from unloading, so require a deep frozen state
|
// that will prevent also chunks from unloading, so require a deep frozen state
|
||||||
if (!TickSpeed.process_entities && TickSpeed.deeplyFrozen()) ticketTickCounter--;
|
if (!TickSpeed.process_entities() && TickSpeed.deeplyFrozen()) ticketTickCounter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ public class LevelRenderer_pausedShakeMixin
|
|||||||
private float changeTickPhase(float previous)
|
private float changeTickPhase(float previous)
|
||||||
{
|
{
|
||||||
initial = previous;
|
initial = previous;
|
||||||
if (!TickSpeed.process_entities)
|
if (!TickSpeed.process_entitiesClient())
|
||||||
return ((MinecraftClientInferface)minecraft).getPausedTickDelta();
|
return ((MinecraftClientInferface)minecraft).getPausedTickDelta();
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,18 @@ public abstract class Level_tickMixin implements LevelInterface
|
|||||||
@Inject(method = "guardEntityTick", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "guardEntityTick", at = @At("HEAD"), cancellable = true)
|
||||||
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
|
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if (!(TickSpeed.process_entities || (e instanceof Player) || (TickSpeed.is_superHot && isClientSide && e.getControllingPassenger() instanceof Player)))
|
// 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))
|
||||||
|
{
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(TickSpeed.gTRM().map(trm -> trm.process_entities).orElse(true) || (e instanceof Player)))
|
||||||
|
{
|
||||||
|
ci.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
entitySection = CarpetProfiler.start_entity_section((Level) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
|
entitySection = CarpetProfiler.start_entity_section((Level) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,15 @@ public class MinecraftMixin
|
|||||||
@Inject(at = @At("HEAD"), method = "tick")
|
@Inject(at = @At("HEAD"), method = "tick")
|
||||||
private void onClientTick(CallbackInfo info) {
|
private void onClientTick(CallbackInfo info) {
|
||||||
if (this.level != null) {
|
if (this.level != null) {
|
||||||
if (CarpetServer.minecraft_server == null)
|
TickSpeed.tickClient();
|
||||||
TickSpeed.tick();
|
if (CarpetServer.minecraft_server == null) // remote client only ? no - now any client
|
||||||
if (!TickSpeed.process_entities)
|
{
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// hmm, server should tick, rgiht?
|
||||||
|
//TickSpeed.tick();
|
||||||
|
}
|
||||||
|
if (!TickSpeed.process_entitiesClient())
|
||||||
CarpetClient.shapes.renewShapes();
|
CarpetClient.shapes.renewShapes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
|
|||||||
))
|
))
|
||||||
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
|
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if (!TickSpeed.process_entities)
|
if (!TickSpeed.process_entities())
|
||||||
return;
|
return;
|
||||||
TICK.onTick((MinecraftServer) (Object) this);
|
TICK.onTick((MinecraftServer) (Object) this);
|
||||||
NETHER_TICK.onTick((MinecraftServer) (Object) this);
|
NETHER_TICK.onTick((MinecraftServer) (Object) this);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import carpet.fakes.MinecraftServerInterface;
|
||||||
|
import carpet.helpers.TickRateManager;
|
||||||
import carpet.helpers.TickSpeed;
|
import carpet.helpers.TickSpeed;
|
||||||
import carpet.patches.CopyProfilerResult;
|
import carpet.patches.CopyProfilerResult;
|
||||||
import carpet.utils.CarpetProfiler;
|
import carpet.utils.CarpetProfiler;
|
||||||
@@ -25,7 +27,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
|
||||||
@Mixin(value = MinecraftServer.class, priority = Integer.MAX_VALUE - 10)
|
@Mixin(value = MinecraftServer.class, priority = Integer.MAX_VALUE - 10)
|
||||||
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask>
|
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask> implements MinecraftServerInterface
|
||||||
{
|
{
|
||||||
@Shadow private volatile boolean running;
|
@Shadow private volatile boolean running;
|
||||||
|
|
||||||
@@ -67,6 +69,20 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
|||||||
|
|
||||||
private float carpetMsptAccum = 0.0f;
|
private float carpetMsptAccum = 0.0f;
|
||||||
|
|
||||||
|
private TickRateManager tickRateManager;
|
||||||
|
|
||||||
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
|
private void onInit(CallbackInfo ci)
|
||||||
|
{
|
||||||
|
tickRateManager = new TickRateManager((MinecraftServer)(Object)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TickRateManager getTickRateManager()
|
||||||
|
{
|
||||||
|
return tickRateManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To ensure compatibility with other mods we should allow milliseconds
|
* To ensure compatibility with other mods we should allow milliseconds
|
||||||
*/
|
*/
|
||||||
@@ -95,32 +111,33 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
|||||||
}
|
}
|
||||||
long msThisTick = 0L;
|
long msThisTick = 0L;
|
||||||
long long_1 = 0L;
|
long long_1 = 0L;
|
||||||
if (TickSpeed.time_warp_start_time != 0 && TickSpeed.continueWarp())
|
float mspt = tickRateManager.mspt;
|
||||||
|
if (tickRateManager.time_warp_start_time != 0 && TickSpeed.continueWarp())
|
||||||
{
|
{
|
||||||
//making sure server won't flop after the warp or if the warp is interrupted
|
//making sure server won't flop after the warp or if the warp is interrupted
|
||||||
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
|
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
|
||||||
carpetMsptAccum = TickSpeed.mspt;
|
carpetMsptAccum = mspt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Math.abs(carpetMsptAccum - TickSpeed.mspt) > 1.0f)
|
if (Math.abs(carpetMsptAccum - mspt) > 1.0f)
|
||||||
{
|
{
|
||||||
// Tickrate changed. Ensure that we use the correct value.
|
// Tickrate changed. Ensure that we use the correct value.
|
||||||
carpetMsptAccum = TickSpeed.mspt;
|
carpetMsptAccum = mspt;
|
||||||
}
|
}
|
||||||
|
|
||||||
msThisTick = (long)carpetMsptAccum; // regular tick
|
msThisTick = (long)carpetMsptAccum; // regular tick
|
||||||
carpetMsptAccum += TickSpeed.mspt - msThisTick;
|
carpetMsptAccum += mspt - msThisTick;
|
||||||
|
|
||||||
long_1 = Util.getMillis() - this.nextTickTime;
|
long_1 = Util.getMillis() - this.nextTickTime;
|
||||||
}
|
}
|
||||||
//end tick deciding
|
//end tick deciding
|
||||||
//smoothed out delay to include mcpt component. With 50L gives defaults.
|
//smoothed out delay to include mcpt component. With 50L gives defaults.
|
||||||
if (long_1 > /*2000L*/1000L+20*TickSpeed.mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*TickSpeed.mspt)
|
if (long_1 > /*2000L*/1000L+20*mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*mspt)
|
||||||
{
|
{
|
||||||
long long_2 = (long)(long_1 / TickSpeed.mspt);//50L;
|
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);
|
LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", long_1, long_2);
|
||||||
this.nextTickTime += (long)(long_2 * TickSpeed.mspt);//50L;
|
this.nextTickTime += (long)(long_2 * mspt);//50L;
|
||||||
this.lastOverloadWarning = this.nextTickTime;
|
this.lastOverloadWarning = this.nextTickTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +151,9 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
|||||||
//this.startMonitor(tickDurationMonitor);
|
//this.startMonitor(tickDurationMonitor);
|
||||||
this.startMetricsRecordingTick();
|
this.startMetricsRecordingTick();
|
||||||
this.profiler.push("tick");
|
this.profiler.push("tick");
|
||||||
this.tickServer(TickSpeed.time_warp_start_time != 0 ? ()->true : this::haveTime);
|
this.tickServer(TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0 ? ()->true : this::haveTime);
|
||||||
this.profiler.popPush("nextTickWait");
|
this.profiler.popPush("nextTickWait");
|
||||||
if (TickSpeed.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
|
if (TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0) // clearing all hanging tasks no matter what when warping
|
||||||
{
|
{
|
||||||
while(this.runEveryTask()) {Thread.yield();}
|
while(this.runEveryTask()) {Thread.yield();}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public abstract class PlayerTabOverlayMixin implements PlayerListHudInterface
|
|||||||
|
|
||||||
@Shadow private Component header;
|
@Shadow private Component header;
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasFooterOrHeader()
|
public boolean hasFooterOrHeader()
|
||||||
{
|
{
|
||||||
return footer != null || header != null;
|
return footer != null || header != null;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public abstract class ServerChunkCache_tickMixin
|
|||||||
private boolean skipChunkTicking(ServerLevel serverWorld)
|
private boolean skipChunkTicking(ServerLevel serverWorld)
|
||||||
{
|
{
|
||||||
boolean debug = serverWorld.isDebug();
|
boolean debug = serverWorld.isDebug();
|
||||||
if (!TickSpeed.process_entities)
|
if (!TickSpeed.process_entities())
|
||||||
{
|
{
|
||||||
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
|
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
|
||||||
// to be kept in sync with the original injection source
|
// to be kept in sync with the original injection source
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class ServerFunctionManager_tickMixin
|
|||||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||||
private void beforeDatapacks(CallbackInfo ci)
|
private void beforeDatapacks(CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if (!TickSpeed.process_entities) ci.cancel();
|
if (!TickSpeed.process_entities()) ci.cancel();
|
||||||
else
|
else
|
||||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,13 +159,13 @@ public abstract class ServerLevel_tickMixin extends Level
|
|||||||
))
|
))
|
||||||
private void tickWorldBorder(WorldBorder worldBorder)
|
private void tickWorldBorder(WorldBorder worldBorder)
|
||||||
{
|
{
|
||||||
if (TickSpeed.process_entities) worldBorder.tick();
|
if (TickSpeed.process_entities()) worldBorder.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
|
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
|
||||||
private void tickWeather(CallbackInfo ci)
|
private void tickWeather(CallbackInfo ci)
|
||||||
{
|
{
|
||||||
if (!TickSpeed.process_entities) ci.cancel();
|
if (!TickSpeed.process_entities()) ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "tick", at = @At(
|
@Redirect(method = "tick", at = @At(
|
||||||
@@ -174,7 +174,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
|||||||
))
|
))
|
||||||
private void tickTimeConditionally(ServerLevel serverWorld)
|
private void tickTimeConditionally(ServerLevel serverWorld)
|
||||||
{
|
{
|
||||||
if (TickSpeed.process_entities) tickTime();
|
if (TickSpeed.process_entities()) tickTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "tick", at = @At(
|
@Redirect(method = "tick", at = @At(
|
||||||
@@ -183,7 +183,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
|||||||
))
|
))
|
||||||
private boolean tickPendingBlocks(ServerLevel serverWorld)
|
private boolean tickPendingBlocks(ServerLevel serverWorld)
|
||||||
{
|
{
|
||||||
if (!TickSpeed.process_entities) return true;
|
if (!TickSpeed.process_entities()) return true;
|
||||||
return serverWorld.isDebug(); // isDebug()
|
return serverWorld.isDebug(); // isDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ public abstract class ServerLevel_tickMixin extends Level
|
|||||||
))
|
))
|
||||||
private void tickConditionally(Raids raidManager)
|
private void tickConditionally(Raids raidManager)
|
||||||
{
|
{
|
||||||
if (TickSpeed.process_entities) raidManager.tick();
|
if (TickSpeed.process_entities()) raidManager.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "tick", at = @At(
|
@Redirect(method = "tick", at = @At(
|
||||||
@@ -202,6 +202,6 @@ public abstract class ServerLevel_tickMixin extends Level
|
|||||||
))
|
))
|
||||||
private void tickConditionally(ServerLevel serverWorld)
|
private void tickConditionally(ServerLevel serverWorld)
|
||||||
{
|
{
|
||||||
if (TickSpeed.process_entities) runBlockEvents();
|
if (TickSpeed.process_entities()) runBlockEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,9 @@ public class Timer_tickSpeedMixin {
|
|||||||
target = "Lnet/minecraft/client/Timer;msPerTick:F"
|
target = "Lnet/minecraft/client/Timer;msPerTick:F"
|
||||||
))
|
))
|
||||||
private float adjustTickSpeed(Timer counter) {
|
private float adjustTickSpeed(Timer counter) {
|
||||||
if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entities)
|
if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entitiesClient())
|
||||||
{
|
{
|
||||||
return Math.max(50.0f, TickSpeed.mspt);
|
return Math.max(50.0f, TickSpeed.msptClient());
|
||||||
}
|
}
|
||||||
return 50f;
|
return 50f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,15 +65,15 @@ public class ClientNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrate(((NumericTag)t).getAsFloat(), false));
|
dataHandlers.put("TickRate", (p, t) -> TickSpeed.tickrateClient(((NumericTag)t).getAsFloat()));
|
||||||
dataHandlers.put("TickingState", (p, t) -> {
|
dataHandlers.put("TickingState", (p, t) -> {
|
||||||
CompoundTag tickingState = (CompoundTag)t;
|
CompoundTag tickingState = (CompoundTag)t;
|
||||||
TickSpeed.setFrozenState(tickingState.getBoolean("is_paused"), tickingState.getBoolean("deepFreeze"));
|
TickSpeed.setFrozenStateClient(tickingState.getBoolean("is_paused"), tickingState.getBoolean("deepFreeze"));
|
||||||
});
|
});
|
||||||
dataHandlers.put("SuperHotState", (p, t) -> {
|
dataHandlers.put("SuperHotState", (p, t) -> {
|
||||||
TickSpeed.is_superHot = ((ByteTag) t).equals(ByteTag.ONE);
|
TickSpeed.setSuperHotClient(((ByteTag) t).equals(ByteTag.ONE));
|
||||||
});
|
});
|
||||||
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.player_active_timeout = ((NumericTag)t).getAsInt());
|
dataHandlers.put("TickPlayerActiveTimeout", (p, t) -> TickSpeed.setPlayer_active_timeoutClient(((NumericTag)t).getAsInt()));
|
||||||
dataHandlers.put("scShape", (p, t) -> { // deprecated // and unused // should remove for 1.17
|
dataHandlers.put("scShape", (p, t) -> { // deprecated // and unused // should remove for 1.17
|
||||||
if (CarpetClient.shapes != null)
|
if (CarpetClient.shapes != null)
|
||||||
CarpetClient.shapes.addShape((CompoundTag)t);
|
CarpetClient.shapes.addShape((CompoundTag)t);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import net.minecraft.nbt.Tag;
|
|||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
public class ServerNetworkHandler
|
public class ServerNetworkHandler
|
||||||
@@ -144,10 +145,10 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateTickSpeedToConnectedPlayers()
|
public static void updateTickSpeedToConnectedPlayers(MinecraftServer server)
|
||||||
{
|
{
|
||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||||
CarpetClient.CARPET_CHANNEL,
|
CarpetClient.CARPET_CHANNEL,
|
||||||
@@ -156,10 +157,10 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateFrozenStateToConnectedPlayers()
|
public static void updateFrozenStateToConnectedPlayers(MinecraftServer server)
|
||||||
{
|
{
|
||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||||
CarpetClient.CARPET_CHANNEL,
|
CarpetClient.CARPET_CHANNEL,
|
||||||
@@ -168,10 +169,10 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateSuperHotStateToConnectedPlayers()
|
public static void updateSuperHotStateToConnectedPlayers(MinecraftServer server)
|
||||||
{
|
{
|
||||||
if(CarpetSettings.superSecretSetting) return;
|
if(CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||||
CarpetClient.CARPET_CHANNEL,
|
CarpetClient.CARPET_CHANNEL,
|
||||||
@@ -180,10 +181,10 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateTickPlayerActiveTimeoutToConnectedPlayers()
|
public static void updateTickPlayerActiveTimeoutToConnectedPlayers(MinecraftServer server)
|
||||||
{
|
{
|
||||||
if (CarpetSettings.superSecretSetting) return;
|
if (CarpetSettings.superSecretSetting) return;
|
||||||
for (ServerPlayer player : remoteCarpetPlayers.keySet())
|
for (ServerPlayer player : validCarpetPlayers)
|
||||||
{
|
{
|
||||||
player.connection.send(new ClientboundCustomPayloadPacket(
|
player.connection.send(new ClientboundCustomPayloadPacket(
|
||||||
CarpetClient.CARPET_CHANNEL,
|
CarpetClient.CARPET_CHANNEL,
|
||||||
@@ -256,7 +257,7 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
private DataBuilder withTickRate()
|
private DataBuilder withTickRate()
|
||||||
{
|
{
|
||||||
tag.putFloat("TickRate", TickSpeed.tickrate);
|
tag.putFloat("TickRate", TickSpeed.gTRM().map(trm -> trm.tickrate).orElse(20.0f));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
private DataBuilder withFrozenState()
|
private DataBuilder withFrozenState()
|
||||||
@@ -269,12 +270,12 @@ public class ServerNetworkHandler
|
|||||||
}
|
}
|
||||||
private DataBuilder withSuperHotState()
|
private DataBuilder withSuperHotState()
|
||||||
{
|
{
|
||||||
tag.putBoolean("SuperHotState", TickSpeed.is_superHot);
|
tag.putBoolean("SuperHotState", TickSpeed.gTRM().map(trm -> trm.is_superHot).orElse(false));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
private DataBuilder withTickPlayerActiveTimeout()
|
private DataBuilder withTickPlayerActiveTimeout()
|
||||||
{
|
{
|
||||||
tag.putInt("TickPlayerActiveTimeout", TickSpeed.player_active_timeout);
|
tag.putInt("TickPlayerActiveTimeout", TickSpeed.gTRM().map(trm -> trm.player_active_timeout).orElse(0));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
private DataBuilder withRule(CarpetRule<?> rule)
|
private DataBuilder withRule(CarpetRule<?> rule)
|
||||||
|
|||||||
@@ -89,13 +89,13 @@ public class TickSyncedBorderExtent implements WorldBorder.BorderExtent
|
|||||||
double ms;
|
double ms;
|
||||||
if (server == null)
|
if (server == null)
|
||||||
{
|
{
|
||||||
ms = TickSpeed.mspt;
|
ms = TickSpeed.mspt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ms = Arrays.stream(server.tickTimes).average().orElseThrow(IllegalStateException::new) * 1.0E-6D;
|
ms = Arrays.stream(server.tickTimes).average().orElseThrow(IllegalStateException::new) * 1.0E-6D;
|
||||||
}
|
}
|
||||||
double tps = 1_000.0D / Math.max((TickSpeed.time_warp_start_time != 0) ? 0.0 : TickSpeed.mspt, ms);
|
double tps = 1_000.0D / Math.max((TickSpeed.gTRM().map(trm -> trm.time_warp_start_time).orElse(0L) != 0) ? 0.0 : TickSpeed.mspt(), ms);
|
||||||
return (long) ((this.tickDuration - this.ticks) / tps * 1_000);
|
return (long) ((this.tickDuration - this.ticks) / tps * 1_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -136,7 +136,7 @@ public class Carpet
|
|||||||
|
|
||||||
public static boolean isTickProcessingPaused()
|
public static boolean isTickProcessingPaused()
|
||||||
{
|
{
|
||||||
return !TickSpeed.process_entities;
|
return !TickSpeed.process_entities();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleExtensionsAPI(CarpetExpression expression)
|
public static void handleExtensionsAPI(CarpetExpression expression)
|
||||||
|
|||||||
Reference in new issue
Block a user