Skip to content

Commit

Permalink
Savestate fixes (#214)
Browse files Browse the repository at this point in the history
## Changes
- [Savestates] Fix loading savestates across dimensions failing on the first try
- [Gui] Readded keystrokes to the gui
- [FileCommands] Added more precision to desyncMonitor
- [Gui] Changed DesyncMonitor values from relative to absolute
- Added hash to dev-build filename and ingame hud
- Removed "savestates are broken" warnings from the chat
- [Savestates] Switched to Paths instead of Files
- [Savestates|Config] Reworked Config and other files
- [Savestates] Switched from storing motion in the playerdata to storing
motion in `World/tasmod/clientMotion.json`
- [Gui] Removed "TASmod is still in development! Major issues may
arise!" message in gui screens
- [PlaybackSerialiser] Loads of fixes to integrate better with
savestates
- [VirtualInput] Fixed player being able to turn during playback
- [Savestates] Fix scoreboard not being applied
- [Savestates] Fix some redstone components behaving weirdly
  • Loading branch information
ScribbleTAS authored Dec 13, 2024
2 parents 0a38f1a + 528331e commit 96c1cbd
Show file tree
Hide file tree
Showing 70 changed files with 3,249 additions and 1,678 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.6
gradle-version: 8.10.2
- name: Build TASmod with Gradle
run: gradle build
- name: Upload Test Report
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/buildandupload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.6
gradle-version: 8.10.2
- name: Build TASmod with Gradle
run: gradle build
- name: Upload artifact
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Create Release
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '22'
distribution: 'temurin'
architecture: x64
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: 8.10.2
- name: Setup workspace
run: gradle build -Prelease=true
- name: Upload assets
uses: softprops/action-gh-release@v2
with:
files: 'build/libs/!(-@(dev|sources|javadoc|all)).jar'
- name: Publish 1.12.2
uses: Kir-Antipov/mc-publish@v3.3
with:
files: 'build/libs/*-1.12.2-*!(*-@(dev|sources|javadoc|all)).jar'
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
20 changes: 12 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ plugins {
id 'fabric-loom' version "${loom_version}"
// legacy looming (loom plugin improvements)
id 'legacy-looming' version "${loom_version}"
id 'com.palantir.git-version' version '3.1.0'
}


// set basic properties
version = project.version
def hash = ""
if(project.release=="false") {
hash = "-SNAPSHOT_"+versionDetails().gitHash.substring(0,7)
}
version = project.version+hash
group = project.group

// compile for java 8
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
java {
// compile for java 8
sourceCompatibility = targetCompatibility = 8
}

loom {
// set access widener
accessWidenerPath = file('src/main/resources/tasmod.accesswidener')
// add log4jconfig
log4jConfigs.from(file('src/main/resources/log4j.xml'))

}

// dependency repositories
Expand Down Expand Up @@ -52,8 +58,6 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}



// task for downloading KillTheRng
//task downloadKTRNG(type: Copy) {
//group 'tasmod'
Expand All @@ -62,15 +66,15 @@ dependencies {
//into 'run/mods/'
//}

compileJava{
compileJava {
options.release = 8
}

// process fabric mod json
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft_version

filesMatching("fabric.mod.json") {
expand 'mod_url': project.mod_url, 'name': project.mod_name, 'mod_version': project.version, 'mod_description': project.mod_description, 'mod_sources': project.mod_sources, 'mod_email': project.mod_email
}
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G

# Fabric properties
minecraft_version=1.12.2
loader_version=0.15.9
loom_version=1.6-SNAPSHOT
loader_version=0.16.9
loom_version=1.8-SNAPSHOT

# Mod properties
mod_name=Tool-Assisted Speedrun Mod
Expand All @@ -16,4 +16,5 @@ mod_email=scribble@minecrafttas.com
# TASmod properties
group=com.minecrafttas
artifact=TASmod-1.12.2
version=Beta1.0-SNAPSHOT
version=Beta1.0
release=false
123 changes: 23 additions & 100 deletions src/main/java/com/minecrafttas/mctcommon/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,116 +1,45 @@
package com.minecrafttas.mctcommon;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.InvalidPropertiesFormatException;
import java.util.LinkedHashMap;
import java.util.List;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

import com.minecrafttas.mctcommon.Configuration.ConfigOptions;
import com.minecrafttas.mctcommon.registry.AbstractRegistry;
import com.minecrafttas.mctcommon.registry.Registerable;
import com.minecrafttas.mctcommon.ConfigurationRegistry.ConfigOptions;
import com.minecrafttas.mctcommon.file.AbstractDataFile;

/**
* A <i>very</i> simple configuration class
*
* @author Scribble
*/

public class Configuration extends AbstractRegistry<ConfigOptions> {
public class Configuration extends AbstractDataFile {

private File file;
private ConfigurationRegistry registry;

private Properties properties;

private String comment;

public Configuration(String comment, File configFile) {
super("Configuration", new LinkedHashMap<>());

file = configFile;
this.comment = comment;
public Configuration(String comment, Path configFile, ConfigurationRegistry registry) {
super(configFile, "config", comment);
this.registry = registry;
}

protected final List<ConfigOptions> configRegistry = new ArrayList<>();

@Override
public void register(ConfigOptions registryObject) {
if(registryObject == null) {
return;
}

if(configRegistry.contains(registryObject)) {
return;
}

configRegistry.add(registryObject);
}

@Override
public void unregister(ConfigOptions registryObject) {
if (registryObject == null) {
return;
}

if (!configRegistry.contains(registryObject)) {
return;
}

configRegistry.remove(registryObject);
}

public void load() {
if (file.exists()) {
properties = loadInner();
public void loadFromXML() {
if (Files.exists(file)) {
loadFromXML(file);
}
if (properties == null || !file.exists()) {
if (properties == null || !Files.exists(file)) {
properties = generateDefault();
save();
}
}

private Properties loadInner() {
FileInputStream fis;
Properties newProp = new Properties();
try {
fis = new FileInputStream(file);
newProp.loadFromXML(fis);
fis.close();
} catch (InvalidPropertiesFormatException e) {
MCTCommon.LOGGER.error("The config file could not be read", e);
return null;
} catch (FileNotFoundException e) {
MCTCommon.LOGGER.warn("No config file found: {}", file);
return null;
} catch (IOException e) {
MCTCommon.LOGGER.error("An error occured while reading the config", e);
return null;
}
return newProp;
}

public void save() {
save(file);
}

public void save(File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
properties.storeToXML(fos, comment, "UTF-8");
fos.close();
} catch (IOException e) {
e.printStackTrace();
saveToXML();
}
}

/**
* Generates the default property list from the values provided in {@link #registry}
* @return The default property list
*/
public Properties generateDefault() {
Properties newProperties = new Properties();
configRegistry.forEach((configOption)->{
registry.getConfigRegistry().forEach((configOption) -> {
newProperties.put(configOption.getConfigKey(), configOption.getDefaultValue());
});
return newProperties;
Expand All @@ -121,6 +50,7 @@ public String get(ConfigOptions configOption) {
}

public int getInt(ConfigOptions configOption) {
// TODO Add config exception or something... NumberFormatExceptions all around...
return Integer.parseInt(get(configOption));
}

Expand All @@ -133,11 +63,11 @@ public boolean has(ConfigOptions configOption) {
}

public void set(ConfigOptions configOption, String value) {
if(properties == null) {
if (properties == null) {
throw new NullPointerException("Config needs to be loaded first, before trying to set a value");
}
properties.setProperty(configOption.getConfigKey(), value);
save();
saveToXML();
}

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

public void delete(ConfigOptions configOption) {
properties.remove(configOption);
save();
}

public interface ConfigOptions extends Registerable {

public String getDefaultValue();

public String getConfigKey();
saveToXML();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.minecrafttas.mctcommon;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import com.minecrafttas.mctcommon.ConfigurationRegistry.ConfigOptions;
import com.minecrafttas.mctcommon.registry.AbstractRegistry;
import com.minecrafttas.mctcommon.registry.Registerable;

public class ConfigurationRegistry extends AbstractRegistry<ConfigOptions> {

protected final List<ConfigOptions> configRegistry = new ArrayList<>();

public ConfigurationRegistry() {
super("Configuration", new LinkedHashMap<>());
}

@Override
public void register(ConfigOptions registryObject) {
if (registryObject == null) {
return;
}

if (configRegistry.contains(registryObject)) {
return;
}

configRegistry.add(registryObject);
}

@Override
public void unregister(ConfigOptions registryObject) {
if (registryObject == null) {
return;
}

if (!configRegistry.contains(registryObject)) {
return;
}

configRegistry.remove(registryObject);
}

public List<ConfigOptions> getConfigRegistry() {
return configRegistry;
}

/**
* <p>Interface for registering your own options in the TASmod config
*
* @see com.minecrafttas.tasmod.registries.TASmodConfig TASmodConfig
* @author Scribble
*/
public interface ConfigOptions extends Registerable {
/**
* @return The config key name that is stored in the file
*/
public String getConfigKey();

/**
* @return The default value that is used if the config key doesn't exist yet
*/
public String getDefaultValue();
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/minecrafttas/mctcommon/MCTCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

public class MCTCommon {
public static final Logger LOGGER = LogManager.getLogger("MCTCommon");

public static final Marker Event = MarkerManager.getMarker("Event");

public static final Marker Server = MarkerManager.getMarker("Server");

public static final Marker Client = MarkerManager.getMarker("Client");

public static final Marker Timeout = MarkerManager.getMarker("Timeout");

}
Loading

0 comments on commit 96c1cbd

Please sign in to comment.