Skip to content

Commit

Permalink
Deprecate the mandatory field and add an incompatible/discouraged cla…
Browse files Browse the repository at this point in the history
…use to mod dependency (#386)

The `mandatory` field is now deprecated, and use of it will **crash** in a development environment.
The field has been replaced with a `type` field, accepting a string with one of 4 possible values (case insensitive):
- `required`: - default, will not allow the game to load _without_ the dependency
- `optional`: will _allow_ the game to load without the dependency
- `incompatible`: will _prevent_ the game from loading when the dependency is present
- `discouraged`: will _show a warning_ when the dependency is present, but will continue loading

For `incompatible` and `discouraged` a `reason` string field has been added that will be shown to users. Please use this field and provide descriptive reasons as to why your mod is incompatible with the other.

Example:
```toml
[[dependencies.mymod]]
type="discouraged" # can be "incompatible"
modId="othermod"
versionRange="[1.4.3,)" # optional, will match any version by default
reason="We conflict because the other mod does...."
```
  • Loading branch information
Matyrobbrt authored Dec 16, 2023
1 parent f2ecd67 commit 8786a13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ java_version=17
minecraft_version=1.20.4
neoform_version=20231207.154220

spi_version=9.0.1
spi_version=9.0.2
mergetool_version=2.0.0
accesstransformers_version=10.0.1
coremods_version=6.0.2
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/net/neoforged/neoforge/common/I18nExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))));
}
Expand All @@ -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<String> 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<String, String> properties) {
Expand All @@ -82,7 +89,11 @@ public static void loadLanguageData(final Map<String, String> 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<String> fallback, Object... args) {
final String pattern = getPattern(i18nMessage, fallback);
try {
return parseFormat(pattern, args);
} catch (IllegalArgumentException e) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/neoforge/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,16 @@
"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.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.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.",
"fml.modloading.cycle": "Detected a mod dependency cycle: {0}",
Expand Down

0 comments on commit 8786a13

Please sign in to comment.