mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Optimise ForgeConfigSpec and make Range public (#9827)
Backport of #9810 to 1.19.2
This commit is contained in:
1 parent
f0a7a457bb
commit
81f99b0116
2 files changed
+19
-19
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder
|
||||
plugins {
|
||||
id 'org.cadixdev.licenser' version '0.6.1'
|
||||
id 'com.github.ben-manes.versions' version '0.46.0'
|
||||
id 'net.minecraftforge.gradleutils' version '2.+'
|
||||
id 'net.minecraftforge.gradleutils' version '[2.2,2.3)'
|
||||
id 'eclipse'
|
||||
id 'de.undercouch.download' version '5.4.0'
|
||||
id 'net.minecraftforge.gradle.patcher' version '[6.0,6.2)' apply false
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraftforge.fml.config.IConfigSpec;
|
||||
@@ -53,15 +54,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfig> implements IConfigSpec<ForgeConfigSpec>//TODO: Remove extends and pipe everything through getSpec/getValues?
|
||||
{
|
||||
private Map<List<String>, String> levelComments;
|
||||
private Map<List<String>, String> levelTranslationKeys;
|
||||
private final Map<List<String>, String> levelComments;
|
||||
private final Map<List<String>, String> levelTranslationKeys;
|
||||
|
||||
private UnmodifiableConfig values;
|
||||
private final UnmodifiableConfig values;
|
||||
private Config childConfig;
|
||||
|
||||
private boolean isCorrecting = false;
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Pattern WINDOWS_NEWLINE = Pattern.compile("\r\n");
|
||||
|
||||
private ForgeConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map<List<String>, String> levelComments, Map<List<String>, String> levelTranslationKeys) {
|
||||
super(storage);
|
||||
@@ -123,11 +125,9 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
|
||||
private void resetCaches(final Iterable<Object> configValues) {
|
||||
configValues.forEach(value -> {
|
||||
if (value instanceof ConfigValue) {
|
||||
final ConfigValue<?> configValue = (ConfigValue<?>) value;
|
||||
if (value instanceof ConfigValue<?> configValue) {
|
||||
configValue.clearCache();
|
||||
} else if (value instanceof Config) {
|
||||
final Config innerConfig = (Config) value;
|
||||
} else if (value instanceof Config innerConfig) {
|
||||
this.resetCaches(innerConfig.valueMap().values());
|
||||
}
|
||||
});
|
||||
@@ -268,10 +268,10 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
{
|
||||
if (obj1 instanceof String string1 && obj2 instanceof String string2)
|
||||
{
|
||||
if (string1.length() > 0 && string2.length() > 0)
|
||||
if (!string1.isEmpty() && !string2.isEmpty())
|
||||
{
|
||||
return string1.replaceAll("\r\n", "\n")
|
||||
.equals(string2.replaceAll("\r\n", "\n"));
|
||||
return WINDOWS_NEWLINE.matcher(string1).replaceAll("\n")
|
||||
.equals(WINDOWS_NEWLINE.matcher(string2).replaceAll("\n"));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -283,10 +283,10 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
{
|
||||
private final Config storage = Config.of(LinkedHashMap::new, InMemoryFormat.withUniversalSupport()); // Use LinkedHashMap for consistent ordering
|
||||
private BuilderContext context = new BuilderContext();
|
||||
private Map<List<String>, String> levelComments = new HashMap<>();
|
||||
private Map<List<String>, String> levelTranslationKeys = new HashMap<>();
|
||||
private List<String> currentPath = new ArrayList<>();
|
||||
private List<ConfigValue<?>> values = new ArrayList<>();
|
||||
private final Map<List<String>, String> levelComments = new HashMap<>();
|
||||
private final Map<List<String>, String> levelTranslationKeys = new HashMap<>();
|
||||
private final List<String> currentPath = new ArrayList<>();
|
||||
private final List<ConfigValue<?>> values = new ArrayList<>();
|
||||
|
||||
//Object
|
||||
public <T> ConfigValue<T> define(String path, T defaultValue) {
|
||||
@@ -370,7 +370,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
LOGGER.debug(CORE, "List on key {} is deemed to need correction. It is null, not a list, or an empty list. Modders, consider defineListAllowEmpty?", path.get(path.size() - 1));
|
||||
return getDefault();
|
||||
}
|
||||
List<?> list = Lists.newArrayList((List<?>) value);
|
||||
List<?> list = new ArrayList<>((List<?>) value);
|
||||
list.removeIf(elementValidator.negate());
|
||||
if (list.isEmpty()) {
|
||||
LOGGER.debug(CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
|
||||
@@ -390,7 +390,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
LOGGER.debug(CORE, "List on key {} is deemed to need correction, as it is null or not a list.", path.get(path.size() - 1));
|
||||
return getDefault();
|
||||
}
|
||||
List<?> list = Lists.newArrayList((List<?>) value);
|
||||
List<?> list = new ArrayList<>((List<?>) value);
|
||||
list.removeIf(elementValidator.negate());
|
||||
if (list.isEmpty()) {
|
||||
LOGGER.debug(CORE, "List on key {} is deemed to need correction. It failed validation.", path.get(path.size() - 1));
|
||||
@@ -691,7 +691,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Range<V extends Comparable<? super V>> implements Predicate<Object>
|
||||
public static class Range<V extends Comparable<? super V>> implements Predicate<Object>
|
||||
{
|
||||
private final Class<? extends V> clazz;
|
||||
private final V min;
|
||||
@@ -821,7 +821,7 @@ public class ForgeConfigSpec extends UnmodifiableConfigWrapper<UnmodifiableConfi
|
||||
|
||||
public List<String> getPath()
|
||||
{
|
||||
return Lists.newArrayList(path);
|
||||
return new ArrayList<>(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user