Save configs from ModMenu-Screen
This commit is contained in:
parent
092e0a39e8
commit
b369954c05
7 changed files with 68 additions and 24 deletions
|
@ -22,6 +22,7 @@ public abstract class Config {
|
|||
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
|
||||
protected final ConfigKeeper keeper;
|
||||
protected final boolean autoSync;
|
||||
public final String configID;
|
||||
|
||||
protected abstract void registerEntries();
|
||||
|
||||
|
@ -34,12 +35,13 @@ public abstract class Config {
|
|||
}
|
||||
|
||||
protected Config(String modID, String group, boolean autoSync, boolean diffContent) {
|
||||
configID = modID + "." + group;
|
||||
this.keeper = new ConfigKeeper(modID, group);
|
||||
this.registerEntries();
|
||||
this.autoSync = autoSync;
|
||||
|
||||
if (autoSync) {
|
||||
final String uid = CONFIG_SYNC_PREFIX + modID + "_" + group;
|
||||
final String uid = CONFIG_SYNC_PREFIX + configID;
|
||||
final AutoSyncID aid = new AutoSyncID(BCLib.MOD_ID, uid);
|
||||
if (diffContent)
|
||||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile(),this::compareForSync);
|
||||
|
@ -47,7 +49,7 @@ public abstract class Config {
|
|||
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
|
||||
|
||||
autoSyncConfigs.put(aid, this);
|
||||
BCLib.LOGGER.info("Added Config " + modID + "." + group + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
|
||||
BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ package ru.bclib.config;
|
|||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken.Bool;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken.Float;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken.Int;
|
||||
import ru.bclib.config.NamedPathConfig.ConfigToken.Str;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
@ -74,12 +78,19 @@ public class NamedPathConfig extends PathConfig{
|
|||
}
|
||||
|
||||
private void set(ConfigToken what, Object value) {
|
||||
BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
||||
if (what instanceof Bool) set(what, (boolean)value);
|
||||
else if (what instanceof Int) set(what, (int)value);
|
||||
else if (what instanceof Float) set(what, (float)value);
|
||||
else if (what instanceof Str) set(what, (String)value);
|
||||
else BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
||||
}
|
||||
|
||||
private Object get(ConfigToken what){
|
||||
BCLib.LOGGER.error("Accessing " + what + " as general type is not supported.");
|
||||
return null;
|
||||
if (what instanceof Bool) return get((Bool)what);
|
||||
else if (what instanceof Int) return get((Int)what);
|
||||
else if (what instanceof Float) return get((Float)what);
|
||||
else if (what instanceof Str) return get((Str)what);
|
||||
else return null;
|
||||
}
|
||||
|
||||
public void set(ConfigToken.Int what, int value) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue