Skip to content

Commit

Permalink
Rebased on main
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Apr 20, 2024
1 parent 0d111fa commit d948210
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions loader/src/main/java/net/neoforged/fml/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,15 @@ private ModLoader() {}

private static final Logger LOGGER = LogManager.getLogger();

private final List<ModLoadingIssue> loadingIssues;
private boolean loadingStateValid;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private final Optional<Consumer<String>> statusConsumer = StartupNotificationManager.modLoaderConsumer();
private ModList modList;

private ModLoader() {
INSTANCE = this;
this.loadingModList = FMLLoader.getLoadingModList();
this.loadingIssues = FMLLoader.getLoadingModList().getModLoadingIssues();
private static final List<ModLoadingIssue> loadingIssues = new ArrayList<>();
private static boolean loadingStateValid;
private static ModList modList;

static {
CrashReportCallables.registerCrashCallable("ModLauncher", FMLLoader::getLauncherInfo);
CrashReportCallables.registerCrashCallable("ModLauncher launch target", FMLLoader::launcherHandlerName);
CrashReportCallables.registerCrashCallable("ModLauncher services", this::computeModLauncherServiceList);
CrashReportCallables.registerCrashCallable("FML Language Providers", this::computeLanguageList);
CrashReportCallables.registerCrashCallable("ModLauncher services", ModLoader::computeModLauncherServiceList);
CrashReportCallables.registerCrashCallable("FML Language Providers", ModLoader::computeLanguageList);
}

private static String computeLanguageList() {
Expand All @@ -97,8 +91,9 @@ private static String computeModLauncherServiceList() {
* @param periodicTask Optional periodic task to perform on the main thread while other activities run
*/
public static void gatherAndInitializeMods(final Executor syncExecutor, final Executor parallelExecutor, final Runnable periodicTask) {
LoadingModList loadingModList = FMLLoader.getLoadingModList();
collectLoadingErrors(loadingModList);
var loadingModList = FMLLoader.getLoadingModList();
loadingIssues.clear();
loadingIssues.addAll(loadingModList.getModLoadingIssues());

ForgeFeature.registerFeature("javaVersion", ForgeFeature.VersionFeatureTest.forVersionString(IModInfo.DependencySide.BOTH, System.getProperty("java.version")));
ForgeFeature.registerFeature("openGLVersion", ForgeFeature.VersionFeatureTest.forVersionString(IModInfo.DependencySide.CLIENT, ImmediateWindowHandler.getGLVersion()));
Expand All @@ -113,7 +108,7 @@ public static void gatherAndInitializeMods(final Executor syncExecutor, final Ex
LOGGER.fatal(CORE, "Error during pre-loading phase: {}", loadingError, loadingError.cause());
}
cancelLoading(modList);
throw new ModLoadingException(this.loadingIssues);
throw new ModLoadingException(loadingIssues);
}
List<? extends ForgeFeature.Bound> failedBounds = loadingModList.getMods().stream()
.map(ModInfo::getForgeFeatures)
Expand Down Expand Up @@ -142,22 +137,22 @@ public static void gatherAndInitializeMods(final Executor syncExecutor, final Ex
throw new ModLoadingException(loadingIssues);
}
modList.setLoadedMods(modContainers);
this.modList = modList;
ModLoader.modList = modList;

constructMods(syncExecutor, parallelExecutor, periodicTask);
}

private List<ModLoadingIssue> getLoadingErrors() {
return this.loadingIssues.stream().filter(issue -> issue.severity() == ModLoadingIssue.Severity.ERROR).toList();
private static List<ModLoadingIssue> getLoadingErrors() {
return loadingIssues.stream().filter(issue -> issue.severity() == ModLoadingIssue.Severity.ERROR).toList();
}

private void cancelLoading(ModList modList) {
statusConsumer.ifPresent(c -> c.accept("ERROR DURING MOD LOADING"));
private static void cancelLoading(ModList modList) {
StartupNotificationManager.modLoaderMessage("ERROR DURING MOD LOADING");
modList.setLoadedMods(Collections.emptyList());
loadingStateValid = false;
}

private boolean hasErrors() {
private static boolean hasErrors() {
return loadingIssues.stream().anyMatch(issue -> issue.severity() == ModLoadingIssue.Severity.ERROR);
}

Expand Down

0 comments on commit d948210

Please sign in to comment.