From 6be2e51e0c42921c9fd5efc4c40503276d9b3547 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Thu, 21 Oct 2021 19:38:07 -0700 Subject: [PATCH] support '/tick freeze on', '/tick freeze off' and '/tick freeze status' The current implementation only allows toggling tick freeze, so scripting is hard. This patch enables users to specifically freeze or unfreeze other than just toggling. It also provides '/tick freeze status' command to dynamically check whether the game is frozen or not. This patch preserves compatibility to the existing '/tick freeze' toggle command. --- .../java/carpet/commands/TickCommand.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/commands/TickCommand.java b/src/main/java/carpet/commands/TickCommand.java index 8b6b3826..b4ada51e 100644 --- a/src/main/java/carpet/commands/TickCommand.java +++ b/src/main/java/carpet/commands/TickCommand.java @@ -45,7 +45,11 @@ public class TickCommand getInteger(c,"ticks"), getString(c, "tail command")))))). then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource(), false)). - then(literal("deep").executes( (c)-> toggleFreeze(c.getSource(), true)))). + 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(1)). then(argument("ticks", integer(1,72000)). @@ -94,9 +98,22 @@ public class TickCommand return 1; } - private static int toggleFreeze(ServerCommandSource source, boolean isDeep) + private static int freezeStatus(ServerCommandSource source) { - TickSpeed.setFrozenState(!TickSpeed.isPaused(), isDeep); + if(TickSpeed.isPaused()) + { + Messenger.m(source, "gi Freeze Status: Game is "+(TickSpeed.deeplyFrozen()?"deeply ":"")+"frozen"); + } + else + { + Messenger.m(source, "gi Freeze Status: Game runs normally"); + } + return 1; + } + + private static int setFreeze(ServerCommandSource source, boolean isDeep, boolean freeze) + { + TickSpeed.setFrozenState(freeze, isDeep); if (TickSpeed.isPaused()) { Messenger.m(source, "gi Game is "+(isDeep?"deeply ":"")+"frozen"); @@ -108,6 +125,11 @@ public class TickCommand return 1; } + private static int toggleFreeze(ServerCommandSource source, boolean isDeep) + { + return setFreeze(source, isDeep, !TickSpeed.isPaused()); + } + private static int step(int advance) { TickSpeed.add_ticks_to_run_in_pause(advance);