Skip to content

[Flavor] Add Alpha flavor #221

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 16 commits into from
Mar 24, 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
@@ -1,5 +1,14 @@
package com.minecrafttas.mctcommon.registry;

/**
* Interface for declaring that a class can be registered by a class of type {@link AbstractRegistry}
*
* @author Scribble
*/
public interface Registerable {

/**
* @return The name of the extension that is registered
*/
public String getExtensionName();
}
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.minecrafttas.tasmod.commands.CommandTickrate;
import com.minecrafttas.tasmod.commands.TabCompletionUtils;
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.registries.TASmodPackets;
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer;
import com.minecrafttas.tasmod.savestates.storage.SavestateMotionStorage;
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
import com.minecrafttas.tasmod.handlers.LoadingScreenHandler;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.filecommands.integrated.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.integrated.LabelFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.integrated.OptionsFileCommandExtension;
import com.minecrafttas.tasmod.playback.metadata.integrated.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.tasfile.flavor.integrated.Beta1Flavor;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.LabelFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.OptionsFileCommandExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.AlphaFlavor;
import com.minecrafttas.tasmod.playback.tasfile.flavor.builtin.Beta1Flavor;
import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;
import com.minecrafttas.tasmod.registries.TASmodConfig;
import com.minecrafttas.tasmod.registries.TASmodKeybinds;
Expand Down Expand Up @@ -312,9 +313,11 @@ private void registerPlaybackMetadata(Minecraft mc) {
}

public static Beta1Flavor betaFlavor = new Beta1Flavor();
public static AlphaFlavor alphaFlavor = new AlphaFlavor();

private void registerSerialiserFlavors(Minecraft mc) {
TASmodAPIRegistry.SERIALISER_FLAVOR.register(betaFlavor);
TASmodAPIRegistry.SERIALISER_FLAVOR.register(alphaFlavor);
}

public static DesyncMonitorFileCommandExtension desyncMonitorFileCommandExtension;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.minecrafttas.tasmod.TASmodClient;
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.filecommands.integrated.DesyncMonitorFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
import com.mojang.realmsclient.gui.ChatFormatting;

import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public void setPlayUntil(int until) {
// ==============================================================

/**
* Storage class which stores the keyboard, mouse and subticks of a given tick.
* Storage class which stores the keyboard, mouse, subticks and comments of a given tick.
*
* @author Scribble
*
Expand Down Expand Up @@ -628,7 +628,13 @@ public VirtualCameraAngle getCameraAngle() {
return cameraAngle;
}

/**
* @return The comment container of this controller. If {@link #comments} is null, returns an empty container.
*/
public CommentContainer getComments() {
if (comments == null) {
return new CommentContainer();
}
return comments;
}

Expand All @@ -647,6 +653,11 @@ public boolean equals(Object other) {
}
}

/**
* Storage class for storing {@link CommentContainer#inlineComments inline} and {@link CommentContainer#endlineComments endline} comments
*
* @author Scribble
*/
public static class CommentContainer implements Serializable {

/**
Expand Down Expand Up @@ -835,6 +846,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
if (mc.world != null)
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + "Loading failed, something went very wrong"));
LOGGER.catching(e);
return;
}

if (mc.world != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static abstract class PlaybackFileCommandExtension implements Registerabl
protected final Path tempDir;

public PlaybackFileCommandExtension() {
this(null);
this((Path) null);
}

/**
Expand All @@ -69,13 +69,18 @@ public PlaybackFileCommandExtension() {
* @param tempFolderName The name of the temp folder
*/
public PlaybackFileCommandExtension(String tempFolderName) {
if (tempFolderName == null) {
this(TASmodClient.tasfiledirectory.resolve("temp").resolve(tempFolderName));
}

public PlaybackFileCommandExtension(Path tempDirectory) {
if (tempDirectory == null) {
tempDir = null;
return;
}
this.tempDir = TASmodClient.tasfiledirectory.resolve("temp").resolve(tempFolderName);

tempDir = tempDirectory;
try {
AbstractDataFile.createDirectory(tempDir);
AbstractDataFile.createDirectory(tempDirectory);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
public class PlaybackFileCommandsRegistry extends AbstractRegistry<PlaybackFileCommandExtension> implements EventPlaybackClient.EventRecordTick, EventPlaybackClient.EventPlaybackTick, EventPlaybackClient.EventRecordClear {

private List<PlaybackFileCommandExtension> enabledExtensions = new ArrayList<>();

private Configuration config = null;

public PlaybackFileCommandsRegistry() {
super("FILECOMMAND_REGISTRY", new LinkedHashMap<>());
}
Expand All @@ -38,16 +38,16 @@ public void unregister(PlaybackFileCommandExtension extension) {
public boolean setEnabled(String extensionName, boolean enabled) {
return setEnabled(extensionName, enabled, true);
}

public boolean setEnabled(String extensionName, boolean enabled, boolean saveToConfig) {
PlaybackFileCommandExtension extension = REGISTRY.get(extensionName);
if(extension == null) {
if (extension == null) {
return false;
}
extension.setEnabled(enabled);
enabledExtensions = getEnabled();
if(saveToConfig) {

if (saveToConfig) {
saveConfig();
}
return true;
Expand All @@ -59,16 +59,20 @@ private void disableAll() {
});
}

public void setEnabled(String... extensionNames) {
setEnabled(Arrays.asList(extensionNames));
}

public void setEnabled(List<String> extensionNames) {
setEnabled(extensionNames, false);
}

public void setEnabled(List<String> extensionNames, boolean saveToConfig) {
disableAll();
for (String name : extensionNames) {
setEnabled(name, true, false);
}
if(saveToConfig)
if (saveToConfig)
saveConfig();
}

Expand All @@ -83,24 +87,24 @@ public List<PlaybackFileCommandExtension> getEnabled() {

return out;
}
public List<PlaybackFileCommandExtension> getAll(){

public List<PlaybackFileCommandExtension> getAll() {
return new ArrayList<>(REGISTRY.values());
}

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

@Override
public void onPlaybackTick(long index, TickContainer container) {
enabledExtensions.forEach(extension -> {
if(extension.isEnabled()) {
if (extension.isEnabled()) {
extension.onPlayback(index, container);
}
});
Expand All @@ -109,8 +113,8 @@ public void onPlaybackTick(long index, TickContainer container) {
public PlaybackFileCommandContainer handleOnSerialiseInline(long currentTick, TickContainer container) {
PlaybackFileCommandContainer out = new PlaybackFileCommandContainer();
for (PlaybackFileCommandExtension extension : enabledExtensions) {
PlaybackFileCommandContainer extensionContainer=extension.onSerialiseInlineComment(currentTick, container);
if(extensionContainer!=null) {
PlaybackFileCommandContainer extensionContainer = extension.onSerialiseInlineComment(currentTick, container);
if (extensionContainer != null) {
out.putAll(extensionContainer);
}
}
Expand All @@ -120,8 +124,8 @@ public PlaybackFileCommandContainer handleOnSerialiseInline(long currentTick, Ti
public PlaybackFileCommandContainer handleOnSerialiseEndline(long currentTick, TickContainer container) {
PlaybackFileCommandContainer out = new PlaybackFileCommandContainer();
for (PlaybackFileCommandExtension extension : enabledExtensions) {
PlaybackFileCommandContainer extensionContainer=extension.onSerialiseEndlineComment(currentTick, container);
if(extensionContainer!=null) {
PlaybackFileCommandContainer extensionContainer = extension.onSerialiseEndlineComment(currentTick, container);
if (extensionContainer != null) {
out.putAll(extensionContainer);
}
}
Expand Down Expand Up @@ -155,22 +159,22 @@ public void setConfig(Configuration config) {
this.config = config;
loadConfig();
}

private void loadConfig() {
if (config == null) {
return;
}
String enabled = config.get(TASmodConfig.EnabledFileCommands);
setEnabled(Arrays.asList(enabled.split(", ")));
}

private void saveConfig() {
if (config == null) {
return;
}
List<String> nameList = new ArrayList<>();
enabledExtensions.forEach(element ->{
List<String> nameList = new ArrayList<>();

enabledExtensions.forEach(element -> {
nameList.add(element.getExtensionName());
});
config.set(TASmodConfig.EnabledFileCommands, String.join(", ", nameList));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.minecrafttas.tasmod.playback.filecommands.integrated;
package com.minecrafttas.tasmod.playback.filecommands.builtin;

import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Path;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.List;
Expand Down Expand Up @@ -40,12 +41,22 @@ public class DesyncMonitorFileCommandExtension extends PlaybackFileCommandExtens
private MonitorContainer currentValues;

public DesyncMonitorFileCommandExtension() {
super("monitoring");
this("monitoring");
}

public DesyncMonitorFileCommandExtension(String tempDirName) {
super(tempDirName);
this.monitorContainer = new BigArrayList<MonitorContainer>(tempDir.toString());
// Is enabled by default
enabled = true;
}

public DesyncMonitorFileCommandExtension(Path tempDir) {
super(tempDir);
this.monitorContainer = new BigArrayList<>(tempDir.toString());
enabled = true;
}

@Override
public String getExtensionName() {
return "tasmod_desyncMonitor@v1";
Expand Down Expand Up @@ -124,7 +135,7 @@ public void onPlayback(long tick, TickContainer tickContainer) {
private MonitorContainer loadFromFile(long tick, String[] args) throws PlaybackLoadException {

if (args.length != 6)
throw new PlaybackLoadException("Tick %s: desyncMonitorArgsLength ");
throw new PlaybackLoadException("Could not load desyncMonitor file command in tick %s. The amount of arguments doesn't match: %s", tick, args.length);

double x = 0;
double y = 0;
Expand Down Expand Up @@ -349,9 +360,9 @@ public void onClear() {
} catch (IOException e) {
e.printStackTrace();
}
monitorContainer = new BigArrayList<MonitorContainer>(tempDir.toString());
monitorContainer = new BigArrayList<MonitorContainer>();
lastStatus = TextFormatting.GRAY + "Empty";
lastPos = "";
lastMotion = "";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecrafttas.tasmod.playback.filecommands.integrated;
package com.minecrafttas.tasmod.playback.filecommands.builtin;

import java.io.IOException;
import java.nio.file.Path;

import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
Expand All @@ -16,7 +17,17 @@ public class LabelFileCommandExtension extends PlaybackFileCommandExtension {
BigArrayList<PlaybackFileCommandContainer> label = new BigArrayList<>();

public LabelFileCommandExtension() {
super("label");
this("label");
}

public LabelFileCommandExtension(String tempDirName) {
super(tempDirName);
this.label = new BigArrayList<>(tempDir.toString());
enabled = true;
}

public LabelFileCommandExtension(Path tempDir) {
super(tempDir);
this.label = new BigArrayList<>(tempDir.toString());
enabled = true;
}
Expand All @@ -31,6 +42,15 @@ public String[] getFileCommandNames() {
return new String[] { "label" };
}

@Override
public PlaybackFileCommandContainer onSerialiseInlineComment(long tick, TickContainer tickContainer) {
PlaybackFileCommandContainer fileCommandContainer = new PlaybackFileCommandContainer();
if (label.size() != 0 && label.get(tick).get("label") != null) {
fileCommandContainer = label.get(tick);
}
return fileCommandContainer;
}

@Override
public void onDeserialiseInlineComment(long tick, TickContainer container, PlaybackFileCommandContainer fileCommandContainer) {
if (fileCommandContainer.containsKey("label")) {
Expand Down
Loading