Skip to content

[PlayUntil] Fixed playuntil, attempt 2 #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ public void onPlaybackTickPre(long index) {
if (playUntil != null && playUntil == index) {
TASmodClient.tickratechanger.pauseGame(true);
PlaybackControllerClient controller = TASmodClient.controller;
controller.setTASState(TASstate.NONE);
controller.setTASState(TASstate.RECORDING);
controller.setIndex(controller.index() - 1);
for (long i = controller.size() - 1; i >= index; i--) {
controller.remove(i);
}
controller.setTASState(TASstate.RECORDING);
playUntil = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,18 @@ public String setTASStateClient(TASstate stateIn, boolean verbose) {
case PLAYBACK:
return TextFormatting.RED + "Please report this message to the mod author, because you should never be able to see this (Error: Playback)";
case RECORDING:
return verbose ? TextFormatting.RED + "A playback is currently running. Please stop the playback first before starting a recording" : "";
stopPlayback(false);
startRecording();
state = TASstate.RECORDING;
return verbose ? TextFormatting.GREEN + "Switching from playback to recording" : "";
case PAUSED:
LOGGER.debug(LoggerMarkers.Playback, "Pausing a playback");
state = TASstate.PAUSED;
stateAfterPause = TASstate.PLAYBACK;
TASmodClient.virtual.clear();
return verbose ? TextFormatting.GREEN + "Pausing a playback" : "";
case NONE:
stopPlayback();
stopPlayback(true);
state = TASstate.NONE;
return verbose ? TextFormatting.GREEN + "Stopping the playback" : "";
}
Expand Down Expand Up @@ -298,10 +301,12 @@ private void startPlayback() {
// TASmod.ktrngHandler.setInitialSeed(startSeed);
}

private void stopPlayback() {
private void stopPlayback(boolean clearInputs) {
LOGGER.debug(LoggerMarkers.Playback, "Stopping a playback");
Minecraft.getMinecraft().gameSettings.chatLinks = true;
TASmodClient.virtual.clear();
if (clearInputs) {
TASmodClient.virtual.clear();
}
}

/**
Expand Down Expand Up @@ -466,6 +471,10 @@ public void onClientTickPost(Minecraft mc) {
} else if (state == TASstate.PLAYBACK) {
playbackNextTick();
}

// if (TASmod.isDevEnvironment) {
// DebugWriter.writeDebugFile(this);
// }
}

private void recordNextTick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void setState(TASstate stateIn) {

public void setServerState(TASstate stateIn) {
if (state != stateIn) {
if (state == TASstate.RECORDING && stateIn == TASstate.PLAYBACK || state == TASstate.PLAYBACK && stateIn == TASstate.RECORDING)
if (state == TASstate.RECORDING && stateIn == TASstate.PLAYBACK)
return;
if (state == TASstate.NONE && state == TASstate.PAUSED) {
return;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/util/DebugWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.minecrafttas.tasmod.util;

import java.nio.file.Path;

import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;

/**
* Prints the current {@link PlaybackControllerClient#inputs} content to {@link TASmodClient#tasfiledirectory}/debug.mctas
*
* @author Scribble
*/
public class DebugWriter {

private static Path debugTASFile = TASmodClient.tasfiledirectory.resolve("debug.mctas");

public static void writeDebugFile(PlaybackControllerClient controller) {
PlaybackSerialiser.saveToFile(debugTASFile, controller, null);
}
}
Loading