Package net.minecraftforge.fml
Class ModLoader
- java.lang.Object
-
- net.minecraftforge.fml.ModLoader
-
public class ModLoader extends java.lang.Object
Loads mods. Dispatch cycle is seen in#loadMods()
and#finishMods()
Overall sequence for loadMods is:- CONSTRUCT
- Constructs the mod instance. Mods can typically setup basic environment such as Event listeners and Configuration specifications here.
- Automated dispatches
- Dispatches automated elements :
Mod.EventBusSubscriber
,RegistryEvent
,CapabilityInject
and others - CONFIG_LOAD
- Dispatches ConfigLoadEvent to mods
- COMMON_SETUP
- Dispatches
FMLCommonSetupEvent
to mods - SIDED_SETUP
- Dispatches
FMLClientSetupEvent
orFMLDedicatedServerSetupEvent
to mods
- ENQUEUE_IMC
- Dispatches
InterModEnqueueEvent
to mods, for enqueuingInterModComms
messages for other mods to receive subsequently - PROCESS_IMC
- Dispatches
InterModProcessEvent
to mods, for processingInterModComms
messages received from other mods prior to this event - COMPLETE
- Dispatches
FMLLoadCompleteEvent
to mods, and completes the mod loading sequence.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ModLoader.ErroredModContainer
-
Field Summary
Fields Modifier and Type Field Description private static ModLoader
INSTANCE
private cpw.mods.modlauncher.TransformingClassLoader
launchClassLoader
private java.util.List<ModLoadingException>
loadingExceptions
private LoadingModList
loadingModList
private boolean
loadingStateValid
private java.util.List<ModLoadingWarning>
loadingWarnings
private static org.apache.logging.log4j.Logger
LOGGER
private static boolean
runningDataGen
private java.util.Optional<java.util.function.Consumer<java.lang.String>>
statusConsumer
-
Constructor Summary
Constructors Modifier Constructor Description private
ModLoader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWarning(ModLoadingWarning warning)
private ModContainer
buildModContainerFromTOML(ModFile modFile, cpw.mods.modlauncher.TransformingClassLoader modClassLoader, java.util.Map<java.lang.String,net.minecraftforge.forgespi.language.IModInfo> modInfoMap, java.util.Map.Entry<java.lang.String,? extends net.minecraftforge.forgespi.language.IModLanguageProvider.IModLanguageLoader> idToProviderEntry)
private java.util.List<ModContainer>
buildMods(ModFile modFile, cpw.mods.modlauncher.TransformingClassLoader modClassLoader)
private java.lang.String
computeLanguageList()
private java.lang.String
computeModLauncherServiceList()
private void
dispatchAndHandleError(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable ticker)
private void
dispatchAndHandleError(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable ticker, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> preSyncTask, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> postSyncTask)
void
finishMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable periodicTask)
void
gatherAndInitializeMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable periodicTask)
Run on the primary starting thread by ClientModLoader and ServerModLoaderstatic ModLoader
get()
java.util.List<ModLoadingWarning>
getWarnings()
static boolean
isDataGenRunning()
static boolean
isLoadingStateValid()
void
loadMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> beforeSidedEvent, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> afterSidedEvent, java.lang.Runnable periodicTask)
<T extends net.minecraftforge.eventbus.api.Event & IModBusEvent>
voidpostEvent(T e)
<T extends net.minecraftforge.eventbus.api.Event & IModBusEvent>
voidrunEventGenerator(java.util.function.Function<ModContainer,T> generator)
private void
waitForTransition(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.lang.Runnable ticker, java.util.concurrent.CompletableFuture<java.util.List<java.lang.Throwable>> transition)
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
INSTANCE
private static ModLoader INSTANCE
-
launchClassLoader
private final cpw.mods.modlauncher.TransformingClassLoader launchClassLoader
-
loadingModList
private final LoadingModList loadingModList
-
loadingExceptions
private final java.util.List<ModLoadingException> loadingExceptions
-
loadingWarnings
private final java.util.List<ModLoadingWarning> loadingWarnings
-
loadingStateValid
private boolean loadingStateValid
-
statusConsumer
private final java.util.Optional<java.util.function.Consumer<java.lang.String>> statusConsumer
-
runningDataGen
private static boolean runningDataGen
-
-
Method Detail
-
computeLanguageList
private java.lang.String computeLanguageList()
-
computeModLauncherServiceList
private java.lang.String computeModLauncherServiceList()
-
get
public static ModLoader get()
-
gatherAndInitializeMods
public void gatherAndInitializeMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable periodicTask)
Run on the primary starting thread by ClientModLoader and ServerModLoader- Parameters:
syncExecutor
- An executor to run tasks on the main threadparallelExecutor
- An executor to run tasks on a parallel loading thread poolperiodicTask
- Optional periodic task to perform on the main thread while other activities run
-
loadMods
public void loadMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> beforeSidedEvent, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> afterSidedEvent, java.lang.Runnable periodicTask)
-
finishMods
public void finishMods(ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable periodicTask)
-
dispatchAndHandleError
private void dispatchAndHandleError(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable ticker)
-
dispatchAndHandleError
private void dispatchAndHandleError(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.util.concurrent.Executor parallelExecutor, java.lang.Runnable ticker, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> preSyncTask, java.util.function.Function<java.util.concurrent.Executor,java.util.concurrent.CompletableFuture<java.lang.Void>> postSyncTask)
-
waitForTransition
private void waitForTransition(ModLoadingStage state, ModWorkManager.DrivenExecutor syncExecutor, java.lang.Runnable ticker, java.util.concurrent.CompletableFuture<java.util.List<java.lang.Throwable>> transition)
-
buildMods
private java.util.List<ModContainer> buildMods(ModFile modFile, cpw.mods.modlauncher.TransformingClassLoader modClassLoader)
-
buildModContainerFromTOML
private ModContainer buildModContainerFromTOML(ModFile modFile, cpw.mods.modlauncher.TransformingClassLoader modClassLoader, java.util.Map<java.lang.String,net.minecraftforge.forgespi.language.IModInfo> modInfoMap, java.util.Map.Entry<java.lang.String,? extends net.minecraftforge.forgespi.language.IModLanguageProvider.IModLanguageLoader> idToProviderEntry)
-
isLoadingStateValid
public static boolean isLoadingStateValid()
- Returns:
- If the current mod loading state is valid. Use if you interact with vanilla systems directly during loading and don't want to cause extraneous crashes due to trying to do things that aren't possible in a "broken load"
-
runEventGenerator
public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> void runEventGenerator(java.util.function.Function<ModContainer,T> generator)
-
postEvent
public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> void postEvent(T e)
-
getWarnings
public java.util.List<ModLoadingWarning> getWarnings()
-
addWarning
public void addWarning(ModLoadingWarning warning)
-
isDataGenRunning
public static boolean isDataGenRunning()
-
-