From 4196a772c2ac6bf3dd93cbbf81ee730250f5d251 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:31:01 +0200 Subject: [PATCH] Add reason field support to mandatory deps (#397) --- gradle.properties | 2 +- src/main/java/net/neoforged/neoforge/common/I18nExtension.java | 3 +++ src/main/resources/assets/neoforge/lang/en_us.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3a0a84adf3..e8130e06a4 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/java/net/neoforged/neoforge/common/I18nExtension.java b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java index 906a8128de..86efcbb674 100644 --- a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Supplier; import java.util.regex.Pattern; @@ -55,6 +56,8 @@ public class I18nExtension { 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))))); + // {0,optional,[prefix]} -> append String value of o if the optional is present, with an optional prefix at the start + customFactories.put("optional", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, o) -> ((Optional) o).ifPresent(val -> stringBuffer.append(formatString == null ? "" : formatString).append(val)))); } private static void parseException(final String formatString, final StringBuffer stringBuffer, final Object objectToParse) { diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 577ebd624a..12dffffe5f 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -66,7 +66,7 @@ "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": "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}§r\n{7,optional,§7Reason for the dependency: §r}", "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.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",