Class ModLoader

java.lang.Object
net.minecraftforge.fml.ModLoader

public class ModLoader extends 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 : net.minecraftforge.fml.common.Mod.EventBusSubscriber, net.minecraftforge.event.RegistryEvent, net.minecraftforge.common.capabilities.CapabilityInject and others
CONFIG_LOAD
Dispatches ConfigLoadEvent to mods
COMMON_SETUP
Dispatches net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent to mods
SIDED_SETUP
Dispatches net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent or net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent to mods
Overall sequence for finishMods is:
ENQUEUE_IMC
Dispatches net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent to mods, for enqueuing InterModComms messages for other mods to receive subsequently
PROCESS_IMC
Dispatches net.minecraftforge.fml.event.lifecycle.InterModProcessEvent to mods, for processing InterModComms messages received from other mods prior to this event
COMPLETE
Dispatches net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent to mods, and completes the mod loading sequence.
  • Field Details

    • LOGGER

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

      private static ModLoader INSTANCE
    • loadingModList

      private final LoadingModList loadingModList
    • loadingExceptions

      private final List<ModLoadingException> loadingExceptions
    • loadingWarnings

      private final List<ModLoadingWarning> loadingWarnings
    • stateManager

      private final ModStateManager stateManager
    • loadingStateValid

      private boolean loadingStateValid
    • statusConsumer

      private final Optional<Consumer<String>> statusConsumer
    • completedStates

      private final Set<IModLoadingState> completedStates
    • modList

      private ModList modList
    • runningDataGen

      private static boolean runningDataGen
  • Constructor Details

    • ModLoader

      private ModLoader()
  • Method Details

    • computeLanguageList

      private String computeLanguageList()
    • computeModLauncherServiceList

      private String computeModLauncherServiceList()
    • get

      public static ModLoader get()
    • gatherAndInitializeMods

      public void gatherAndInitializeMods(ModWorkManager.DrivenExecutor 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
    • loadMods

      public void loadMods(ModWorkManager.DrivenExecutor syncExecutor, Executor parallelExecutor, Runnable periodicTask)
    • finishMods

      public void finishMods(ModWorkManager.DrivenExecutor syncExecutor, Executor parallelExecutor, Runnable periodicTask)
    • dispatchAndHandleError

      private void dispatchAndHandleError(IModLoadingState state, ModWorkManager.DrivenExecutor syncExecutor, Executor parallelExecutor, Runnable ticker, ProgressMeter progressBar)
    • handleInlineTransition

      private void handleInlineTransition(Consumer<ModList> transition, IModLoadingState state, ModWorkManager.DrivenExecutor syncExecutor, Runnable ticker)
    • waitForTransition

      private void waitForTransition(IModLoadingState state, ModWorkManager.DrivenExecutor syncExecutor, Runnable ticker, CompletableFuture<Void> transition)
    • buildMods

      private List<ModContainer> buildMods(net.minecraftforge.forgespi.locating.IModFile modFile)
    • buildModContainerFromTOML

      private ModContainer buildModContainerFromTOML(net.minecraftforge.forgespi.locating.IModFile modFile, Map<String,net.minecraftforge.forgespi.language.IModInfo> modInfoMap, Map.Entry<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"
    • hasCompletedState

      public boolean hasCompletedState(String stateName)
    • runEventGenerator

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

      public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> void postEvent(T e)
    • postEventWithReturn

      public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> T postEventWithReturn(T e)
    • postEventWrapContainerInModOrder

      public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> void postEventWrapContainerInModOrder(T event)
    • postEventWithWrapInModOrder

      public <T extends net.minecraftforge.eventbus.api.Event & IModBusEvent> void postEventWithWrapInModOrder(T e, BiConsumer<ModContainer,T> pre, BiConsumer<ModContainer,T> post)
    • getWarnings

      public List<ModLoadingWarning> getWarnings()
    • addWarning

      public void addWarning(ModLoadingWarning warning)
    • isDataGenRunning

      public static boolean isDataGenRunning()