From 389bc1eceae7c5bbf9798ec628b993b16265464a Mon Sep 17 00:00:00 2001 From: cpw Date: Sat, 22 Jun 2019 12:52:22 -0400 Subject: [PATCH] Tidy up mod loading a bit more, and also crash if the [[mods]] list isn't a list. Signed-off-by: cpw --- .../fml/loading/moddiscovery/ModFileInfo.java | 3 +++ .../fml/client/ClientModLoader.java | 21 +++++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java index 2efe965f5a..247cda8bf9 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java @@ -55,6 +55,9 @@ public class ModFileInfo implements IModFileInfo this.properties = config.getOptional("properties"). map(UnmodifiableConfig::valueMap).orElse(Collections.emptyMap()); this.modFile.setFileProperties(this.properties); + if (config.contains("mods") && !(config.get("mods") instanceof Collection)) { + throw new InvalidModFileException("Mods list is not a list.", this); + } final ArrayList modConfigs = config.getOrElse("mods", ArrayList::new); if (modConfigs.isEmpty()) { throw new InvalidModFileException("Missing mods list", this); diff --git a/src/main/java/net/minecraftforge/fml/client/ClientModLoader.java b/src/main/java/net/minecraftforge/fml/client/ClientModLoader.java index c34bb8c602..ed30501d33 100644 --- a/src/main/java/net/minecraftforge/fml/client/ClientModLoader.java +++ b/src/main/java/net/minecraftforge/fml/client/ClientModLoader.java @@ -58,18 +58,16 @@ public class ClientModLoader ClientModLoader.mc = minecraft; SidedProvider.setClient(()->minecraft); LogicalSidedProvider.setClient(()->minecraft); - try { - ModLoader.get().gatherAndInitializeMods(); - } catch (LoadingFailedException e) { - error = e; - } + runTaskWithCatch(ModLoader.get()::gatherAndInitializeMods); ResourcePackLoader.loadResourcePacks(defaultResourcePacks); mcResourceManager.addReloadListener(ClientModLoader::onreload); mcResourceManager.addReloadListener(BrandingControl.resourceManagerReloadListener()); } private static CompletableFuture onreload(final IFutureReloadListener.IStage stage, final IResourceManager resourceManager, final IProfiler prepareProfiler, final IProfiler executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) { - return CompletableFuture.runAsync(runTaskWithCatch(ModLoader.get()::loadMods), syncExecutor).thenCompose(stage::markCompleteAwaitingOthers).thenRunAsync(runTaskWithCatch(ModLoader.get()::finishMods)); + return CompletableFuture.runAsync(runTaskWithCatch(ModLoader.get()::loadMods), syncExecutor). + thenCompose(stage::markCompleteAwaitingOthers). + thenRunAsync(runTaskWithCatch(ClientModLoader::end)); } private static Runnable runTaskWithCatch(Runnable r) { @@ -78,19 +76,14 @@ public class ClientModLoader r.run(); } catch (LoadingFailedException e) { MinecraftForge.EVENT_BUS.shutdown(); - error = e; + if (error == null) error = e; } }; } + public static void end() { - try { - ModLoader.get().finishMods(); - } catch (LoadingFailedException e) { - MinecraftForge.EVENT_BUS.shutdown(); - if (error == null) error = e; - TEMP_printLoadingExceptions(e); - } + runTaskWithCatch(ModLoader.get()::finishMods); loading = false; mc.gameSettings.loadOptions(); }