Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b0516f6
[Savestates] Properly implement SavestateStorageExtensions
ScribbleTAS Sep 13, 2025
d00137c
[Savestates] Split SavestatePlayerHandler into client and server
ScribbleTAS Sep 28, 2025
0ee9579
[Common] Update datafile and config
ScribbleTAS Sep 30, 2025
bf7b99a
[Savestates] Implement SavestateIndexer
ScribbleTAS Sep 30, 2025
3a8a8c4
[Savestates] Change savestate data directory from "tasmod" to "tas"
ScribbleTAS Sep 30, 2025
2d568d5
Bump version to Beta2
ScribbleTAS Sep 30, 2025
b4d8ae8
[Savestates] Readd tracker file
ScribbleTAS Oct 1, 2025
bea92a9
[Common] Fix TASmod logger being used instead of the MCTCommon one
ScribbleTAS Oct 9, 2025
b905d23
[Commands] Updating /folder savestates to open the correct savestate …
ScribbleTAS Oct 9, 2025
a4ee2a4
[Savestates] Add documentation to indexer
ScribbleTAS Oct 9, 2025
3350160
[Savestates] Update savestate command pt.1
ScribbleTAS Oct 14, 2025
80e48b2
[Savestates] Implement info command from LoTAS-Light
ScribbleTAS Oct 14, 2025
cfb0079
[Savestates] Fix components not being clickable in chat
ScribbleTAS Oct 15, 2025
b070d48
[Savestates] Properly implement savestate deletion
ScribbleTAS Oct 15, 2025
90e7c43
[Savestates] Update Gui usage during savestate loading/saving
ScribbleTAS Oct 16, 2025
895344d
[Savestates] Add command feedback
ScribbleTAS Oct 16, 2025
1bae8b3
[Savestates] Add warning when tickrate is set to 0
ScribbleTAS Oct 17, 2025
a50d7e3
[Savestates] Convert legacy savestate to new format
ScribbleTAS Oct 17, 2025
8f25e6a
[Savestates] Implement info all subcommand
ScribbleTAS Oct 17, 2025
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ mod_email=scribble@minecrafttas.com
# TASmod properties
group=com.minecrafttas
artifact=TASmod-1.12.2
version=Beta1.2
version=Beta2
release=false
32 changes: 27 additions & 5 deletions src/main/java/com/minecrafttas/mctcommon/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.minecrafttas.mctcommon;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
Expand All @@ -23,16 +24,37 @@ public Configuration(String comment, Path configFile, ConfigurationRegistry regi
}

@Override
public void loadFromXML() {
public void load() {

if (Files.exists(file)) {
loadFromXML(file);
String in = null;
try {
in = readFile(file);
} catch (IOException e) {
MCTCommon.LOGGER.catching(e);
return;
}

if (in.startsWith("<?xml")) {
MCTCommon.LOGGER.warn("Converting xml config to json");
loadFromXML();
return;
}

loadFromJson(file);
}

if (properties == null || !Files.exists(file)) {
properties = generateDefault();
saveToXML();
saveToJson();
}
}

@Override
public void save() {
super.saveToJson();
}

/**
* Generates the default property list from the values provided in {@link #registry}
* @return The default property list
Expand Down Expand Up @@ -67,7 +89,7 @@ public void set(ConfigOptions configOption, String value) {
throw new NullPointerException("Config needs to be loaded first, before trying to set a value");
}
properties.setProperty(configOption.getConfigKey(), value);
saveToXML();
save();
}

public void set(ConfigOptions configOption, int value) {
Expand All @@ -86,6 +108,6 @@ public void reset(ConfigOptions configOption) {

public void delete(ConfigOptions configOption) {
properties.remove(configOption);
saveToXML();
saveToJson();
}
}
125 changes: 73 additions & 52 deletions src/main/java/com/minecrafttas/mctcommon/KeybindManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.minecrafttas.mctcommon;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;

Expand All @@ -21,47 +21,7 @@ public class KeybindManager implements EventClientGameLoop {

private final IsKeyDownFunc defaultFunction;

public static class Keybind {

public final KeyBinding vanillaKeyBinding;
private final String category;
private final Runnable onKeyDown;
private final IsKeyDownFunc isKeyDownFunc;

/**
* Initialize keybind
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown) {
this(name, category, defaultKey, onKeyDown, null);
}

/**
* Initialize keybind with a different "isKeyDown" method
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown, IsKeyDownFunc func) {
this.vanillaKeyBinding = new KeyBinding(name, defaultKey, category);
this.category = category;
this.onKeyDown = onKeyDown;
this.isKeyDownFunc = func;
}

@Override
public String toString() {
return this.vanillaKeyBinding.getKeyDescription();
}
}

private List<Keybind> keybindings;
private Map<KeybindID, Keybind> keybindings;

/**
* Initialize keybind manage
Expand All @@ -71,15 +31,15 @@ public String toString() {
*/
public KeybindManager(IsKeyDownFunc defaultFunction) {
this.defaultFunction = defaultFunction;
this.keybindings = new ArrayList<>();
this.keybindings = new HashMap<>();
}

/**
* Handle registered keybindings on game loop
*/
@Override
public void onRunClientGameLoop(Minecraft mc) {
for (Keybind keybind : this.keybindings) {
for (Keybind keybind : this.keybindings.values()) {
IsKeyDownFunc keyDown = keybind.isKeyDownFunc != null ? keybind.isKeyDownFunc : defaultFunction;
if (keyDown.isKeyDown(keybind.vanillaKeyBinding)) {
keybind.onKeyDown.run();
Expand All @@ -88,26 +48,87 @@ public void onRunClientGameLoop(Minecraft mc) {

}

public void registerKeybinds(GameSettings options, Class<? extends KeybindID> keybindIDclass) {
if (keybindIDclass.isEnum())
registerKeybinds(options, keybindIDclass.getEnumConstants());
}

public void registerKeybinds(GameSettings options, KeybindID... keybind) {
for (KeybindID keybindEnum : keybind) {
registerKeybind(options, keybindEnum, keybindEnum.getKeybind());
}
}

/**
* Register new keybind
* Register a new keybind
*
* @param keybind Keybind to register
* @param options
* @param keybindID The {@link KeybindID} to register this underI
* @param keybind The {@link Keybind} to register
*/
public void registerKeybind(Keybind keybind, GameSettings options) {
this.keybindings.add(keybind);
public void registerKeybind(GameSettings options, KeybindID keybindID, Keybind keybind) {
this.keybindings.put(keybindID, keybind);
KeyBinding keyBinding = keybind.vanillaKeyBinding;

if (!AccessorKeyBinding.getCategoryOrder().containsKey(keybind.category))
AccessorKeyBinding.getCategoryOrder().put(keybind.category, AccessorKeyBinding.getCategoryOrder().size() + 1);
Map<String, Integer> categoryOrder = AccessorKeyBinding.getCategoryOrder();

if (!categoryOrder.containsKey(keybind.category))
categoryOrder.put(keybind.category, categoryOrder.size() + 1);

// add keybinding
options.keyBindings = ArrayUtils.add(options.keyBindings, keyBinding);
}

public Keybind getKeybind(KeybindID id) {
return keybindings.get(id);
}

@FunctionalInterface
public static interface IsKeyDownFunc {

public boolean isKeyDown(KeyBinding keybind);
}

public static interface KeybindID {
public Keybind getKeybind();
}

public static class Keybind {

public final KeyBinding vanillaKeyBinding;
private final String category;
private final Runnable onKeyDown;
private final IsKeyDownFunc isKeyDownFunc;

/**
* Initialize keybind
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown) {
this(name, category, defaultKey, onKeyDown, null);
}

/**
* Initialize keybind with a different "isKeyDown" method
*
* @param name Name of keybind
* @param category Category of keybind
* @param defaultKey Default key of keybind
* @param onKeyDown Will be run when the keybind is pressed
*/
public Keybind(String name, String category, int defaultKey, Runnable onKeyDown, IsKeyDownFunc func) {
this.vanillaKeyBinding = new KeyBinding(name, defaultKey, category);
this.category = category;
this.onKeyDown = onKeyDown;
this.isKeyDownFunc = func;
}

@Override
public String toString() {
return this.vanillaKeyBinding.getKeyDescription();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase>
if (newReturnValue != null)
returnValue = newReturnValue;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new EventException(eventClass, e);
throw new EventException(eventClass, e.getCause());
} catch (IllegalArgumentException e) {
throw new EventException(String.format("Event fired with the wrong number of parameters. Expected: %s, Actual: %s", method.getParameterCount(), eventParams.length), eventClass, e);
}
Expand Down
Loading