mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 10:34:49 +00:00
Basic error display GUI.
This commit is contained in:
1 parent
dec65732ce
commit
bb9eca96a8
26 files changed
+451
-83
No files matched your search
@@ -25,6 +25,8 @@ import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.fml.language.IModInfo;
|
||||
import net.minecraftforge.fml.loading.DefaultModInfos;
|
||||
import net.minecraftforge.fml.loading.EarlyLoadingException;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.LoadingModList;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
@@ -34,11 +36,10 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -53,12 +54,15 @@ public class ModLoader
|
||||
private final LoadingModList loadingModList;
|
||||
private final ModLoadingClassLoader modClassLoader;
|
||||
|
||||
private final List<ModLoadingException> loadingExceptions;
|
||||
private ModLoader()
|
||||
{
|
||||
INSTANCE = this;
|
||||
this.launchClassLoader = FMLLoader.getLaunchClassLoader();
|
||||
this.loadingModList = FMLLoader.getLoadingModList();
|
||||
this.modClassLoader = new ModLoadingClassLoader(this.launchClassLoader);
|
||||
this.loadingExceptions = FMLLoader.getLoadingModList().
|
||||
getErrors().stream().map(ModLoadingException::fromEarlyException).collect(Collectors.toList());
|
||||
Thread.currentThread().setContextClassLoader(this.modClassLoader);
|
||||
}
|
||||
|
||||
@@ -67,14 +71,17 @@ public class ModLoader
|
||||
return INSTANCE == null ? INSTANCE = new ModLoader() : INSTANCE;
|
||||
}
|
||||
|
||||
private static Callable<Boolean> fireClientEvents()
|
||||
private static Runnable fireClientEvents()
|
||||
{
|
||||
return ()->MinecraftForge.EVENT_BUS.post(new ModelRegistryEvent());
|
||||
}
|
||||
|
||||
public void loadMods() {
|
||||
if (!this.loadingExceptions.isEmpty()) {
|
||||
throw new LoadingFailedException(loadingExceptions);
|
||||
}
|
||||
final ModList modList = ModList.of(loadingModList.getModFiles().stream().map(ModFileInfo::getFile).collect(Collectors.toList()), loadingModList.getMods());
|
||||
final ModContainer forgeModContainer;
|
||||
ModContainer forgeModContainer;
|
||||
try
|
||||
{
|
||||
forgeModContainer = (ModContainer)Class.forName("net.minecraftforge.common.ForgeModContainer", true, modClassLoader).
|
||||
@@ -83,21 +90,41 @@ public class ModLoader
|
||||
catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InstantiationException | InvocationTargetException e)
|
||||
{
|
||||
LOGGER.error(CORE,"Unable to load the Forge Mod Container", e);
|
||||
throw new RuntimeException(e);
|
||||
loadingExceptions.add(new ModLoadingException(DefaultModInfos.forgeModInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadforge", e));
|
||||
forgeModContainer = null;
|
||||
}
|
||||
final Stream<ModContainer> modContainerStream = loadingModList.getModFiles().stream().
|
||||
map(ModFileInfo::getFile).
|
||||
map(mf -> buildMods(mf, modClassLoader)).
|
||||
flatMap(Collection::stream);
|
||||
if (!loadingExceptions.isEmpty()) {
|
||||
LOGGER.error(CORE, "Failed to initialize mod containers");
|
||||
throw new LoadingFailedException(loadingExceptions);
|
||||
}
|
||||
modList.setLoadedMods(Streams.concat(Stream.of(forgeModContainer), modContainerStream).collect(Collectors.toList()));
|
||||
LifecycleEventProvider.CONSTRUCT.dispatch();
|
||||
dispatchAndHandleError(LifecycleEventProvider.CONSTRUCT);
|
||||
WorldPersistenceHooks.addHook(new FMLWorldPersistenceHook());
|
||||
WorldPersistenceHooks.addHook((WorldPersistenceHooks.WorldPersistenceHook)forgeModContainer.getMod());
|
||||
GameData.fireCreateRegistryEvents();
|
||||
CapabilityManager.INSTANCE.injectCapabilities(modList.getAllScanData());
|
||||
LifecycleEventProvider.PREINIT.dispatch();
|
||||
Boolean result = DistExecutor.callWhenOn(Dist.CLIENT, ModLoader::fireClientEvents);
|
||||
LifecycleEventProvider.SIDEDINIT.dispatch();
|
||||
dispatchAndHandleError(LifecycleEventProvider.PREINIT);
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, ModLoader::fireClientEvents);
|
||||
dispatchAndHandleError(LifecycleEventProvider.SIDEDINIT);
|
||||
}
|
||||
|
||||
private void dispatchAndHandleError(LifecycleEventProvider event) {
|
||||
if (!loadingExceptions.isEmpty()) {
|
||||
LOGGER.error("Skipping lifecycle event {}, {} errors found.", event, loadingExceptions.size());
|
||||
} else {
|
||||
event.dispatch(this::accumulateErrors);
|
||||
}
|
||||
if (!loadingExceptions.isEmpty()) {
|
||||
LOGGER.error("Failed to complete lifecycle event {}, {} errors found", event, loadingExceptions.size());
|
||||
throw new LoadingFailedException(loadingExceptions);
|
||||
}
|
||||
}
|
||||
private void accumulateErrors(List<ModLoadingException> errors) {
|
||||
loadingExceptions.addAll(errors);
|
||||
}
|
||||
|
||||
private List<ModContainer> buildMods(final ModFile modFile, final ModLoadingClassLoader modClassLoader)
|
||||
@@ -105,16 +132,22 @@ public class ModLoader
|
||||
final Map<String, IModInfo> modInfoMap = modFile.getModFileInfo().getMods().stream().collect(Collectors.toMap(IModInfo::getModId, Function.identity()));
|
||||
|
||||
return modFile.getScanResult().getTargets().entrySet().stream().
|
||||
map(e->e.getValue().<ModContainer>loadMod(modInfoMap.get(e.getKey()), modClassLoader, modFile.getScanResult())).
|
||||
collect(Collectors.toList());
|
||||
map(e-> {
|
||||
try {
|
||||
return e.getValue().<ModContainer>loadMod(modInfoMap.get(e.getKey()), modClassLoader, modFile.getScanResult());
|
||||
} catch (ModLoadingException mle) {
|
||||
loadingExceptions.add(mle);
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public void finishMods()
|
||||
{
|
||||
LifecycleEventProvider.INIT.dispatch();
|
||||
LifecycleEventProvider.POSTINIT.dispatch();
|
||||
LifecycleEventProvider.COMPLETE.dispatch();
|
||||
dispatchAndHandleError(LifecycleEventProvider.INIT);
|
||||
dispatchAndHandleError(LifecycleEventProvider.POSTINIT);
|
||||
dispatchAndHandleError(LifecycleEventProvider.COMPLETE);
|
||||
GameData.freezeData();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user