Skip to content

Commit 8f310d8

Browse files
authored
[PlayUntil] Fixed playuntil, attempt 2 (#246)
- Allow the controller state to go from playback to recording - Added a way to constantly write the current PlaybackController inputs to the file for debugging inputs.
2 parents c38b4de + cefdbba commit 8f310d8

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

src/main/java/com/minecrafttas/tasmod/handlers/PlayUntilHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ public void onPlaybackTickPre(long index) {
3535
if (playUntil != null && playUntil == index) {
3636
TASmodClient.tickratechanger.pauseGame(true);
3737
PlaybackControllerClient controller = TASmodClient.controller;
38-
controller.setTASState(TASstate.NONE);
38+
controller.setTASState(TASstate.RECORDING);
3939
controller.setIndex(controller.index() - 1);
4040
for (long i = controller.size() - 1; i >= index; i--) {
4141
controller.remove(i);
4242
}
43-
controller.setTASState(TASstate.RECORDING);
4443
playUntil = null;
4544
}
4645
}

src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,18 @@ public String setTASStateClient(TASstate stateIn, boolean verbose) {
237237
case PLAYBACK:
238238
return TextFormatting.RED + "Please report this message to the mod author, because you should never be able to see this (Error: Playback)";
239239
case RECORDING:
240-
return verbose ? TextFormatting.RED + "A playback is currently running. Please stop the playback first before starting a recording" : "";
240+
stopPlayback(false);
241+
startRecording();
242+
state = TASstate.RECORDING;
243+
return verbose ? TextFormatting.GREEN + "Switching from playback to recording" : "";
241244
case PAUSED:
242245
LOGGER.debug(LoggerMarkers.Playback, "Pausing a playback");
243246
state = TASstate.PAUSED;
244247
stateAfterPause = TASstate.PLAYBACK;
245248
TASmodClient.virtual.clear();
246249
return verbose ? TextFormatting.GREEN + "Pausing a playback" : "";
247250
case NONE:
248-
stopPlayback();
251+
stopPlayback(true);
249252
state = TASstate.NONE;
250253
return verbose ? TextFormatting.GREEN + "Stopping the playback" : "";
251254
}
@@ -298,10 +301,12 @@ private void startPlayback() {
298301
// TASmod.ktrngHandler.setInitialSeed(startSeed);
299302
}
300303

301-
private void stopPlayback() {
304+
private void stopPlayback(boolean clearInputs) {
302305
LOGGER.debug(LoggerMarkers.Playback, "Stopping a playback");
303306
Minecraft.getMinecraft().gameSettings.chatLinks = true;
304-
TASmodClient.virtual.clear();
307+
if (clearInputs) {
308+
TASmodClient.virtual.clear();
309+
}
305310
}
306311

307312
/**
@@ -466,6 +471,10 @@ public void onClientTickPost(Minecraft mc) {
466471
} else if (state == TASstate.PLAYBACK) {
467472
playbackNextTick();
468473
}
474+
475+
// if (TASmod.isDevEnvironment) {
476+
// DebugWriter.writeDebugFile(this);
477+
// }
469478
}
470479

471480
private void recordNextTick() {

src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void setState(TASstate stateIn) {
8888

8989
public void setServerState(TASstate stateIn) {
9090
if (state != stateIn) {
91-
if (state == TASstate.RECORDING && stateIn == TASstate.PLAYBACK || state == TASstate.PLAYBACK && stateIn == TASstate.RECORDING)
91+
if (state == TASstate.RECORDING && stateIn == TASstate.PLAYBACK)
9292
return;
9393
if (state == TASstate.NONE && state == TASstate.PAUSED) {
9494
return;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.minecrafttas.tasmod.util;
2+
3+
import java.nio.file.Path;
4+
5+
import com.minecrafttas.tasmod.TASmodClient;
6+
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
7+
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;
8+
9+
/**
10+
* Prints the current {@link PlaybackControllerClient#inputs} content to {@link TASmodClient#tasfiledirectory}/debug.mctas
11+
*
12+
* @author Scribble
13+
*/
14+
public class DebugWriter {
15+
16+
private static Path debugTASFile = TASmodClient.tasfiledirectory.resolve("debug.mctas");
17+
18+
public static void writeDebugFile(PlaybackControllerClient controller) {
19+
PlaybackSerialiser.saveToFile(debugTASFile, controller, null);
20+
}
21+
}

0 commit comments

Comments
 (0)