Adding enabled predicate

This commit is contained in:
Frank 2021-08-21 09:49:15 +02:00
parent b369954c05
commit 0adc5024f1

View file

@ -11,34 +11,48 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
public class NamedPathConfig extends PathConfig{ public class NamedPathConfig extends PathConfig{
public abstract static class ConfigToken extends ConfigKey{ public abstract static class ConfigToken <T> extends ConfigKey{
public static class Int extends ConfigToken{ public static class Int extends ConfigToken<Integer>{
public final int defaultValue; public Int(int def, String entry, ResourceLocation path) { this(def, entry, path.getNamespace(), path.getPath());}
public Int(int def, String entry, String... path) { super(entry, path); this.defaultValue=def;} public Int(int def, String entry, String... path) { super(def, entry, path);}
public Int(int def, String entry, ResourceLocation path) { super(entry, path); this.defaultValue=def;}
} }
public static class Float extends ConfigToken{ public static class Float extends ConfigToken<java.lang.Float>{
public final float defaultValue; public Float(float def, String entry, ResourceLocation path) { this(def, entry, path.getNamespace(), path.getPath());}
public Float(float def, String entry, String... path) { super(entry, path); this.defaultValue=def;} public Float(float def, String entry, String... path) { super(def, entry, path); }
public Float(float def, String entry, ResourceLocation path) { super(entry, path); this.defaultValue=def;}
} }
public static class Bool extends ConfigToken{ public static class Bool extends ConfigToken<Boolean>{
public final boolean defaultValue; public Bool(boolean def, String entry, ResourceLocation path) { this(def, entry, path.getNamespace(), path.getPath());}
public Bool(boolean def, String entry, String... path) { super(entry, path); this.defaultValue=def;} public Bool(boolean def, String entry, String... path) { super(def, entry, path); }
public Bool(boolean def, String entry, ResourceLocation path) { super(entry, path); this.defaultValue=def;}
} }
public static class Str extends ConfigToken{ public static class Str extends ConfigToken<String>{
public final String defaultValue; public Str(String def, String entry, ResourceLocation path) { this(def, entry, path.getNamespace(), path.getPath());}
public Str(String def, String entry, String... path) { super(entry, path); this.defaultValue=def;} public Str(String def, String entry, String... path) { super(def, entry, path); }
public Str(String def, String entry, ResourceLocation path) { super(entry, path); this.defaultValue=def;}
} }
ConfigToken(String entry, String... path) { super(entry, path); }
ConfigToken(String entry, ResourceLocation path) { super(entry, path); } public static final Predicate<NamedPathConfig> ALWAYS_ENABLED = (config) -> true;
public final T defaultValue;
protected final Predicate<NamedPathConfig> enabled;
ConfigToken(T defaultValue, String entry, ResourceLocation path) { this(defaultValue, entry, path.getNamespace(), path.getPath()); }
ConfigToken(T defaultValue, String entry, String... path) { this(defaultValue, ALWAYS_ENABLED, entry, path); }
ConfigToken(T defaultValue, String entry, ResourceLocation path, Predicate<NamedPathConfig> enabled) { this(defaultValue, enabled, entry, path.getNamespace(), path.getPath()); }
ConfigToken(T defaultValue, String entry, String path, Predicate<NamedPathConfig> enabled) { this(defaultValue, enabled, entry, path); }
ConfigToken(T defaultValue, String entry, String[] path, Predicate<NamedPathConfig> enabled) { this(defaultValue, enabled, entry, path); }
private ConfigToken(T defaultValue, Predicate<NamedPathConfig> enabled, String entry, String... path) {
super(entry, path);
this.enabled = enabled;
this.defaultValue = defaultValue
}
} }
public NamedPathConfig(String modID, String group, boolean autoSync, boolean diffContent) { public NamedPathConfig(String modID, String group, boolean autoSync, boolean diffContent) {