Class ModContainer

java.lang.Object
net.neoforged.fml.ModContainer
Direct Known Subclasses:
FMLModContainer, MinecraftModContainer

public abstract class ModContainer extends Object
The container that wraps around mods in the system.

The philosophy is that individual mod implementation technologies should not impact the actual loading and management of mod code. This class provides a mechanism by which we can wrap actual mod code so that the loader and other facilities can treat mods at arms length.

  • Field Details

    • LOGGER

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

      protected final String modId
    • namespace

      protected final String namespace
    • modInfo

      protected final IModInfo modInfo
    • extensionPoints

      protected final Map<Class<? extends IExtensionPoint>,Supplier<?>> extensionPoints
  • Constructor Details

    • ModContainer

      public ModContainer(IModInfo info)
  • Method Details

    • getModId

      public final String getModId()
      Returns:
      the modid for this mod
    • getNamespace

      public final String getNamespace()
      Returns:
      the resource prefix for the mod
    • getModInfo

      public IModInfo getModInfo()
    • getCustomExtension

      public <T extends IExtensionPoint> Optional<T> getCustomExtension(Class<T> point)
    • registerExtensionPoint

      public <T extends IExtensionPoint> void registerExtensionPoint(Class<T> point, T extension)
      Registers an IExtensionPoint with the mod container.
    • registerExtensionPoint

      public <T extends IExtensionPoint> void registerExtensionPoint(Class<T> point, Supplier<T> extension)
      Registers an IExtensionPoint with the mod container. This overload allows passing a supplier that will only be evaluated when the extension is requested.
    • registerConfig

      public void registerConfig(ModConfig.Type type, IConfigSpec configSpec)
      Adds a ModConfig with the given type and spec. An empty config spec will be ignored and a debug line will be logged.
      Parameters:
      type - The type of config
      configSpec - A config spec
    • registerConfig

      public void registerConfig(ModConfig.Type type, IConfigSpec configSpec, String fileName)
      Adds a ModConfig with the given type, spec, and overridden file name. An empty config spec will be ignored and a debug line will be logged.
      Parameters:
      type - The type of config
      configSpec - A config spec
    • constructMod

      @OverrideOnly protected void constructMod()
      Function invoked by FML to construct the mod, right before the dispatch of FMLConstructModEvent.
    • getEventBus

      @Nullable public abstract @Nullable net.neoforged.bus.api.IEventBus getEventBus()
      Returns the event bus for this mod, if available.

      Not all mods have an event bus!

      Returns:
      the event bus for this mod, if available
    • acceptEvent

      public final <T extends net.neoforged.bus.api.Event & IModBusEvent> void acceptEvent(T e)
      Accept an arbitrary event for processing by the mod. Posted to getEventBus().
      Parameters:
      e - Event to accept
    • acceptEvent

      public final <T extends net.neoforged.bus.api.Event & IModBusEvent> void acceptEvent(net.neoforged.bus.api.EventPriority phase, T e)
      Accept an arbitrary event for processing by the mod. Posted to getEventBus().
      Parameters:
      e - Event to accept