Skip to content

Commit 1dc16c2

Browse files
committed
TimeLeft now displays as HH:MM:SS by default
Added displayTimeInTicks option
1 parent df2a0df commit 1dc16c2

5 files changed

Lines changed: 71 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Simply use commands to configure the loop.
2525
- `trackTimeOfDay [true]` - Toggles tracking the time of day during loops.
2626
- `trackItems [false]` - Toggles tracking items during loops.
2727
- `showLoopInfo [true]` - Toggles a bar at the top of the screen showing the amount of ticks/time left until the next loop.
28+
- `displayTimeInTicks [false]` - Displays the ticks instead of HH:MM:SS on the Progress bar.
2829

2930
# LoopType Options
3031
- `TICK` (Loops every `setTicks` ticks)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ yarn_mappings=1.21.1+build.3
99
loader_version=0.16.10
1010

1111
# Mod Properties
12-
mod_version=1.6.3
12+
mod_version=1.7.0
1313
maven_group=com.vltno.timeloop
1414
archives_base_name=time-loop
1515

src/main/java/com/vltno/timeloop/Commands.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
5858
LOGGER.info("Status requested: {}", status);
5959
return 1;
6060
}))
61-
61+
6262
// SETTINGS
6363
.then(CommandManager.literal("settings")
6464

@@ -74,7 +74,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
7474
mod.loopType = newLoopType;
7575
mod.config.loopType = newLoopType;
7676
mod.config.save();
77-
77+
7878
context.getSource().sendMessage(Text.literal("Looping type is set to: " + newLoopType.asString()));
7979
LOGGER.info("Loop type set to {}", newLoopType.asString());
8080
return 1;
@@ -96,13 +96,13 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
9696
mod.config.ticksLeft = newTicks;
9797

9898
mod.config.save();
99-
99+
100100
mod.executeCommand(String.format("bossbar set minecraft:loop_info max %s", newTicks));
101101
context.getSource().sendMessage(Text.literal("Loop ticks is set to: " + newTicks + " ticks"));
102102
LOGGER.info("Loop ticks set to {} ticks", newTicks);
103103
return 1;
104104
})))
105-
105+
106106
.then(CommandManager.literal("maxLoops")
107107
.requires(source -> source.hasPermissionLevel(2))
108108
.executes(context -> {
@@ -119,7 +119,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
119119
LOGGER.info("Max Loops set to {}", maxLoops);
120120
return 1;
121121
})))
122-
122+
123123
.then(CommandManager.literal("setTimeOfDay")
124124
.requires(source -> source.hasPermissionLevel(2))
125125
.executes(context -> {
@@ -136,7 +136,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
136136
LOGGER.info("Time set to {}", newTime);
137137
return 1;
138138
})))
139-
139+
140140
// TOGGLES
141141
.then(CommandManager.literal("toggles")
142142
.then(CommandManager.literal("trackTimeOfDay")
@@ -151,7 +151,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
151151
mod.trackTimeOfDay = newTrackTimeOfDay;
152152
mod.config.trackTimeOfDay = newTrackTimeOfDay;
153153
mod.config.save();
154-
154+
155155
context.getSource().sendMessage(Text.literal("Tracking time of day is set to: " + newTrackTimeOfDay));
156156
LOGGER.info("Tracking time of day set to {}", newTrackTimeOfDay);
157157
return 1;
@@ -169,14 +169,32 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
169169
mod.trackItems = newTrackItems;
170170
mod.config.trackItems = newTrackItems;
171171
mod.config.save();
172-
172+
173173
mod.updateEntitiesToTrack(newTrackItems);
174-
174+
175175
context.getSource().sendMessage(Text.literal("Tracking items is set to: " + newTrackItems));
176176
LOGGER.info("Tracking items set to {}", newTrackItems);
177177
return 1;
178178
})))
179-
179+
180+
.then(CommandManager.literal("displayTimeInTicks")
181+
.requires(source -> source.hasPermissionLevel(2))
182+
.executes(context -> {
183+
context.getSource().sendMessage(Text.literal("Display Time in ticks is set to: " + mod.displayTimeInTicks));
184+
return 1;
185+
})
186+
.then(CommandManager.argument("value", BoolArgumentType.bool())
187+
.executes(context -> {
188+
boolean newDisplayTimeInTicks = BoolArgumentType.getBool(context, "value");
189+
mod.displayTimeInTicks = newDisplayTimeInTicks;
190+
mod.config.displayTimeInTicks = newDisplayTimeInTicks;
191+
mod.config.save();
192+
193+
context.getSource().sendMessage(Text.literal("Display Time in ticks is set to: " + newDisplayTimeInTicks));
194+
LOGGER.info("Display Time in ticks set to {}", newDisplayTimeInTicks);
195+
return 1;
196+
}))))
197+
180198
.then(CommandManager.literal("showLoopInfo")
181199
.requires(source -> source.hasPermissionLevel(2))
182200
.executes(context -> {
@@ -189,13 +207,13 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
189207
mod.showLoopInfo = newShowLoopInfo;
190208
mod.config.showLoopInfo = newShowLoopInfo;
191209
mod.config.save();
192-
210+
193211
mod.loopBossBar.visible(newShowLoopInfo);
194-
212+
195213
context.getSource().sendMessage(Text.literal("Showing loop info is set to: " + newShowLoopInfo));
196214
LOGGER.info("Show loop info set to {}", newShowLoopInfo);
197215
return 1;
198-
})))))
216+
}))))
199217

200218
.then(CommandManager.literal("reset")
201219
.requires(source -> source.hasPermissionLevel(2))

src/main/java/com/vltno/timeloop/TimeLoop.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.vltno.timeloop;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonParser;
36
import net.fabricmc.api.ModInitializer;
47
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
58
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@@ -17,6 +20,9 @@
1720
import net.minecraft.util.WorldSavePath;
1821
import org.slf4j.Logger;
1922
import org.slf4j.LoggerFactory;
23+
24+
import java.io.IOException;
25+
import java.nio.file.Files;
2026
import java.nio.file.Path;
2127
import java.util.ArrayList;
2228
import java.util.List;
@@ -43,6 +49,7 @@ public class TimeLoop implements ModInitializer {
4349
private List<String> recordingPlayers; // Add this field
4450

4551
public boolean showLoopInfo;
52+
public boolean displayTimeInTicks;
4653
public boolean trackItems;
4754
public LoopTypes loopType;
4855

@@ -93,6 +100,7 @@ public void onInitialize() {
93100
sceneName = config.sceneName;
94101

95102
showLoopInfo = config.showLoopInfo;
103+
displayTimeInTicks = config.displayTimeInTicks;
96104
trackItems = config.trackItems;
97105
loopType = config.loopType;
98106

@@ -181,11 +189,7 @@ public void onInitialize() {
181189
long time = serverWorld.getTimeOfDay();
182190
long timeLeft = (time > timeSetting) ? Math.abs(serverWorld.getTimeOfDay() - (2 * timeSetting)) : Math.abs(startTimeOfDay - timeSetting);
183191

184-
if (showLoopInfo && isLooping) {
185-
loopBossBar.setBossBarName("Time Left: " + timeLeft);
186-
loopBossBar.setBossBarPercentage((int)timeSetting, (int)(timeSetting - timeLeft));
187-
}
188-
192+
updateProgressBar((int)timeSetting, (int)(timeSetting - timeLeft));
189193
if (timeSetting - timeLeft == timeSetting) {
190194
runLoopIteration();
191195
}
@@ -194,11 +198,8 @@ public void onInitialize() {
194198
else if (loopType == LoopTypes.TICKS) {
195199
tickCounter++;
196200
ticksLeft = loopLengthTicks - tickCounter;
197-
if (showLoopInfo && isLooping) {
198-
loopBossBar.setBossBarName("Ticks Left: " + ticksLeft);
199-
loopBossBar.setBossBarPercentage(loopLengthTicks, tickCounter);
200-
}
201201

202+
updateProgressBar(loopLengthTicks, ticksLeft);
202203
if (tickCounter >= loopLengthTicks) {
203204
tickCounter = 0; // Reset counter
204205
ticksLeft = loopLengthTicks; // Reset
@@ -291,6 +292,15 @@ public void stopLoop() {
291292
}
292293
}
293294

295+
public void updateProgressBar(int time, int timeLeft) {
296+
if (showLoopInfo && isLooping) {
297+
if (displayTimeInTicks) {loopBossBar.setBossBarName("Time Left: " + timeLeft);}
298+
else {loopBossBar.setBossBarName("Time Left: " + convertTicksToTime(timeLeft));}
299+
300+
loopBossBar.setBossBarPercentage(time, timeLeft);
301+
}
302+
}
303+
294304
/**
295305
* Executes a minecraft chat command.
296306
*/
@@ -343,11 +353,11 @@ private void removeOldSceneEntries() {
343353
if (sceneFile.toFile().exists()) {
344354
try {
345355
// Load the scene data from the file
346-
String jsonContent = new String(java.nio.file.Files.readAllBytes(sceneFile));
356+
String jsonContent = new String(Files.readAllBytes(sceneFile));
347357

348358
// Parse the content
349-
com.google.gson.JsonObject jsonObject = com.google.gson.JsonParser.parseString(jsonContent).getAsJsonObject();
350-
com.google.gson.JsonArray subScenes = jsonObject.getAsJsonArray("subscenes");
359+
JsonObject jsonObject = JsonParser.parseString(jsonContent).getAsJsonObject();
360+
JsonArray subScenes = jsonObject.getAsJsonArray("subscenes");
351361

352362
// Check if we have more scenes than maxLoops
353363
if (subScenes.size() > maxLoops) {
@@ -362,10 +372,10 @@ private void removeOldSceneEntries() {
362372
jsonObject.add("subScenes", subScenes);
363373

364374
// Write the updated JSON back to the file
365-
java.nio.file.Files.write(sceneFile, jsonObject.toString().getBytes());
375+
Files.write(sceneFile, jsonObject.toString().getBytes());
366376
LOOP_LOGGER.info("Removed old scene entries to maintain maxLoops: {}", maxLoops);
367377
}
368-
} catch (java.io.IOException e) {
378+
} catch (IOException e) {
369379
LOOP_LOGGER.error("Failed to read or write scene file: {}", sceneFile, e);
370380
}
371381
} else {
@@ -388,6 +398,19 @@ public void updateEntitiesToTrack(boolean items) {
388398
executeCommand(String.format("mocap settings playback record_entities %s", entitiesToTrack));
389399
executeCommand(String.format("mocap settings playback play_entities %s", entitiesToTrack));
390400
}
401+
402+
/**
403+
* Converts time in ticks to HH:MM:SS
404+
*
405+
* @param ticksLeft A int value.
406+
*/
407+
public String convertTicksToTime(int ticksLeft) {
408+
int timeLeft = ticksLeft / 20;
409+
int hours = timeLeft / 3600;
410+
int minutes = (timeLeft % 3600) / 60;
411+
int seconds = timeLeft % 60;
412+
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
413+
}
391414
}
392415

393416
// use this in the future

src/main/java/com/vltno/timeloop/TimeLoopConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class TimeLoopConfig {
2323
public int ticksLeft;
2424

2525
public boolean showLoopInfo = true;
26+
public boolean displayTimeInTicks = false;
2627
public boolean trackItems = false;
2728
public LoopTypes loopType = LoopTypes.TICKS;
2829

0 commit comments

Comments
 (0)