dacl dependency & translation support
This commit is contained in:
@@ -1,62 +1,15 @@
|
||||
package com.kasetoatz.fastghast.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import static com.kasetoatz.fastghast.Fastghast.CONFIG;
|
||||
|
||||
public class Config
|
||||
public class Config implements ModMenuApi
|
||||
{
|
||||
public static double UNMOUNTED_SPEED = 0.05;
|
||||
public static double MOUNTED_SPEED = 0.15;
|
||||
|
||||
private static final Path FILE = FabricLoader.getInstance().getConfigDir().resolve("fastghast.json");
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public static void load() {
|
||||
if (!Files.exists(FILE))
|
||||
{
|
||||
save();
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
String json = Files.readString(FILE);
|
||||
JsonObject data = GSON.fromJson(json, JsonObject.class);
|
||||
if (data.has("unmounted-speed"))
|
||||
{
|
||||
UNMOUNTED_SPEED = data.get("unmounted-speed").getAsDouble();
|
||||
}
|
||||
if (data.has("mounted-speed"))
|
||||
{
|
||||
MOUNTED_SPEED = data.get("mounted-speed").getAsDouble();
|
||||
}
|
||||
save();
|
||||
}
|
||||
catch (IOException exc)
|
||||
{
|
||||
throw new CrashException(CrashReport.create(exc, "Loading config file."));
|
||||
}
|
||||
}
|
||||
|
||||
private static void save()
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory()
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonObject data = new JsonObject();
|
||||
data.addProperty("unmounted-speed", UNMOUNTED_SPEED);
|
||||
data.addProperty("mounted-speed", MOUNTED_SPEED);
|
||||
Files.writeString(FILE, GSON.toJson(data));
|
||||
}
|
||||
catch (IOException exc)
|
||||
{
|
||||
throw new CrashException(CrashReport.create(exc, "Saving config file."));
|
||||
}
|
||||
return CONFIG::getUI;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user