Skip to content

Commit 33d224a

Browse files
committed
Fixed starting recordings.
CURRENT BUGS: - Automatically starting loop (too early, player not loaded in world yet) - Stopping & Saving recordings - Continuing after reload (maybe a bug? not tested yet)
1 parent 79dfec7 commit 33d224a

4 files changed

Lines changed: 8 additions & 87 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
2626
if (!mod.isLooping) {
2727
mod.startLoop();
2828
context.getSource().sendMessage(Text.literal("Loop started!"));
29-
LOGGER.info("loop started");
29+
LOGGER.info("Loop started");
3030
return 1;
3131
}
3232
context.getSource().sendMessage(Text.literal("Loop already running!"));
@@ -96,8 +96,6 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
9696
mod.config.ticksLeft = newTicks;
9797

9898
mod.config.save();
99-
100-
mod.executeCommand(String.format("bossbar set minecraft:loop_info max %s", newTicks));
10199
context.getSource().sendMessage(Text.literal("Loop ticks is set to: " + newTicks + " ticks"));
102100
LOGGER.info("Loop ticks set to {} ticks", newTicks);
103101
return 1;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public void setBossBarName(String bossBarName) {
2828
public void setBossBarPercentage(int whole, int part) {
2929
bossBar.setPercent(1.0f - ((float) part / whole));
3030
}
31-
32-
public float getBossBarPercentage() {
33-
return bossBar.getPercent();
34-
}
3531

3632
public void addPlayer(ServerPlayerEntity player) {
3733
LOGGER.info("Adding player: {}", player.getName().getString());

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

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void onInitialize() {
145145
loopBossBar.addPlayer(player);
146146
if (isLooping) {
147147
LOOP_LOGGER.info("Starting recording for newly joined player: {}", playerName);
148-
executeCommand("mocap recording start " + playerName);
148+
startLoop();
149149
}
150150
});
151151

@@ -156,7 +156,7 @@ public void onInitialize() {
156156
loopBossBar.removePlayer(player);
157157
if (isLooping) {
158158
LOOP_LOGGER.info("Saving recording for Disconnected player: {}", playerName);
159-
String recordingName = "-" + playerName + "." + playerName + ".1";
159+
String recordingName = "-+mc." + playerName + ".1";
160160
executeCommand(String.format("mocap recording stop " + recordingName));
161161
executeCommand("mocap recording save " + recordingName + " " + recordingName);
162162
}
@@ -222,9 +222,6 @@ public void startLoop() {
222222
ticksLeft = loopLengthTicks;
223223
LOOP_LOGGER.info("Starting Loop");
224224
startRecordings();
225-
for (String playerName : recordingPlayers) {
226-
executeCommand(String.format("mocap recording start %s", playerName));
227-
}
228225
}
229226

230227
/**
@@ -234,7 +231,7 @@ private void runLoopIteration() {
234231
LOOP_LOGGER.info("Starting iteration {} of loop", loopIteration);
235232
if (trackTimeOfDay) { serverWorld.setTimeOfDay(startTimeOfDay); }
236233
for (String playerName : recordingPlayers) {
237-
String recordingName = "-" + playerName + "." + playerName + ".1";
234+
String recordingName = "-+mc." + playerName + ".1";
238235

239236
executeCommand("mocap playback start " + recordingName);
240237
}
@@ -248,7 +245,6 @@ private void runLoopIteration() {
248245
* Starts the recordings.
249246
*/
250247
private void startRecordings() {
251-
// Start recording for every player
252248
for (String playerName : recordingPlayers) {
253249
executeCommand(String.format("mocap recording start %s", playerName));
254250
}
@@ -264,10 +260,10 @@ public void stopLoop() {
264260
config.isLooping = false;
265261
loopBossBar.visible(false);
266262
for (String playerName : recordingPlayers) {
267-
String recordingName = "-" + playerName + "." + playerName + ".1";
263+
String recordingName = "-+mc." + playerName + ".1";
268264

269265
executeCommand("mocap recording stop " + recordingName);
270-
// executeCommand("mocap recording save " + recordingName + " " + recordingName);
266+
executeCommand("mocap recording save " + recordingName + " " + recordingName);
271267
}
272268
executeCommand("mocap playback stop_all including_others");
273269
tickCounter = 0;
@@ -292,74 +288,6 @@ public void executeCommand(String command) {
292288
}
293289
}
294290

295-
/**
296-
* Checks if a recording file with the specified name exists in the predefined recordings directory.
297-
* The method returns a boolean indicating the existence of the file.
298-
*
299-
* @param recordingName The name of the recording file to check, without the file extension.
300-
* @return true if the recording file exists, false otherwise.
301-
*/
302-
private boolean recordingFileExists(String recordingName) {
303-
// Build the complete path for the recording directory using the absolute world path
304-
Path recordingDir = worldFolder.resolve("mocap_files").resolve("recordings");
305-
Path recordingFile = recordingDir.resolve(recordingName.toLowerCase() + ".mcmocap_rec");
306-
307-
boolean exists = recordingFile.toFile().exists();
308-
if (!exists) {
309-
LOOP_LOGGER.error("Expected recording file does not exist: {}", recordingFile.toAbsolutePath());
310-
}
311-
return exists;
312-
}
313-
314-
/**
315-
* Removes outdated entries from the scene file to ensure the number of subscenes does not exceed the maximum allowed loops.
316-
*
317-
* The method checks if there are more recorded subscenes in the scene file than the value specified by maxLoops. If so,
318-
* it removes the oldest entries to maintain the desired number. The updated data is then saved back to the file.
319-
*
320-
*/
321-
private void removeOldSceneEntries() {
322-
if (isLooping) {
323-
if (maxLoops > 1) {
324-
Path sceneDir = worldFolder.resolve("mocap_files").resolve("scenes");
325-
Path sceneFile = sceneDir.resolve(sceneName+".mcmocap_scene");
326-
327-
// Check if the scene file exists
328-
if (sceneFile.toFile().exists()) {
329-
try {
330-
// Load the scene data from the file
331-
String jsonContent = new String(java.nio.file.Files.readAllBytes(sceneFile));
332-
333-
// Parse the content
334-
com.google.gson.JsonObject jsonObject = com.google.gson.JsonParser.parseString(jsonContent).getAsJsonObject();
335-
com.google.gson.JsonArray subScenes = jsonObject.getAsJsonArray("subscenes");
336-
337-
// Check if we have more scenes than maxLoops
338-
if (subScenes.size() > maxLoops) {
339-
// Calculate the number of scenes to remove
340-
int entriesToRemove = subScenes.size() - maxLoops;
341-
// Remove the excess entries (removing from the start of the array)
342-
for (int i = 0; i < entriesToRemove; i++) {
343-
subScenes.remove(0); // Remove the first (oldest) entry
344-
}
345-
346-
// Update the JSON object with the modified subScenes array
347-
jsonObject.add("subScenes", subScenes);
348-
349-
// Write the updated JSON back to the file
350-
java.nio.file.Files.write(sceneFile, jsonObject.toString().getBytes());
351-
LOOP_LOGGER.info("Removed old scene entries to maintain maxLoops: {}", maxLoops);
352-
}
353-
} catch (java.io.IOException e) {
354-
LOOP_LOGGER.error("Failed to read or write scene file: {}", sceneFile, e);
355-
}
356-
} else {
357-
LOOP_LOGGER.error("Scene file does not exist: {}", sceneFile);
358-
}
359-
}
360-
}
361-
}
362-
363291
/**
364292
* Updates the entities to be tracked for recording and playback settings.
365293
* This method modifies the entities being tracked based on the specified parameter,
@@ -370,7 +298,7 @@ private void removeOldSceneEntries() {
370298
*/
371299
public void updateEntitiesToTrack(boolean items) {
372300
String entitiesToTrack = "@vehicles" + (items ? ";@items" : "");
373-
executeCommand(String.format("mocap settings recording record_entities %s", entitiesToTrack));
301+
executeCommand(String.format("mocap settings recording track_entities %s", entitiesToTrack));
374302
executeCommand(String.format("mocap settings playback play_entities %s", entitiesToTrack));
375303
}
376304
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import java.nio.file.Path;
1111

1212
public class TimeLoopConfig {
13-
// These values will be loaded/saved from/to the JSON config file.
14-
public String sceneName = "loop_scene";
13+
// These values will be loaded/saved from/to the JSON config file.bossbar set minecraft:loop_info
1514
public boolean firstStart = true;
1615
public int loopIteration = 1;
1716
public boolean isLooping = false;

0 commit comments

Comments
 (0)