diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/AbstractComponentContainer.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/AbstractComponentContainer.java index 28570bea..926906f7 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/AbstractComponentContainer.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/AbstractComponentContainer.java @@ -99,14 +99,7 @@ public void fromTag(NbtCompound tag) { } } - for (String missedKeyId : componentMap.getKeys()) { - Identifier id = Identifier.tryParse(missedKeyId); - String cause; - if (id == null) cause = "invalid identifier"; - else if (ComponentRegistry.get(id) == null) cause = "unregistered key"; - else cause = "provider does not have "; - ComponentsInternals.LOGGER.warn("Failed to deserialize component: {} {}", cause, missedKeyId); - } + ComponentsInternals.logDeserializationWarnings(componentMap.getKeys()); } } diff --git a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/ComponentsInternals.java b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/ComponentsInternals.java index 9df5b5b5..24509e15 100644 --- a/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/ComponentsInternals.java +++ b/cardinal-components-base/src/main/java/dev/onyxstudios/cca/internal/base/ComponentsInternals.java @@ -22,17 +22,49 @@ */ package dev.onyxstudios.cca.internal.base; +import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; import dev.onyxstudios.cca.internal.base.asm.StaticComponentLoadingException; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.Reader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; +import java.util.Properties; public final class ComponentsInternals { public static final Logger LOGGER = LogManager.getLogger("Cardinal Components API"); + private static boolean logDeserializationWarnings = true; + + public static void init() { + Path path = FabricLoader.getInstance().getConfigDir().resolve("cardinal-components-api.properties"); + try(Reader reader = Files.newBufferedReader(path)) { + Properties cfg = new Properties(); + cfg.load(reader); + logDeserializationWarnings = Boolean.parseBoolean(cfg.getProperty("log-deserialization-warnings", "true")); + } catch (IOException e) { + try { + Files.writeString(path, """ + # If set to false, warnings will not get logged when a component fails to be resolved (typically due to mods being removed) + # Default value: true + log-deserialization-warnings = true + + # Internal value, do not edit or your changes may be arbitrarily reset + config-version = 1 + """); + } catch (IOException ex) { + LOGGER.error("Failed to write config file at {}", path); + } + } + } @Nonnull public static R createFactory(Class factoryClass) { @@ -48,4 +80,17 @@ public static R createFactory(Class factoryClass) { throw new StaticComponentLoadingException("Failed to instantiate generated component factory", e); } } + + public static void logDeserializationWarnings(Collection missedKeyIds) { + if (logDeserializationWarnings) { + for (String missedKeyId : missedKeyIds) { + Identifier id = Identifier.tryParse(missedKeyId); + String cause; + if (id == null) cause = "invalid identifier"; + else if (ComponentRegistry.get(id) == null) cause = "unregistered key"; + else cause = "provider does not have "; + LOGGER.warn("Failed to deserialize component: {} {}", cause, missedKeyId); + } + } + } } diff --git a/cardinal-components-base/src/main/resources/fabric.mod.json b/cardinal-components-base/src/main/resources/fabric.mod.json index a01c12cc..2df8c97c 100644 --- a/cardinal-components-base/src/main/resources/fabric.mod.json +++ b/cardinal-components-base/src/main/resources/fabric.mod.json @@ -6,6 +6,11 @@ "description": "dynamically exposing components", "version": "${version}", "icon": "assets/cardinal-components-base/icon.png", + "entrypoints": { + "main": [ + "dev.onyxstudios.cca.internal.base.ComponentsInternals::init" + ] + }, "custom": { "modmenu": { "badges": [ "library" ], diff --git a/changelog.md b/changelog.md index bc243a4a..d550cb85 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,13 @@ +------------------------------------------------------ +Version 4.2.0 +------------------------------------------------------ +**Additions** +- Players can now set the `log-deserialization-warnings` option to toggle warnings when a component fails to be resolved + (typically due to mods being removed) + +**Mod Compatibility** +- Fixed incompatibility with Immersive Portals + ------------------------------------------------------ Version 4.1.4 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index 611db04b..0374504b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_api_version=0.47.8+1.18.2 elmendorf_version=0.5.2 #Publishing -mod_version = 4.1.4 +mod_version = 4.2.0 curseforge_id = 318449 modrinth_id = K01OU20C curseforge_versions = 1.18; 1.18.1; 1.18.2