From fd1948939a5978832ce5da5bb2dbbd0df49a2ac3 Mon Sep 17 00:00:00 2001 From: Anthony Hilyard Date: Thu, 19 May 2022 15:53:47 -0700 Subject: Bumped required forge version to 40.1, fixed IcebergConfig crash. --- .../iceberg/config/IcebergConfigSpec.java | 37 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java') diff --git a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java index 01a5e40..89b81b2 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java +++ b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfigSpec.java @@ -3,7 +3,6 @@ package com.anthonyhilyard.iceberg.config; import java.io.File; import java.lang.reflect.Field; import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -23,6 +22,7 @@ import net.minecraftforge.fml.Logging; import net.minecraftforge.fml.config.IConfigSpec; import net.minecraftforge.fml.unsafe.UnsafeHacks; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; @@ -48,18 +48,20 @@ import com.google.common.collect.Lists; */ public class IcebergConfigSpec extends UnmodifiableConfigWrapper implements IConfigSpec { - private Map, String> levelComments = new HashMap<>(); + private Map, String> levelComments; + private Map, String> levelTranslationKeys; private UnmodifiableConfig values; private Config childConfig; private boolean isCorrecting = false; - private IcebergConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map, String> levelComments) + private IcebergConfigSpec(UnmodifiableConfig storage, UnmodifiableConfig values, Map, String> levelComments, Map, String> levelTranslationKeys) { super(storage); this.values = values; this.levelComments = levelComments; + this.levelTranslationKeys = levelTranslationKeys; // Update the filewatcher's default instance to have a more sensible exception handler. try @@ -72,6 +74,16 @@ public class IcebergConfigSpec extends UnmodifiableConfigWrapper path) + { + return levelComments.get(path); + } + + public String getLevelTranslationKey(List path) + { + return levelTranslationKeys.get(path); + } + public void setConfig(CommentedConfig config) { this.childConfig = config; @@ -391,7 +403,10 @@ public class IcebergConfigSpec extends UnmodifiableConfigWrapper> values = UnsafeHacks.>>getField(valuesField, this); Config storage = UnsafeHacks.getField(storageField, this); Map, String> levelComments = UnsafeHacks., String>>getField(levelCommentsField, this); + Map, String> levelTranslationKeys = UnsafeHacks., String>>getField(levelTranslationKeysField, this); Config valueCfg = Config.of(Config.getDefaultMapCreator(true, true), InMemoryFormat.withSupport(ConfigValue.class::isAssignableFrom)); values.forEach(v -> valueCfg.set(v.getPath(), v)); - final IcebergConfigSpec ret = new IcebergConfigSpec(storage, valueCfg, levelComments); + final IcebergConfigSpec ret = new IcebergConfigSpec(storage, valueCfg, levelComments, levelTranslationKeys); values.forEach(v -> { try { Field specField = ConfigValue.class.getDeclaredField("spec"); UnsafeHacks.setField(specField, v, ret); } - catch (Exception e) { } + catch (Exception e) { + Loader.LOGGER.warn("Failed to create spec field {}!", v.toString()); + Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e)); + } }); result = ret; } - catch (Exception e) { } + catch (Exception e) { + Loader.LOGGER.warn("Failed to build IcebergConfigSpec!"); + Loader.LOGGER.warn(ExceptionUtils.getStackTrace(e)); + } return result; } -- cgit