Skip to content

Commit

Permalink
retire static TickSpeed. Use Server and Client synchronization agents.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed May 17, 2023
1 parent d0a7967 commit c6f52b3
Show file tree
Hide file tree
Showing 28 changed files with 490 additions and 398 deletions.
8 changes: 2 additions & 6 deletions src/main/java/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
import carpet.commands.PlayerCommand;
import carpet.commands.ProfileCommand;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.TickRateManager;
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.helpers.TickSpeed;
import carpet.logging.LoggerRegistry;
import carpet.script.CarpetScriptServer;
import carpet.api.settings.CarpetRule;
Expand Down Expand Up @@ -129,7 +128,7 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)

public static void tick(MinecraftServer server)
{
TickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
trm.tick();
HUDController.update_hud(server, null);
if (scriptServer != null) scriptServer.tick();
Expand Down Expand Up @@ -229,9 +228,6 @@ public static void onServerClosed(MinecraftServer server)
extensions.forEach(e -> e.onServerClosed(server));
minecraft_server = null;
}

// this for whatever reason gets called multiple times even when joining;
TickSpeed.resetClient();
}
public static void onServerDoneClosing(MinecraftServer server)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/carpet/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import carpet.fakes.MinecraftServerInterface;
import carpet.fakes.SpawnGroupInterface;
import carpet.helpers.HopperCounter;
import carpet.helpers.TickRateManager;
import carpet.helpers.ServerTickRateManager;
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
import carpet.utils.SpawnReporter;
Expand Down Expand Up @@ -199,8 +199,8 @@ private static int runTest(CommandSourceStack source, int ticks, String counter)


// tick warp 0
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.tickrate_advance(null, 0, null, null);
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.requestGameToWarpSpeed(null, 0, null, null);
// tick warp given player
CommandSourceStack csource = null;
ServerPlayer player = null;
Expand All @@ -212,7 +212,7 @@ private static int runTest(CommandSourceStack source, int ticks, String counter)
catch (CommandSyntaxException ignored)
{
}
trm.tickrate_advance(player, ticks, null, csource);
trm.requestGameToWarpSpeed(player, ticks, null, csource);
Messenger.m(source, String.format("gi Started spawn test for %d ticks", ticks));
return 1;
}
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/carpet/commands/TickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import carpet.CarpetSettings;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.TickRateManager;
import carpet.helpers.ServerTickRateManager;
import carpet.network.ServerNetworkHandler;
import carpet.utils.CarpetProfiler;
import carpet.utils.CommandHelper;
Expand Down Expand Up @@ -73,33 +73,33 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co

private static int setTps(CommandSourceStack source, float tps)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.tickrate(tps, true);
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.setTickRate(tps, true);
queryTps(source);
return (int)tps;
}

private static int queryTps(CommandSourceStack source)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();

Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", trm.tickrate));
return (int) trm.tickrate;
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
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
Component message = trm.tickrate_advance(player, advance, tail_command, source);
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)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
if(trm.isPaused())
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
if(trm.gameIsPaused())
{
Messenger.m(source, "gi Freeze Status: Game is "+(trm.deeplyFrozen()?"deeply ":"")+"frozen");
}
Expand All @@ -112,9 +112,9 @@ private static int freezeStatus(CommandSourceStack source)

private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean freeze)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.setFrozenState(freeze, isDeep);
if (trm.isPaused())
if (trm.gameIsPaused())
{
Messenger.m(source, "gi Game is "+(isDeep?"deeply ":"")+"frozen");
}
Expand All @@ -127,24 +127,24 @@ private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean

private static int toggleFreeze(CommandSourceStack source, boolean isDeep)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
return setFreeze(source, isDeep, !trm.isPaused());
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
return setFreeze(source, isDeep, !trm.gameIsPaused());
}

private static int step(CommandSourceStack source, int advance)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.add_ticks_to_run_in_pause(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)
{
TickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.is_superHot = !trm.is_superHot;
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
trm.setSuperHot(!trm.isSuperHot());
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers(source.getServer());
if (trm.is_superHot)
if (trm.isSuperHot())
{
Messenger.m(source, "gi Superhot enabled");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/carpet/fakes/ClientLevelInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package carpet.fakes;

import carpet.helpers.TickRateManager;

public interface ClientLevelInterface
{
TickRateManager getTickRateManager();
}
10 changes: 10 additions & 0 deletions src/main/java/carpet/fakes/MinecraftInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package carpet.fakes;

import carpet.helpers.TickRateManager;

import java.util.Optional;

public interface MinecraftInterface
{
Optional<TickRateManager> getTickRateManager();
}
4 changes: 2 additions & 2 deletions src/main/java/carpet/fakes/MinecraftServerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;
import java.util.function.BooleanSupplier;

import carpet.helpers.TickRateManager;
import carpet.helpers.ServerTickRateManager;
import carpet.script.CarpetScriptServer;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
Expand All @@ -25,5 +25,5 @@ public interface MinecraftServerInterface
void addScriptServer(CarpetScriptServer scriptServer);
CarpetScriptServer getScriptServer();

TickRateManager getTickRateManager();
ServerTickRateManager getTickRateManager();
}
Loading

0 comments on commit c6f52b3

Please sign in to comment.