1717import net .minecraft .util .WorldSavePath ;
1818import org .slf4j .Logger ;
1919import org .slf4j .LoggerFactory ;
20+
21+ import java .io .IOException ;
22+ import java .nio .file .Files ;
2023import java .nio .file .Path ;
2124import java .util .ArrayList ;
2225import java .util .List ;
@@ -43,6 +46,7 @@ public class TimeLoop implements ModInitializer {
4346 private List <String > recordingPlayers ; // Add this field
4447
4548 public boolean showLoopInfo ;
49+ public boolean displayTimeInTicks ;
4650 public boolean trackItems ;
4751 public LoopTypes loopType ;
4852
@@ -92,6 +96,7 @@ public void onInitialize() {
9296 ticksLeft = config .ticksLeft ;
9397
9498 showLoopInfo = config .showLoopInfo ;
99+ displayTimeInTicks = config .displayTimeInTicks ;
95100 trackItems = config .trackItems ;
96101 loopType = config .loopType ;
97102
@@ -175,11 +180,7 @@ public void onInitialize() {
175180 long time = serverWorld .getTimeOfDay ();
176181 long timeLeft = (time > timeSetting ) ? Math .abs (serverWorld .getTimeOfDay () - (2 * timeSetting )) : Math .abs (startTimeOfDay - timeSetting );
177182
178- if (showLoopInfo && isLooping ) {
179- loopBossBar .setBossBarName ("Time Left: " + timeLeft );
180- loopBossBar .setBossBarPercentage ((int )timeSetting , (int )(timeSetting - timeLeft ));
181- }
182-
183+ updateProgressBar ((int )timeSetting , (int )(timeSetting - timeLeft ));
183184 if (timeSetting - timeLeft == timeSetting ) {
184185 runLoopIteration ();
185186 }
@@ -188,11 +189,8 @@ public void onInitialize() {
188189 else if (loopType == LoopTypes .TICKS ) {
189190 tickCounter ++;
190191 ticksLeft = loopLengthTicks - tickCounter ;
191- if (showLoopInfo && isLooping ) {
192- loopBossBar .setBossBarName ("Ticks Left: " + ticksLeft );
193- loopBossBar .setBossBarPercentage (loopLengthTicks , tickCounter );
194- }
195192
193+ updateProgressBar (loopLengthTicks , ticksLeft );
196194 if (tickCounter >= loopLengthTicks ) {
197195 tickCounter = 0 ; // Reset counter
198196 ticksLeft = loopLengthTicks ; // Reset
@@ -245,6 +243,7 @@ private void runLoopIteration() {
245243 * Starts the recordings.
246244 */
247245 private void startRecordings () {
246+ // Start recording for every player
248247 for (String playerName : recordingPlayers ) {
249248 executeCommand (String .format ("mocap recording start %s" , playerName ));
250249 }
@@ -272,6 +271,15 @@ public void stopLoop() {
272271 }
273272 }
274273
274+ public void updateProgressBar (int time , int timeLeft ) {
275+ if (showLoopInfo && isLooping ) {
276+ if (displayTimeInTicks ) {loopBossBar .setBossBarName ("Time Left: " + timeLeft );}
277+ else {loopBossBar .setBossBarName ("Time Left: " + convertTicksToTime (timeLeft ));}
278+
279+ loopBossBar .setBossBarPercentage (time , timeLeft );
280+ }
281+ }
282+
275283 /**
276284 * Executes a minecraft chat command.
277285 */
@@ -301,6 +309,19 @@ public void updateEntitiesToTrack(boolean items) {
301309 executeCommand (String .format ("mocap settings recording track_entities %s" , entitiesToTrack ));
302310 executeCommand (String .format ("mocap settings playback play_entities %s" , entitiesToTrack ));
303311 }
312+
313+ /**
314+ * Converts time in ticks to HH:MM:SS
315+ *
316+ * @param ticksLeft A int value.
317+ */
318+ public String convertTicksToTime (int ticksLeft ) {
319+ int timeLeft = ticksLeft / 20 ;
320+ int hours = timeLeft / 3600 ;
321+ int minutes = (timeLeft % 3600 ) / 60 ;
322+ int seconds = timeLeft % 60 ;
323+ return String .format ("%02d:%02d:%02d" , hours , minutes , seconds );
324+ }
304325}
305326
306327// use this in the future
0 commit comments