Serialization + modmenu stuff

This commit is contained in:
SD 2021-01-11 12:24:25 +05:30
parent 4337af9aa6
commit fa9e5502a4
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5
2 changed files with 12 additions and 3 deletions

View file

@ -294,6 +294,14 @@ public final class ModConfig {
}
}
public static void serialize() {
try {
Files.write(CONFIG_PATH, GSON.toJson(CODEC.encodeStart(JsonOps.INSTANCE, INSTANCE).getOrThrow(false, System.err::println)).getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
LOGGER.error("An Unexpected error occured when serializing the Config", e);
}
}
public static int deserialize() {
LimboDecay.init();
try {
@ -313,8 +321,7 @@ public final class ModConfig {
).getOrThrow(false, System.err::println).getFirst();
return 1;
} catch (IOException e) {
LOGGER.error("An Unexpected error occured when deserializing the Config. Using default values for now.");
e.printStackTrace();
LOGGER.error("An Unexpected error occured when deserializing the Config. Using default values", e);
INSTANCE = FALLBACK;
return -1;
}

View file

@ -2,6 +2,8 @@ package org.dimdev.dimdoors.client.config;
import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.client.util.ScreenGenerator;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -10,6 +12,6 @@ import net.fabricmc.api.Environment;
public class ModMenuImpl implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return LoadConfigScreen::new;
return screen -> ScreenGenerator.create(screen, ModConfig.INSTANCE, ModConfig::serialize);
}
}