Skip to content

Commit

Permalink
Only crash for mandatory fields used by dev mods (#60)
Browse files Browse the repository at this point in the history
Dev mods -- mods which are being developed in the current development 
environment -- are located and provided by `MinecraftLocator`.

This allows mod dependencies in the dev environment to use the 
deprecated `mandatory` field (if they haven't been updated yet by
their respective authors) while still forcing the mod developer to
replace their own use of the field in their dev mods.
  • Loading branch information
Matyrobbrt authored Dec 23, 2023
1 parent 429fe42 commit 29b9b43
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ public ModVersion(final IModInfo owner, final IConfigurable config) {
this.modId = config.<String>getConfigElement("modId")
.orElseThrow(()->new InvalidModFileException("Missing required field modid in dependency", getOwningFile()));
this.type = config.<String>getConfigElement("type")
// TODO - 1.21: remove the fallback to the mandatory field
.map(str -> str.toUpperCase(Locale.ROOT)).map(DependencyType::valueOf).orElseGet(() -> {
final var mandatory = config.<Boolean>getConfigElement("mandatory");
if (mandatory.isPresent()) {
if (!FMLLoader.isProduction()) {
LOGGER.error("Mod '{}' uses deprecated 'mandatory' field in the dependency declaration for '{}'. Use the 'type' field and 'required'/'optional' instead", owner.getModId(), modId);
throw new InvalidModFileException("Deprecated 'mandatory' field is used in dependency", getOwningFile());
// only error the mod being "developed" (i.e. found through the MOD_CLASSES) to prevent dependencies from causing the crash
if (owner.getOwningFile().getFile().getProvider() instanceof MinecraftLocator) {
throw new InvalidModFileException("Deprecated 'mandatory' field is used in dependency", getOwningFile());
}
}

return mandatory.get() ? DependencyType.REQUIRED : DependencyType.OPTIONAL;
Expand Down

0 comments on commit 29b9b43

Please sign in to comment.