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

Make mixin entries from the mods.toml optional. #237

Merged
merged 7 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion loader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'net.neoforged.jarcompatibilitychecker' version '0.1.3'
id 'net.neoforged.jarcompatibilitychecker' version '0.1.13'
}

checkJarCompatibility {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public void addMixinConfigs() {
.map(ModFileInfo::getFile)
.forEach(file -> {
final String modId = file.getModInfos().get(0).getModId();
file.getMixinConfigs().forEach(cfg -> DeferredMixinConfigRegistration.addMixinConfig(cfg, modId));
file.getMixinConfigs()
.stream()
.filter(potential -> potential.requiredModIds().isEmpty() ||
marchermans marked this conversation as resolved.
Show resolved Hide resolved
potential.requiredModIds().stream().allMatch(
id -> this.getModFileById(id) != null
))
.forEach(cfg -> DeferredMixinConfigRegistration.addMixinConfig(cfg.name(), modId));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ModFile implements IModFile {
private ModFileScanData fileModFileScanData;
private volatile CompletableFuture<ModFileScanData> futureScanResult;
private List<CoreModFile> coreMods;
private List<String> mixinConfigs;
private List<ModFileParser.PotentialMixinConfig> mixinConfigs;
private List<Path> accessTransformers;

public static final Attributes.Name TYPE = new Attributes.Name("FMLModType");
Expand Down Expand Up @@ -135,7 +135,7 @@ public List<CoreModFile> getCoreMods() {
return coreMods;
}

public List<String> getMixinConfigs() {
public List<ModFileParser.PotentialMixinConfig> getMixinConfigs() {
return mixinConfigs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.neoforged.fml.loading.LogMarkers;
import net.neoforged.fml.loading.moddiscovery.readers.JarModsDotTomlModFileReader;
import net.neoforged.neoforgespi.language.IConfigurable;
import net.neoforged.neoforgespi.language.IModFileInfo;
import net.neoforged.neoforgespi.locating.IModFile;
import net.neoforged.neoforgespi.locating.InvalidModFileException;
Expand Down Expand Up @@ -85,17 +87,28 @@ protected static List<CoreModFile> getCoreMods(final ModFile modFile) {
.toList();
}

protected static List<String> getMixinConfigs(IModFileInfo modFileInfo) {
/**
* Represents a potential mixin configuration.
*
* @param name The name of the mixin configuration.
* @param requiredModIds The mod ids that are required for this mixin configuration to be loaded. If empty, will be loaded regardless.
*/
public record PotentialMixinConfig(String name, List<String> requiredModIds) {}
marchermans marked this conversation as resolved.
Show resolved Hide resolved
marchermans marked this conversation as resolved.
Show resolved Hide resolved
marchermans marked this conversation as resolved.
Show resolved Hide resolved

protected static List<PotentialMixinConfig> getMixinConfigs(IModFileInfo modFileInfo) {
try {
var config = modFileInfo.getConfig();
var mixinsEntries = config.getConfigList("mixins");
return mixinsEntries
.stream()
.map(entry -> entry
.<String>getConfigElement("config")
.orElseThrow(
() -> new InvalidModFileException("Missing \"config\" in [[mixins]] entry", modFileInfo)))
.toList();

var potentialMixins = new ArrayList<PotentialMixinConfig>();
for (IConfigurable mixinsEntry : mixinsEntries) {
var name = mixinsEntry.<String>getConfigElement("config")
.orElseThrow(() -> new InvalidModFileException("Missing \"config\" in [[mixins]] entry", modFileInfo));
var requiredModIds = mixinsEntry.<List<String>>getConfigElement("requiredMods").orElse(List.of());
potentialMixins.add(new PotentialMixinConfig(name, requiredModIds));
}

return potentialMixins;
} catch (Exception exception) {
LOGGER.error("Failed to load mixin configs from mod file", exception);
return List.of();
Expand Down
Loading