Skip to content

Commit

Permalink
Add alphabetical sorted ModList to start of latest.log file (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
TelepathicGrunt authored Aug 10, 2024
1 parent 2d3fba1 commit a2d3df6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion loader/src/main/java/net/neoforged/fml/ModList.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private String fileToLine(IModFile mf) {
}

private String crashReport() {
return "\n" + applyForEachModFile(this::fileToLine).collect(Collectors.joining("\n\t\t", "\t\t", ""));
return "\n" + applyForEachModFileAlphabetical(this::fileToLine).collect(Collectors.joining("\n\t\t", "\t\t", ""));
}

public static ModList of(List<ModFile> modFiles, List<ModInfo> sortedList) {
Expand Down Expand Up @@ -152,6 +152,16 @@ public <T> Stream<T> applyForEachModFile(Function<IModFile, T> function) {
return modFiles.stream().map(IModFileInfo::getFile).map(function);
}

/**
* Stream sorted by Mod Name in alphabetical order
*/
public <T> Stream<T> applyForEachModFileAlphabetical(Function<IModFile, T> function) {
return modFiles.stream()
.map(IModFileInfo::getFile)
.sorted(Comparator.comparing(modFile -> modFile.getModInfos().getFirst().getDisplayName(), String.CASE_INSENSITIVE_ORDER))
.map(function);
}

public void forEachModContainer(BiConsumer<String, ModContainer> modContainerConsumer) {
indexedMods.forEach(modContainerConsumer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -129,13 +130,33 @@ public ModValidator discoverMods() {
LOGGER.error(LogMarkers.SCAN, "Mod Discovery failed. Skipping dependency discovery.");
}

LOGGER.info("\n Mod List:\n\t\tName Version (Mod Id)\n\n{}", logReport(modFilesMap.values()));

//Validate the loading. With a deduplicated list, we can now successfully process the artifacts and load
//transformer plugins.
var validator = new ModValidator(modFilesMap, discoveryIssues);
validator.stage1Validation();
return validator;
}

private String logReport(Collection<List<ModFile>> modFiles) {
return modFiles.stream()
.flatMap(Collection::stream)
.filter(modFile -> !modFile.getModInfos().isEmpty())
.sorted(Comparator.comparing(modFile -> modFile.getModInfos().getFirst().getDisplayName(), String.CASE_INSENSITIVE_ORDER))
.map(this::fileToLine)
.collect(Collectors.joining("\n\t\t", "\t\t", ""));
}

private String fileToLine(IModFile mf) {
var mainMod = mf.getModInfos().getFirst();

return String.format(Locale.ENGLISH, "%s %s (%s)",
mainMod.getDisplayName(),
mainMod.getVersion(),
mainMod.getModId());
}

private class DiscoveryPipeline implements IDiscoveryPipeline {
private final ModFileDiscoveryAttributes defaultAttributes;
private final List<ModFile> loadedFiles;
Expand Down

0 comments on commit a2d3df6

Please sign in to comment.