Skip to content

Commit 5ac35d6

Browse files
committed
Merge branch 'master' into beta
# Conflicts: # src/main/java/com/vltno/timeloop/Commands.java # src/main/java/com/vltno/timeloop/TimeLoop.java
2 parents 2dd4e51 + 2faa6ac commit 5ac35d6

5 files changed

Lines changed: 56 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ Simply use commands to configure the loop.
1818
- `status` - Shows the status of the loop in chat.
1919
- **settings**
2020
- `maxLoops [0]` - Sets the maximum amount of loops. 0 is infinite.
21-
- `setTicks [6000]` - Set the duration / length of the loop in ticks (6000 ticks is 5 mins).
21+
- `setLength [6000]` - Set the duration / length of the loop in ticks (6000 ticks is 5 mins).
2222
- `setTimeOfDay [13000]` - Sets the time of day to loop at (same as minecraft so 13000 is night).
2323
- `loopType [TICK]` - Sets the type of loop.
2424
- **toggles**
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: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
8080
return 1;
8181
})))
8282

83-
.then(CommandManager.literal("setTicks")
83+
.then(CommandManager.literal("setLength")
8484
.requires(source -> source.hasPermissionLevel(2))
8585
.executes(context -> {
86-
context.getSource().sendMessage(Text.literal("Loop ticks is set to: " + mod.loopLengthTicks + " ticks"));
86+
context.getSource().sendMessage(Text.literal("Loop length is set to: " + mod.loopLengthTicks + " ticks"));
8787
return 1;
8888
})
8989
.then(CommandManager.argument("ticks", IntegerArgumentType.integer(20))
@@ -97,7 +97,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
9797

9898
mod.config.save();
9999
context.getSource().sendMessage(Text.literal("Loop ticks is set to: " + newTicks + " ticks"));
100-
LOGGER.info("Loop ticks set to {} ticks", newTicks);
100+
LOGGER.info("Loop length set to {} ticks", newTicks);
101101
return 1;
102102
})))
103103

@@ -174,7 +174,25 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
174174
LOGGER.info("Tracking items set to {}", newTrackItems);
175175
return 1;
176176
})))
177-
177+
178+
.then(CommandManager.literal("displayTimeInTicks")
179+
.requires(source -> source.hasPermissionLevel(2))
180+
.executes(context -> {
181+
context.getSource().sendMessage(Text.literal("Display Time in ticks is set to: " + mod.displayTimeInTicks));
182+
return 1;
183+
})
184+
.then(CommandManager.argument("value", BoolArgumentType.bool())
185+
.executes(context -> {
186+
boolean newDisplayTimeInTicks = BoolArgumentType.getBool(context, "value");
187+
mod.displayTimeInTicks = newDisplayTimeInTicks;
188+
mod.config.displayTimeInTicks = newDisplayTimeInTicks;
189+
mod.config.save();
190+
191+
context.getSource().sendMessage(Text.literal("Display Time in ticks is set to: " + newDisplayTimeInTicks));
192+
LOGGER.info("Display Time in ticks set to {}", newDisplayTimeInTicks);
193+
return 1;
194+
})))
195+
178196
.then(CommandManager.literal("showLoopInfo")
179197
.requires(source -> source.hasPermissionLevel(2))
180198
.executes(context -> {

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import net.minecraft.util.WorldSavePath;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
20+
21+
import java.io.IOException;
22+
import java.nio.file.Files;
2023
import java.nio.file.Path;
2124
import java.util.ArrayList;
2225
import 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

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

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

2424
public boolean showLoopInfo = true;
25+
public boolean displayTimeInTicks = false;
2526
public boolean trackItems = false;
2627
public LoopTypes loopType = LoopTypes.TICKS;
2728

0 commit comments

Comments
 (0)