mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-26 23:03:15 +00:00
Port tag preference system from TiC
This commit is contained in:
1 parent
de08cc8808
commit
037e98c851
4 files changed
+327
-3
No files matched your search
@@ -3,10 +3,12 @@ package slimeknights.mantle.config;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.Builder;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import slimeknights.mantle.Mantle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -16,15 +18,20 @@ import java.util.function.Function;
|
||||
public class Config {
|
||||
/** List of all cached client config values, for cache clearing */
|
||||
private static final List<CachedValue<?>> CLIENT_VALUES = new ArrayList<>();
|
||||
private static final List<CachedValue<?>> SERVER_VALUES = new ArrayList<>();
|
||||
|
||||
/** If true, enables the heart renderer */
|
||||
public static final CachedBoolean EXTRA_HEART_RENDERER;
|
||||
|
||||
private static final ForgeConfigSpec.Builder CLIENT_BUILDER;
|
||||
public static final ForgeConfigSpec CLIENT_SPEC;
|
||||
/** List of preferences for tag outputs */
|
||||
public static final CachedValue<List<String>> TAG_PREFERENCES;
|
||||
|
||||
private static final ForgeConfigSpec.Builder CLIENT_BUILDER, SERVER_BUILDER;
|
||||
public static final ForgeConfigSpec CLIENT_SPEC, SERVER_SPEC;
|
||||
|
||||
static {
|
||||
CLIENT_BUILDER = new ForgeConfigSpec.Builder();
|
||||
SERVER_BUILDER = new ForgeConfigSpec.Builder();
|
||||
|
||||
// client options
|
||||
EXTRA_HEART_RENDERER = client(builder ->
|
||||
@@ -34,7 +41,14 @@ public class Config {
|
||||
.translation("config.mantle.extraHeartRenderer")
|
||||
.define("extraHeartRenderer", true));
|
||||
|
||||
// server options
|
||||
TAG_PREFERENCES = server(builder ->
|
||||
builder.comment("Preferences for outputs from tags used in automatic compat in recipes")
|
||||
.translation("config.mantle.tagPreferences")
|
||||
.define("tagPreferences", Arrays.asList("minecraft", "tconstruct", "tmechworks", "immersiveengineering", "mekanism", "thermalfoundation", "thermalexpansion")));
|
||||
|
||||
CLIENT_SPEC = CLIENT_BUILDER.build();
|
||||
SERVER_SPEC = SERVER_BUILDER.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +62,17 @@ public class Config {
|
||||
return cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cached boolean value for the client and adds it to the list to be invalidated on reload
|
||||
* @param function Lambda to get config value
|
||||
* @return Cached config value
|
||||
*/
|
||||
private static <T> CachedValue<T> server(Function<Builder,ConfigValue<T>> function) {
|
||||
CachedValue<T> cached = new CachedValue<>(function.apply(SERVER_BUILDER));
|
||||
SERVER_VALUES.add(cached);
|
||||
return cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to call when the config changes
|
||||
* @param configEvent Config event
|
||||
@@ -55,8 +80,11 @@ public class Config {
|
||||
public static void configChanged(final ModConfig.ModConfigEvent configEvent) {
|
||||
ModConfig config = configEvent.getConfig();
|
||||
if (config.getModId().equals(Mantle.modId)) {
|
||||
if (config.getSpec() == Config.CLIENT_SPEC) {
|
||||
ForgeConfigSpec spec = config.getSpec();
|
||||
if (spec == Config.CLIENT_SPEC) {
|
||||
CLIENT_VALUES.forEach(CachedValue::invalidate);
|
||||
} else if (spec == Config.SERVER_SPEC) {
|
||||
SERVER_VALUES.forEach(CachedValue::invalidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user