Class FMLLoader

java.lang.Object
net.neoforged.fml.loading.FMLLoader
All Implemented Interfaces:
AutoCloseable

public final class FMLLoader extends Object implements AutoCloseable
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • current

      private static final AtomicReference<@Nullable FMLLoader> current
    • originalClassLoader

      @Nullable private final @Nullable ClassLoader originalClassLoader
      The context class-loader that will be restored when the loader is closed.
    • currentClassLoader

      private ClassLoader currentClassLoader
      The current tail of the class-loader chain. It is moved whenever a new set of Jars is loaded.
    • ownedResources

      private final List<AutoCloseable> ownedResources
      Resources owned by this loader, such as opened URL classloaders, which will be closed alongside the loader.
    • closeCallbacks

      private final List<AutoCloseable> closeCallbacks
      Additional user-supplied resources that will be closed, before this loader itself is closed.
    • programArgs

      private final ProgramArgs programArgs
    • languageProviderLoader

      private LanguageProviderLoader languageProviderLoader
    • dist

      private final net.neoforged.api.distmarker.Dist dist
    • loadingModList

      private LoadingModList loadingModList
    • gameDir

      private final Path gameDir
    • locatedPaths

      private final Set<Path> locatedPaths
    • versionInfo

      private VersionInfo versionInfo
    • versionSupportMatrix

      private VersionSupportMatrix versionSupportMatrix
    • backgroundScanHandler

      public BackgroundScanHandler backgroundScanHandler
    • production

      private final boolean production
    • gameLayer

      @Nullable private @Nullable ModuleLayer gameLayer
    • earlyServicesJars

      private final List<ModFile> earlyServicesJars
    • discoveryResult

      @VisibleForTesting FMLLoader.DiscoveryResult discoveryResult
    • classTransformerAuditLog

      private final ClassProcessorAuditLog classTransformerAuditLog
    • bindings

      @Nullable @VisibleForTesting volatile @Nullable IBindingsProvider bindings
  • Constructor Details

    • FMLLoader

      private FMLLoader(ClassLoader currentClassLoader, String[] programArgs, net.neoforged.api.distmarker.Dist dist, boolean production, Path gameDir)
  • Method Details

    • getClassTransformerAuditLog

      @Internal public ClassProcessorAuditSource getClassTransformerAuditLog()
    • getModFileByClass

      @Nullable public @Nullable IModFile getModFileByClass(Class<?> clazz)
      Tries to get the mod file that a given class belongs to.
      Returns:
      Null, if the class doesn't belong to a mod file.
    • addCloseCallback

      public void addCloseCallback(AutoCloseable callback)
      Adds a callback that will be called once, when this loader is about to close.

      Mod files and class-loaders will not be closed yet when the callback is called, allowing for class-loading to occur normally.

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • makeCurrent

      private void makeCurrent()
    • getCurrentClassLoader

      public ClassLoader getCurrentClassLoader()
    • getProgramArgs

      public ProgramArgs getProgramArgs()
    • getBindings

      @Internal public IBindingsProvider getBindings()
    • create

      public static FMLLoader create(StartupArgs startupArgs)
    • create

      public static FMLLoader create(@Nullable @Nullable Instrumentation instrumentation, StartupArgs startupArgs)
    • createClassProcessorSet

      private static ClassProcessorSet createClassProcessorSet(StartupArgs startupArgs, FMLLoader.LaunchContextAdapter launchContext, FMLLoader.DiscoveryResult discoveryResult, MixinFacade mixinFacade)
    • createAccessTransformerService

      private static ClassProcessor createAccessTransformerService(FMLLoader.DiscoveryResult discoveryResult)
    • buildTransformingLoader

      private TransformingClassLoader buildTransformingLoader(ClassProcessorSet classProcessorSet, ClassProcessorAuditLog auditTrail, List<JarContentsModule> content)
    • maskContentAlreadyOnClasspath

      private void maskContentAlreadyOnClasspath(List<JarContentsModule> content)
      If any location being added is already on the classpath, we add a masking classloader to ensure that resources are not double-reported when using getResources/getResource.

      The primary purpose of this is in mod and NeoForge development environments, where IDEs put the mod on the app classpath, but we also add it as content to the game layer. This method is responsible for setting up a classloader that prevents getResource/getResources from reporting Jar resources for both the jar on the App classpath and on the transforming classloader.

    • getBasePaths

      private static List<Path> getBasePaths(JarContents contents, boolean ignoreFilter)
    • getModuleNameList

      private static String getModuleNameList(Configuration cf, List<JarContentsModule> content)
    • detectDist

      private static net.neoforged.api.distmarker.Dist detectDist(ClassLoader classLoader)
    • detectProduction

      private static boolean detectProduction(ClassLoader classLoader)
    • loadEarlyServices

      private void loadEarlyServices(StartupArgs startupArgs)
    • loadPlugins

      private void loadPlugins(List<IModFileInfo> plugins)
    • appendLoader

      private void appendLoader(String loaderName, List<JarContents> jars)
      Loads the given services into a URL classloader.
    • runDiscovery

      private FMLLoader.DiscoveryResult runDiscovery()
    • runOffThread

      private static <T> T runOffThread(Supplier<T> supplier)
    • getLanguageLoadingProvider

      public static LanguageProviderLoader getLanguageLoadingProvider()
    • getCurrent

      public static FMLLoader getCurrent()
    • getCurrentOrNull

      @Nullable public static @Nullable FMLLoader getCurrentOrNull()
    • getDist

      public net.neoforged.api.distmarker.Dist getDist()
    • getLoadingModList

      public LoadingModList getLoadingModList()
      Throws:
      IllegalStateException - if the loading mod list hasn't been built yet.
    • getGameDir

      public Path getGameDir()
    • isProduction

      public boolean isProduction()
    • getGameLayer

      public ModuleLayer getGameLayer()
    • getVersionInfo

      public VersionInfo getVersionInfo()
      Please note that the returned version information can be incomplete until mod discovery has been completed. This is only relevant for early FML services.
    • getVersionSupportMatrix

      VersionSupportMatrix getVersionSupportMatrix()