Biome include lists

This commit is contained in:
paulevsGitch 2021-11-20 20:24:00 +03:00
parent c0b7ccca72
commit df214cdb24
8 changed files with 57 additions and 13 deletions

View file

@ -21,8 +21,8 @@ import java.util.List;
import java.util.Map;
public abstract class Config {
protected final static Map<AutoSyncID, Config> AUTO_SYNC_CONFIGS = new HashMap<>();
public static final String CONFIG_SYNC_PREFIX = "CONFIG_";
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
protected final ConfigKeeper keeper;
protected final boolean autoSync;
public final String configID;
@ -51,7 +51,7 @@ public abstract class Config {
else
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
autoSyncConfigs.put(aid, this);
AUTO_SYNC_CONFIGS.put(aid, this);
BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
}
}
@ -70,7 +70,7 @@ public abstract class Config {
}
public static void reloadSyncedConfig(AutoSyncID aid, File file) {
Config cfg = autoSyncConfigs.get(aid);
Config cfg = AUTO_SYNC_CONFIGS.get(aid);
if (cfg != null) {
cfg.reload();
}

View file

@ -23,9 +23,9 @@ import java.util.function.Supplier;
public final class ConfigKeeper {
private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
private JsonObject configObject;
private final ConfigWriter writer;
private JsonObject configObject;
private boolean changed = false;
public ConfigKeeper(String modID, String group) {
@ -33,7 +33,7 @@ public final class ConfigKeeper {
this.configObject = writer.load();
}
File getConfigFile() {
public File getConfigFile() {
return this.writer.getConfigFile();
}
@ -141,7 +141,9 @@ public final class ConfigKeeper {
}
String paramKey = key.getEntry();
paramKey += " [default: " + entry.getDefault() + "]";
if (entry.hasDefaultInName()) {
paramKey += " [default: " + entry.getDefault() + "]";
}
this.changed |= entry.setLocation(obj, paramKey);
}
@ -328,7 +330,6 @@ public final class ConfigKeeper {
}
public static class StringArrayEntry extends ArrayEntry<String> {
public StringArrayEntry(List<String> defaultValue) {
super(defaultValue);
}
@ -341,10 +342,14 @@ public final class ConfigKeeper {
protected void add(JsonArray array, String el){
array.add(el);
}
@Override
protected boolean hasDefaultInName() {
return false;
}
}
public static class EnumEntry<T extends Enum<T>> extends Entry<T> {
private final Type type;
public EnumEntry(T defaultValue) {
@ -372,7 +377,6 @@ public final class ConfigKeeper {
}
public static abstract class RangeEntry<T extends Comparable<T>> extends Entry<T> {
private final T min, max;
public RangeEntry(T defaultValue, T minVal, T maxVal) {
@ -396,7 +400,6 @@ public final class ConfigKeeper {
}
public static abstract class Entry<T> {
protected final T defaultValue;
protected Consumer<T> writer;
protected Supplier<T> reader;
@ -448,5 +451,9 @@ public final class ConfigKeeper {
public void setDefault() {
this.setValue(defaultValue);
}
protected boolean hasDefaultInName() {
return true;
}
}
}

View file

@ -3,6 +3,9 @@ package ru.bclib.config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import ru.bclib.BCLib;
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import java.util.Collections;
public class Configs {
// Client and Server-Config must be the first entries. They are not part of the Auto-Sync process
@ -13,15 +16,22 @@ public class Configs {
public static final PathConfig GENERATOR_CONFIG = new PathConfig(BCLib.MOD_ID, "generator", false);
public static final PathConfig MAIN_CONFIG = new PathConfig(BCLib.MOD_ID, "main", true, true);
public static final String MAIN_PATCH_CATEGORY = "patches";
public static final PathConfig RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes");
public static final PathConfig BIOMES_CONFIG = new PathConfig(BCLib.MOD_ID, "biomes", false);
public static final String MAIN_PATCH_CATEGORY = "patches";
public static void save() {
MAIN_CONFIG.saveChanges();
RECIPE_CONFIG.saveChanges();
GENERATOR_CONFIG.saveChanges();
initForcedConfig();
}
private static void initForcedConfig() {
BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST));
BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("nether_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST));
BIOMES_CONFIG.saveChanges();
}
}

View file

@ -6,7 +6,6 @@ import ru.bclib.config.ConfigKeeper.FloatRange;
import ru.bclib.config.ConfigKeeper.IntegerRange;
public class PathConfig extends Config {
public PathConfig(String modID, String group, boolean autoSync, boolean diffContent) {
super(modID, group, autoSync, diffContent);
}