mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 12:37:59 +01:00
Have forge config use the right class
This commit is contained in:
parent
e30cf4cb3e
commit
4e069637a7
2 changed files with 12 additions and 27 deletions
|
@ -2,16 +2,13 @@ package com.minelittlepony.client;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.minelittlepony.client.settings.ClientPonyConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class Config extends ClientPonyConfig {
|
||||
static final Gson gson = new GsonBuilder()
|
||||
|
@ -19,19 +16,16 @@ class Config extends ClientPonyConfig {
|
|||
.excludeFieldsWithoutExposeAnnotation()
|
||||
.create();
|
||||
|
||||
private final File configFile;
|
||||
private final Path configFile;
|
||||
|
||||
Config(File file) {
|
||||
Config(Path file) {
|
||||
configFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (configFile.exists()) {
|
||||
configFile.delete();
|
||||
}
|
||||
|
||||
try (JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(configFile)))) {
|
||||
try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(configFile))) {
|
||||
writer.setIndent(" ");
|
||||
|
||||
gson.toJson(this, Config.class, writer);
|
||||
|
@ -40,12 +34,12 @@ class Config extends ClientPonyConfig {
|
|||
}
|
||||
}
|
||||
|
||||
static Config of(File file) {
|
||||
static Config of(Path file) {
|
||||
Config result = null;
|
||||
|
||||
if (file.exists()) {
|
||||
try (FileInputStream s = new FileInputStream(file)) {
|
||||
result = gson.fromJson(new JsonReader(new InputStreamReader(s)), Config.class);
|
||||
if (Files.exists(file)) {
|
||||
try (BufferedReader s = Files.newBufferedReader(file)) {
|
||||
result = gson.fromJson(s, Config.class);
|
||||
} catch (IOException ignored) {
|
||||
result = null;
|
||||
}
|
||||
|
|
|
@ -14,11 +14,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
|||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import com.minelittlepony.client.IModUtilities;
|
||||
import com.minelittlepony.client.MineLPClient;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
@Mod("minelittlepony")
|
||||
public class ForgeModMineLittlePony implements IModUtilities {
|
||||
|
@ -33,12 +29,7 @@ public class ForgeModMineLittlePony implements IModUtilities {
|
|||
|
||||
private void init(final FMLCommonSetupEvent event) {
|
||||
|
||||
// TODO: I don't know what forge did with `event.getModConfigurationDirectory()` but it's not where it used to be.
|
||||
|
||||
File configDirectory = new File(Minecraft.getInstance().getFileResourcePacks().getParentFile(), "config");
|
||||
File configFile = new File(configDirectory, "minelittlepony.json");
|
||||
|
||||
mlp.init(Config.of(configFile));
|
||||
mlp.init(Config.of(FMLPaths.CONFIGDIR.get().resolve("minelittlepony.json")));
|
||||
}
|
||||
|
||||
private void posInit(FMLClientSetupEvent event) {
|
||||
|
|
Loading…
Reference in a new issue