Skip to content

Commit 88a2b71

Browse files
committed
Made it actually work
Replaces `sceneName` with `scenePrefix` for better clarity and flexibility in player scene naming. Moves player recording list handling to `LoopSceneManager`, including serialization and deserialization. Simplifies and enhances the loop playback and scene configuration logic.
1 parent 3ccf8d4 commit 88a2b71

4 files changed

Lines changed: 43 additions & 15 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
240240
mod.config.displayTimeInTicks = false;
241241

242242
mod.executeCommand("mocap playback stop_all");
243-
mod.executeCommand(String.format("mocap scenes remove %s", mod.sceneName));
244-
mod.executeCommand(String.format("mocap scenes add %s", mod.sceneName));
243+
mod.loopSceneManager.forEachPlayerSceneName(playerSceneName -> {
244+
mod.executeCommand(String.format("mocap scenes remove %s", playerSceneName));
245+
mod.executeCommand(String.format("mocap scenes add %s", playerSceneName));
246+
});
247+
245248
mod.loopIteration = 0;
246249
mod.config.loopIteration = 0;
247250
mod.config.save();

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
public class LoopSceneManager {
88
private TimeLoopConfig config;
9-
private String sceneName;
9+
private String scenePrefix;
1010
private List<String> recordingPlayers;
1111

1212
// Constructor to initialize recordingPlayers
13-
public LoopSceneManager(TimeLoopConfig _config) {
14-
this.config = _config;
15-
this.sceneName = config.sceneName;
13+
public LoopSceneManager(TimeLoopConfig config) {
14+
this.config = config;
15+
this.scenePrefix = config.scenePrefix;
1616
this.recordingPlayers = new ArrayList<>();
1717
}
1818

1919
// Method to add a player to the recordingPlayers list
2020
public void addPlayer(String playerName) {
2121
if (playerName != null && !playerName.isEmpty()) {
22-
recordingPlayers.add(playerName.toLowerCase());
22+
recordingPlayers.add(playerName);
2323
} else {
2424
System.out.println("Invalid player name. Player not added.");
2525
}
@@ -41,7 +41,7 @@ public void removePlayer(String playerName) {
4141

4242
// Method to generate playerSceneName for a given player
4343
public String getPlayerSceneName(String playerName) {
44-
return (sceneName + "_" + playerName).toLowerCase();
44+
return (playerName.startsWith(scenePrefix)) ? playerName : (scenePrefix + "_" + playerName).toLowerCase();
4545
}
4646

4747
// Method to get all playerSceneNames for recordingPlayers
@@ -60,4 +60,12 @@ public void forEachPlayerSceneName(Consumer<String> action) {
6060
public void forEachRecordingPlayer(Consumer<String> action) {
6161
recordingPlayers.forEach(action);
6262
}
63+
64+
public void setRecordingPlayers(List<String> recordingPlayers) {
65+
this.recordingPlayers = recordingPlayers;
66+
}
67+
68+
public void saveRecordingPlayers() {
69+
config.recordingPlayers = this.recordingPlayers;
70+
}
6371
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class TimeLoop implements ModInitializer {
4343
public boolean trackTimeOfDay;
4444
public boolean isLooping;
4545
public int maxLoops;
46-
public String sceneName;
4746
private int tickCounter = 0; // Tracks elapsed ticks
4847
public int ticksLeft;
4948

@@ -56,7 +55,7 @@ public class TimeLoop implements ModInitializer {
5655
public TimeLoopConfig config;
5756

5857
// The loop scene manager object
59-
private LoopSceneManager loopSceneManager;
58+
public LoopSceneManager loopSceneManager;
6059

6160
// Get the world folder path for config/recording loading
6261
private Path worldFolder;
@@ -65,7 +64,6 @@ public class TimeLoop implements ModInitializer {
6564
@Override
6665
public void onInitialize() {
6766
LOOP_LOGGER.info("Initializing TimeLoop mod");
68-
loopSceneManager = new LoopSceneManager(config);
6967

7068
// Register the custom ArgumentType
7169
ArgumentTypeRegistry.registerArgumentType(Identifier.of("timeloop",""), LoopTypesArgumentType.class, ConstantArgumentSerializer.of(LoopTypesArgumentType::new));
@@ -92,20 +90,24 @@ public void onInitialize() {
9290
worldFolder = server.getSavePath(WorldSavePath.ROOT);
9391
config = TimeLoopConfig.load(worldFolder);
9492

93+
// Loop scene manager
94+
loopSceneManager = new LoopSceneManager(config);
95+
9596
loopIteration = config.loopIteration;
9697
loopLengthTicks = config.loopLengthTicks;
9798
isLooping = config.isLooping;
9899
startTimeOfDay = config.startTimeOfDay;
99100
timeSetting = config.timeSetting;
100101
trackTimeOfDay = config.trackTimeOfDay;
101102
ticksLeft = config.ticksLeft;
102-
sceneName = config.sceneName;
103103

104104
showLoopInfo = config.showLoopInfo;
105105
displayTimeInTicks = config.displayTimeInTicks;
106106
trackItems = config.trackItems;
107107
loopType = config.loopType;
108108

109+
loopSceneManager.setRecordingPlayers(config.recordingPlayers);
110+
109111
TimeLoop.server = server;
110112
serverWorld = server.getOverworld();
111113

@@ -121,6 +123,14 @@ public void onInitialize() {
121123
executeCommand("mocap settings recording entity_tracking_distance 1");
122124

123125
updateEntitiesToTrack(trackItems);
126+
127+
try {
128+
loopSceneManager.forEachPlayerSceneName(playerSceneName -> {
129+
executeCommand(String.format("mocap scenes add %s", playerSceneName));
130+
});
131+
} catch (Error e) {
132+
LOOP_LOGGER.error("Failed to add player scenes to mocap scenes: {}", e.getMessage());
133+
}
124134
});
125135

126136
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
@@ -164,6 +174,7 @@ public void onInitialize() {
164174
loopBossBar.removePlayer(player);
165175
if (isLooping) {
166176
saveRecordings();
177+
loopSceneManager.saveRecordingPlayers();
167178
}
168179
});
169180

@@ -216,7 +227,7 @@ public void startLoop() {
216227
LOOP_LOGGER.info("Attempted to start already running recording loop");
217228
return;
218229
}
219-
if (showLoopInfo) {loopBossBar.visible(true);}
230+
if (showLoopInfo) { loopBossBar.visible(true); }
220231
isLooping = true;
221232
config.isLooping = true;
222233
tickCounter = 0;
@@ -237,7 +248,7 @@ private void runLoopIteration() {
237248
executeCommand("mocap playback stop_all including_others");
238249

239250
loopSceneManager.forEachPlayerSceneName(playerSceneName -> {
240-
executeCommand(String.format("mocap playback start .%s", loopSceneManager.getPlayerSceneName(playerSceneName)));
251+
executeCommand(String.format("mocap playback start .%s", playerSceneName));
241252
});
242253

243254
loopIteration++;
@@ -285,6 +296,7 @@ public void stopLoop() {
285296
config.isLooping = false;
286297
loopBossBar.visible(false);
287298
saveRecordings();
299+
loopSceneManager.saveRecordingPlayers();
288300
executeCommand("mocap playback stop_all including_others");
289301
tickCounter = 0;
290302
ticksLeft = loopLengthTicks;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import java.io.Writer;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11+
import java.util.ArrayList;
12+
import java.util.List;
1113

1214
public class TimeLoopConfig {
1315
// These values will be loaded/saved from/to the JSON config file.bossbar set minecraft:loop_info
14-
public String sceneName = "loop_scene";
16+
public String scenePrefix = "loop_scene";
1517
public boolean firstStart = true;
1618
public int loopIteration = 1;
1719
public boolean isLooping = false;
@@ -26,6 +28,8 @@ public class TimeLoopConfig {
2628
public boolean displayTimeInTicks = false;
2729
public boolean trackItems = false;
2830
public LoopTypes loopType = LoopTypes.TICKS;
31+
32+
public List<String> recordingPlayers = new ArrayList<>();
2933

3034
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
3135
private static Path configPath;
@@ -49,6 +53,7 @@ public static TimeLoopConfig load(Path configDir) {
4953
}
5054
// Create default config if none exists
5155
TimeLoopConfig config = new TimeLoopConfig();
56+
// config.recordingPlayers.add("stufffffffffffff");
5257
config.save();
5358
return config;
5459
}

0 commit comments

Comments
 (0)