Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions loader/src/main/java/net/neoforged/fml/loading/ModSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.neoforged.fml.ModLoadingException;
import net.neoforged.fml.ModLoadingIssue;
import net.neoforged.fml.loading.moddiscovery.ModFile;
import net.neoforged.fml.loading.moddiscovery.ModFileInfo;
import net.neoforged.fml.loading.moddiscovery.ModInfo;
import net.neoforged.fml.loading.toposort.CyclePresentException;
import net.neoforged.fml.loading.toposort.TopologicalSort;
Expand Down Expand Up @@ -99,7 +98,7 @@ public static LoadingModList sort(List<ModFile> plugins, List<ModFile> gameLibra
if (modLoadingException == null) {
list = LoadingModList.of(plugins, gameLibraries, ms.modFiles, ms.sortedList, issues, ms.modDependencies);
} else {
list = LoadingModList.of(plugins, gameLibraries, ms.modFiles, ms.sortedList, concat(issues, modLoadingException.getIssues()), Map.of());
list = LoadingModList.of(plugins, gameLibraries, ms.systemMods, ms.systemMods.stream().map(mf -> (ModInfo) mf.getModInfos().getFirst()).collect(toList()), concat(issues, modLoadingException.getIssues()), Map.of());
}
}

Expand Down Expand Up @@ -171,14 +170,15 @@ private void sort(List<ModLoadingIssue> issues) {
try {
sorted = TopologicalSort.topologicalSort(graph, Comparator.comparing(infos::get));
} catch (CyclePresentException e) {
Set<Set<ModFileInfo>> cycles = e.getCycles();
Set<Set<ModInfo>> cycles = e.getCycles();
if (LOGGER.isErrorEnabled(LogMarkers.LOADING)) {
LOGGER.error(LogMarkers.LOADING, "Mod Sorting failed.\nDetected Cycles: {}\n", cycles);
}
var dataList = cycles.stream()
.<ModFileInfo>mapMulti(Iterable::forEach)
.<IModInfo>mapMulti((mf, c) -> mf.getMods().forEach(c))
.map(IModInfo::getModId)
.map(cycle -> cycle.stream()
.map(IModInfo::getModId)
.sorted()
.collect(Collectors.joining(", ")))
.map(list -> ModLoadingIssue.error("fml.modloadingissue.cycle", list).withCause(e))
.toList();
throw new ModLoadingException(dataList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ private ForgeFeature.Bound makeBound(Map.Entry<String, Object> e) {
}
}

@Override
public String toString() {
return modId + " (" + displayName + ") @ " + version;
}

class ModVersion implements net.neoforged.neoforgespi.language.IModInfo.ModVersion {
private IModInfo owner;
private final String modId;
Expand Down
29 changes: 29 additions & 0 deletions loader/src/test/java/net/neoforged/fml/loading/FMLLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,35 @@ void testMissingRequiredDependency() throws Exception {
assertThat(getTranslatedIssues(e.getIssues())).containsOnly("ERROR: Mod testmod requires requiredmod any\nCurrently, requiredmod is not installed\n");
}

@Test
void testDependencyCycle() throws Exception {
installation.setupProductionClient();
installation.buildModJar("mod_one.jar")
.withModsToml(builder -> {
builder.unlicensedJavaMod();
builder.addMod("mod_one", "1.0");
builder.addDependency("mod_one", "mod_two", "[1.0,)", dep -> dep.set("ordering", "BEFORE"));
})
.build();
installation.buildModJar("mod_two.jar")
.withModsToml(builder -> {
builder.unlicensedJavaMod();
builder.addMod("mod_two", "1.0");
builder.addDependency("mod_two", "mod_three", "[1.0,)", dep -> dep.set("ordering", "BEFORE"));
})
.build();
installation.buildModJar("mod_three.jar")
.withModsToml(builder -> {
builder.unlicensedJavaMod();
builder.addMod("mod_three", "1.0");
builder.addDependency("mod_three", "mod_one", "[1.0,)", dep -> dep.set("ordering", "BEFORE"));
})
.build();

var e = assertThrows(ModLoadingException.class, () -> launchInstalledDist());
assertThat(getTranslatedIssues(e.getIssues())).containsOnly("ERROR: Detected a mod dependency cycle: mod_one, mod_three, mod_two");
}

@Test
void testDependencyOverride() throws Exception {
installation.setupProductionClient();
Expand Down
Loading