Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only crash if mods found by the MC locator (i.e. dev mods) are using the mandatory field #60

Merged
merged 5 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading