Package net.neoforged.fml
Class ModLoader
java.lang.Object
net.neoforged.fml.ModLoader
Contains the logic to load mods, i.e. turn the
LoadingModList
into the ModList
,
as well as initialization tasks for mods and methods to dispatch mod bus events.
For the mod initialization flow, see CommonModLoader
in NeoForge.
For mod bus event dispatch, see postEvent(Event)
and related methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Exception that is fired when a mod loading future cannot be executed because a dependent future failed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List
<ModLoadingIssue> private static final org.apache.logging.log4j.Logger
private static ModList
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addLoadingIssue
(ModLoadingIssue issue) private static void
addLoadingIssuesFromException
(String context, Throwable error) private static ModContainer
buildModContainerFromTOML
(IModInfo modInfo, ModFileScanData scanData) private static List
<ModContainer> private static void
cancelLoading
(ModList modList) static void
private static String
private static String
private static void
constructMods
(Executor syncExecutor, Executor parallelExecutor, Runnable periodicTask) static void
dispatchParallelEvent
(String name, Executor syncExecutor, Executor parallelExecutor, Runnable periodicTask, BiFunction<ModContainer, DeferredWorkQueue, ParallelDispatchEvent> eventConstructor) Dispatches a parallel event across all mod containers, with progress displayed on the loading screen.static void
dispatchParallelTask
(String name, Executor parallelExecutor, Runnable periodicTask, Consumer<ModContainer> task) Dispatches a task across all mod containers in parallel, with progress displayed on the loading screen.static void
gatherAndInitializeMods
(Executor syncExecutor, Executor parallelExecutor, Runnable periodicTask) Run on the primary starting thread by ClientModLoader and ServerModLoaderstatic List
<ModLoadingIssue> static List
<ModLoadingIssue> static List
<ModLoadingIssue> static boolean
private static boolean
isMeaningfulException
(Throwable error) static <T extends net.neoforged.bus.api.Event & IModBusEvent>
voidpostEvent
(T e) static <T extends net.neoforged.bus.api.Event & IModBusEvent>
TpostEventWithReturn
(T e) static <T extends net.neoforged.bus.api.Event & IModBusEvent>
voidpostEventWithWrapInModOrder
(T e, BiConsumer<ModContainer, T> pre, BiConsumer<ModContainer, T> post) static <T extends net.neoforged.bus.api.Event & IModBusEvent>
voidpostEventWrapContainerInModOrder
(T event) static <T extends net.neoforged.bus.api.Event & IModBusEvent>
voidrunEventGenerator
(Function<ModContainer, T> generator) static void
runInitTask
(String name, Executor syncExecutor, Runnable periodicTask, Runnable initTask) Runs a single task on thesyncExecutor
, while ticking the loading screen.private static void
waitForFuture
(String name, Runnable periodicTask, CompletableFuture<?> future) static void
waitForTask
(String name, Runnable periodicTask, CompletableFuture<?> future) Waits for a task to complete, displaying the name of the task on the loading screen.
-
Field Details
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
loadingIssues
-
modList
-
-
Constructor Details
-
ModLoader
private ModLoader()
-
-
Method Details
-
computeLanguageList
-
computeModLauncherServiceList
-
gatherAndInitializeMods
public static void gatherAndInitializeMods(Executor syncExecutor, Executor parallelExecutor, 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
-
cancelLoading
-
constructMods
-
runInitTask
public static void runInitTask(String name, Executor syncExecutor, Runnable periodicTask, Runnable initTask) Runs a single task on thesyncExecutor
, while ticking the loading screen. -
dispatchParallelEvent
public static void dispatchParallelEvent(String name, Executor syncExecutor, Executor parallelExecutor, Runnable periodicTask, BiFunction<ModContainer, DeferredWorkQueue, ParallelDispatchEvent> eventConstructor) Dispatches a parallel event across all mod containers, with progress displayed on the loading screen. -
waitForTask
Waits for a task to complete, displaying the name of the task on the loading screen. -
dispatchParallelTask
public static void dispatchParallelTask(String name, Executor parallelExecutor, Runnable periodicTask, Consumer<ModContainer> task) Dispatches a task across all mod containers in parallel, with progress displayed on the loading screen. -
waitForFuture
-
isMeaningfulException
-
addLoadingIssuesFromException
-
buildMods
-
buildModContainerFromTOML
-
runEventGenerator
public static <T extends net.neoforged.bus.api.Event & IModBusEvent> void runEventGenerator(Function<ModContainer, T> generator) -
postEvent
-
postEventWithReturn
-
postEventWrapContainerInModOrder
public static <T extends net.neoforged.bus.api.Event & IModBusEvent> void postEventWrapContainerInModOrder(T event) -
postEventWithWrapInModOrder
public static <T extends net.neoforged.bus.api.Event & IModBusEvent> void postEventWithWrapInModOrder(T e, BiConsumer<ModContainer, T> pre, BiConsumer<ModContainer, T> post) -
hasErrors
public static boolean hasErrors()- Returns:
- If the errors occurred during mod loading. 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.
If you are running in a Mixin before mod loading has actually started, check
LoadingModList.hasErrors()
instead.
-
getLoadingErrors
-
getLoadingWarnings
-
getLoadingIssues
-
clearLoadingIssues
@VisibleForTesting @Internal public static void clearLoadingIssues() -
addLoadingIssue
-