Tidy up mod loading a bit more, and also crash if the [[mods]] list isn't

a list.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-06-22 12:52:22 -04:00
parent 1e0437208b
commit 389bc1ecea
No known key found for this signature in database
GPG Key ID: 8EB3DF749553B1B7
2 changed files with 10 additions and 14 deletions

View File

@ -55,6 +55,9 @@ public class ModFileInfo implements IModFileInfo
this.properties = config.<UnmodifiableConfig>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<UnmodifiableConfig> modConfigs = config.getOrElse("mods", ArrayList::new);
if (modConfigs.isEmpty()) {
throw new InvalidModFileException("Missing mods list", this);

View File

@ -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<Void> 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();
}