From d813ba979fc054214025d3df3847aeb609641965 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 14:49:45 +0200 Subject: [PATCH 1/5] Add an incompatible/conflicting clause to mod dependency --- gradle.properties | 4 ++-- .../neoforged/neoforge/common/I18nExtension.java | 16 +++++++++++++--- .../resources/assets/neoforge/lang/en_us.json | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index b8c9d1db22..91c1300757 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ java_version=17 minecraft_version=1.20.4 neoform_version=20231207.154220 -spi_version=8.0.0 +spi_version=8.0.7-breaks-clause mergetool_version=2.0.0 accesstransformers_version=10.0.1 coremods_version=6.0.2 @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=2.0.0 +fancy_mod_loader_version=2.0.1 mojang_logging_version=1.1.1 log4j_version=2.19.0 guava_version=31.1.2-jre diff --git a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java index 3e03e45914..846add3fc6 100644 --- a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java @@ -13,6 +13,7 @@ import java.util.Map; import java.util.Objects; import java.util.function.BiConsumer; +import java.util.function.Supplier; import java.util.regex.Pattern; import net.neoforged.fml.Logging; import net.neoforged.fml.loading.StringUtils; @@ -50,6 +51,8 @@ public class I18nExtension { customFactories.put("featurebound", (name, formatString, locale) -> new CustomReadOnlyFormat(MavenVersionStringHelper::parseFeatureBoundValue)); // {0,i18n,fml.message} -> pass object to i18n string 'fml.message' customFactories.put("i18n", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, o) -> stringBuffer.append(I18nExtension.parseMessage(formatString, o)))); + // {0,i18ntranslate} -> attempt to use the argument as a translation key + customFactories.put("i18ntranslate", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, o) -> stringBuffer.append(I18nExtension.parseMessage((String) o)))); // {0,ornull,fml.absent} -> append String value of o, or i18n string 'fml.absent' (message format transforms nulls into the string literal "null") customFactories.put("ornull", ((name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, o) -> stringBuffer.append(Objects.equals(String.valueOf(o), "null") ? I18nExtension.parseMessage(formatString) : String.valueOf(o))))); } @@ -72,8 +75,12 @@ private static void parseModInfo(final String formatString, final StringBuffer s } } - public static String getPattern(final String patternName) { - return i18n == null ? patternName : i18n.getOrDefault(patternName, patternName); + public static String getPattern(final String patternName, final Supplier fallback) { + if (i18n == null) { + return fallback.get(); + } + final var translated = i18n.get(patternName); + return translated == null ? fallback.get() : translated; } public static void loadLanguageData(final Map properties) { @@ -82,7 +89,10 @@ public static void loadLanguageData(final Map properties) { } public static String parseMessage(final String i18nMessage, Object... args) { - final String pattern = getPattern(i18nMessage); + return parseMessageWithFallback(i18nMessage, () -> i18nMessage, args); + } + public static String parseMessageWithFallback(final String i18nMessage, final Supplier fallback, Object... args) { + final String pattern = getPattern(i18nMessage, fallback); try { return parseFormat(pattern, args); } catch (IllegalArgumentException e) { diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 82f2e254d5..59dfbb37cf 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -65,8 +65,14 @@ "fml.modloading.uncaughterror":"An uncaught parallel processing error has occurred.\n\u00a77{2,exc,msg}", "fml.modloading.errorduringevent":"{0,modinfo,name} ({0,modinfo,id}) encountered an error during the {1,lower} event phase\n\u00a77{2,exc,msg}", "fml.modloading.failedtoloadforge": "Failed to load NeoForge", + "fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}", "fml.modloading.missingdependency.optional": "Mod \u00a7e{4}\u00a7r only supports \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}", + "fml.modloading.incompatiblemod": "Mod \u00a7e{4}\u00a7r is §cincompatible§r with \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}§r\n§7The reason is:§r §o{7,i18ntranslate}§r", + "fml.modloading.conflictingmod": "Mod \u00a7e{3}\u00a7r §dconflicts§r with \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r\nProceed at your own risk", + "fml.modloading.incompatiblemod.noreason": "§4No reason provided§r", + "fml.modloading.conflictingmod.noreason": "§4No reason provided§r", + "fml.dependencyloading.conflictingdependencies": "Some mods have requested conflicting versions of: \u00a76{3}\u00a7r. Requested by: \u00a7e{4}\u00a7r.", "fml.dependencyloading.mismatchedcontaineddependencies": "Some mods have agreed upon an acceptable version range for : \u00a76{3}\u00a7r, but no jar was provided which matched the range. Requested by: \u00a7e{4}\u00a7r.", "fml.modloading.cycle": "Detected a mod dependency cycle: {0}", From 7d8652268eac6b78947dc6086055c6eda7a01d40 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 15:01:18 +0200 Subject: [PATCH 2/5] Update message --- gradle.properties | 2 +- src/main/resources/assets/neoforge/lang/en_us.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 91c1300757..a2fbd4422b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=2.0.1 +fancy_mod_loader_version=2.0.3 mojang_logging_version=1.1.1 log4j_version=2.19.0 guava_version=31.1.2-jre diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 59dfbb37cf..d66324bb10 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -69,7 +69,9 @@ "fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}", "fml.modloading.missingdependency.optional": "Mod \u00a7e{4}\u00a7r only supports \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}", "fml.modloading.incompatiblemod": "Mod \u00a7e{4}\u00a7r is §cincompatible§r with \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}§r\n§7The reason is:§r §o{7,i18ntranslate}§r", - "fml.modloading.conflictingmod": "Mod \u00a7e{3}\u00a7r §dconflicts§r with \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r\nProceed at your own risk", + "fml.modloading.conflictingmod": "Mod \u00a7e{3}\u00a7r §dconflicts§r with \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r", + "fml.modloading.conflictingmod.proceed": "Proceed at your own risk", + "fml.modloading.incompatiblemod.noreason": "§4No reason provided§r", "fml.modloading.conflictingmod.noreason": "§4No reason provided§r", From 80517c480074aeaae0aced0c6c5c025a40288ca9 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 15:05:30 +0200 Subject: [PATCH 3/5] Yellow --- src/main/resources/assets/neoforge/lang/en_us.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index d66324bb10..0d986e5e12 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -72,8 +72,8 @@ "fml.modloading.conflictingmod": "Mod \u00a7e{3}\u00a7r §dconflicts§r with \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r", "fml.modloading.conflictingmod.proceed": "Proceed at your own risk", - "fml.modloading.incompatiblemod.noreason": "§4No reason provided§r", - "fml.modloading.conflictingmod.noreason": "§4No reason provided§r", + "fml.modloading.incompatiblemod.noreason": "§eNo reason provided§r", + "fml.modloading.conflictingmod.noreason": "§eNo reason provided§r", "fml.dependencyloading.conflictingdependencies": "Some mods have requested conflicting versions of: \u00a76{3}\u00a7r. Requested by: \u00a7e{4}\u00a7r.", "fml.dependencyloading.mismatchedcontaineddependencies": "Some mods have agreed upon an acceptable version range for : \u00a76{3}\u00a7r, but no jar was provided which matched the range. Requested by: \u00a7e{4}\u00a7r.", From c36a7a86a0ed939286c18bef93aa85b4e6e0cdad Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 16:06:11 +0200 Subject: [PATCH 4/5] discouraged --- gradle.properties | 2 +- src/main/resources/assets/neoforge/lang/en_us.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index a2fbd4422b..667bc3696e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=2.0.3 +fancy_mod_loader_version=2.0.4 mojang_logging_version=1.1.1 log4j_version=2.19.0 guava_version=31.1.2-jre diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 0d986e5e12..88c0e0b66f 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -69,11 +69,11 @@ "fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}", "fml.modloading.missingdependency.optional": "Mod \u00a7e{4}\u00a7r only supports \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}", "fml.modloading.incompatiblemod": "Mod \u00a7e{4}\u00a7r is §cincompatible§r with \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}§r\n§7The reason is:§r §o{7,i18ntranslate}§r", - "fml.modloading.conflictingmod": "Mod \u00a7e{3}\u00a7r §dconflicts§r with \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r", - "fml.modloading.conflictingmod.proceed": "Proceed at your own risk", + "fml.modloading.discouragedmod": "Mod \u00a7e{3}\u00a7r §ddiscourages§r the use of \u00a73{2}\u00a7r \u00a7o{4,vr}\u00a7r\n\u00a77Currently, \u00a73{2}\u00a7r\u00a77 is \u00a7o{5}§r\n§7The reason is:§r §o{6,i18ntranslate}§r", + "fml.modloading.discouragedmod.proceed": "Proceed at your own risk", "fml.modloading.incompatiblemod.noreason": "§eNo reason provided§r", - "fml.modloading.conflictingmod.noreason": "§eNo reason provided§r", + "fml.modloading.discouragedmod.noreason": "§eNo reason provided§r", "fml.dependencyloading.conflictingdependencies": "Some mods have requested conflicting versions of: \u00a76{3}\u00a7r. Requested by: \u00a7e{4}\u00a7r.", "fml.dependencyloading.mismatchedcontaineddependencies": "Some mods have agreed upon an acceptable version range for : \u00a76{3}\u00a7r, but no jar was provided which matched the range. Requested by: \u00a7e{4}\u00a7r.", From 7d15d509220c561eeed961d43822a234a500f431 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 23:19:07 +0200 Subject: [PATCH 5/5] Update --- gradle.properties | 4 ++-- .../java/net/neoforged/neoforge/common/I18nExtension.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 667bc3696e..3a0a84adf3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ java_version=17 minecraft_version=1.20.4 neoform_version=20231207.154220 -spi_version=8.0.7-breaks-clause +spi_version=9.0.2 mergetool_version=2.0.0 accesstransformers_version=10.0.1 coremods_version=6.0.2 @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1 slf4j_api_version=2.0.7 apache_maven_artifact_version=3.8.5 jarjar_version=0.4.0 -fancy_mod_loader_version=2.0.4 +fancy_mod_loader_version=2.0.3 mojang_logging_version=1.1.1 log4j_version=2.19.0 guava_version=31.1.2-jre diff --git a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java index 846add3fc6..906a8128de 100644 --- a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java @@ -91,6 +91,7 @@ public static void loadLanguageData(final Map properties) { public static String parseMessage(final String i18nMessage, Object... args) { return parseMessageWithFallback(i18nMessage, () -> i18nMessage, args); } + public static String parseMessageWithFallback(final String i18nMessage, final Supplier fallback, Object... args) { final String pattern = getPattern(i18nMessage, fallback); try {