Skip to content

Commit

Permalink
[PlaybackSerialiser] Fixed FileCommmands#onRecord() not being called
Browse files Browse the repository at this point in the history
- Enabled DesyncMonitorFileCommandExtension by default
  • Loading branch information
ScribbleTAS committed Jul 1, 2024
1 parent e6f89b0 commit 852d17a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.minecrafttas.tasmod.networking.TASmodBufferBuilder;
import com.minecrafttas.tasmod.networking.TASmodPackets;
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadata;
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser2;
import com.minecrafttas.tasmod.playback.tasfile.exception.PlaybackLoadException;
import com.minecrafttas.tasmod.playback.tasfile.exception.PlaybackSaveException;
Expand Down Expand Up @@ -800,8 +801,10 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
try {
TASmodClient.controller.setInputs(PlaybackSerialiser2.loadFromFile(new File(directory, name + ".mctas"), flavor));
} catch (PlaybackLoadException e) {
if (mc.world != null)
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage()));
if (mc.world != null) {
TextComponentString textComponent = new TextComponentString(e.getMessage());
mc.ingameGUI.getChatGUI().printChatMessage(textComponent);
}
LOGGER.catching(e);
return;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void register(PlaybackFileCommandExtension extension) {
}

REGISTRY.put(extension.name(), extension);
enabledExtensions = getEnabled();
}

@Override
Expand Down Expand Up @@ -86,16 +87,20 @@ public List<PlaybackFileCommandExtension> getEnabled() {
}

@Override
public void onPlaybackTick(long index, TickContainer container) {
public void onRecordTick(long index, TickContainer container) {
enabledExtensions.forEach(extension -> {
extension.onRecord(index, container);
if(extension.isEnabled()) {
extension.onRecord(index, container);
}
});
}

@Override
public void onRecordTick(long index, TickContainer container) {
public void onPlaybackTick(long index, TickContainer container) {
enabledExtensions.forEach(extension -> {
extension.onPlayback(index, container);
if(extension.isEnabled()) {
extension.onPlayback(index, container);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventPlaybackClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand;
Expand All @@ -38,6 +37,10 @@ public class DesyncMonitorFileCommandExtension extends PlaybackFileCommandExtens

private MonitorContainer currentValues;

public DesyncMonitorFileCommandExtension() {
enabled = true;
}

@Override
public String name() {
return "tasmod_desyncMonitoring@v1";
Expand Down Expand Up @@ -93,6 +96,7 @@ public void onDeserialiseEndlineComment(long tick, TickContainer container, Play
List<PlaybackFileCommand> commandsEndline = fileCommandContainer.get("desyncMonitor");
if (commandsEndline == null || commandsEndline.isEmpty()) {
recordNull(tick);
return;
}

PlaybackFileCommand command = commandsEndline.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static SerialiserFlavorBase searchForFlavor(List<String> lines, List<Seri
return flavor.clone();
}
}
throw new PlaybackLoadException("Couldn't find a flavorname in the file. TASmod is missing a flavor-extension or the file is broken");
throw new PlaybackLoadException("Couldn't find a flavorname in the file. TASfile is missing a flavor-extension or the file is broken");
}

public static SerialiserFlavorBase readFlavor(File file) throws PlaybackLoadException, IOException {
Expand Down

0 comments on commit 852d17a

Please sign in to comment.