Class ModLoader

java.lang.Object
net.neoforged.fml.ModLoader

public final class ModLoader extends Object
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.

  • Field Details

    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
    • loadingIssues

      private static final List<ModLoadingIssue> loadingIssues
    • modList

      private static ModList modList
  • Constructor Details

    • ModLoader

      private ModLoader()
  • Method Details

    • computeLanguageList

      private static String computeLanguageList()
    • computeModLauncherServiceList

      private static String 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 thread
      parallelExecutor - An executor to run tasks on a parallel loading thread pool
      periodicTask - Optional periodic task to perform on the main thread while other activities run
    • cancelLoading

      private static void cancelLoading(ModList modList)
    • constructMods

      private static void constructMods(Executor syncExecutor, Executor parallelExecutor, Runnable periodicTask)
    • runInitTask

      public static void runInitTask(String name, Executor syncExecutor, Runnable periodicTask, Runnable initTask)
      Runs a single task on the syncExecutor, 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

      public 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.
    • 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

      private static void waitForFuture(String name, Runnable periodicTask, CompletableFuture<?> future)
    • isMeaningfulException

      private static boolean isMeaningfulException(Throwable error)
    • addLoadingIssuesFromException

      private static void addLoadingIssuesFromException(String context, Throwable error)
    • buildMods

      private static List<ModContainer> buildMods(IModFile modFile)
    • buildModContainerFromTOML

      private static ModContainer buildModContainerFromTOML(IModInfo modInfo, ModFileScanData scanData)
    • runEventGenerator

      public static <T extends net.neoforged.bus.api.Event & IModBusEvent> void runEventGenerator(Function<ModContainer,T> generator)
    • postEvent

      public static <T extends net.neoforged.bus.api.Event & IModBusEvent> void postEvent(T e)
    • postEventWithReturn

      public static <T extends net.neoforged.bus.api.Event & IModBusEvent> T postEventWithReturn(T e)
    • 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

      @Internal public static List<ModLoadingIssue> getLoadingErrors()
    • getLoadingWarnings

      @Internal public static List<ModLoadingIssue> getLoadingWarnings()
    • getLoadingIssues

      @Internal public static List<ModLoadingIssue> getLoadingIssues()
    • clearLoadingIssues

      @VisibleForTesting @Internal public static void clearLoadingIssues()
    • addLoadingIssue

      @Internal public static void addLoadingIssue(ModLoadingIssue issue)