• Forums

Navigation

  • Home
  • Style Guide
  • Getting Started
    • Home
    • Structuring Your Mod
    • Forge Update Checker
    • Debug Profiler
  • Concepts
    • Sides
    • Resources
    • Data
    • Registries
    • Mod Lifecycle
      • Registry Events
      • Data Generation
      • Common Setup
      • Sided Setup
      • InterModComms
    • Internationalization and localization
  • Blocks
    • Home
    • Blockstates
    • Interaction
  • Animation API
    • Intro to the Animation API
    • Armatures
    • Animation State Machines
    • Using the API
  • Tile Entities
    • Home
    • Renderer
  • Items
    • Home
    • Loot Modification
  • Models
    • Intro to Models
    • Model Files
    • Blockstates
      • Intro to Blockstate JSONs
    • Coloring Textures
    • Item Property Overrides
    • Advanced Models
      • IBakedModel
      • Perspective
      • ItemOverrideList
  • Rendering
    • ItemStackTileEntityRenderer
  • Data Generation
    • Introduction
    • Model Providers
  • Events
    • Basic Usage
  • Networking
    • Home
    • Overview
    • SimpleImpl
    • Entities
  • Data Storage
    • Capabilities
    • World Saved Data
  • Utilities
    • Recipes
    • Tags
  • Effects
    • Particles
    • Sounds
  • Conventions
    • Versioning
    • Locations
  • Advanced Topics
    • Access Transformers
  • Contributing to Forge
    • Getting Started
    • PR Guidelines
  • Legacy Versions
    • Home
    • Porting from 1.13/1.14 to 1.15

Mod Lifecycle

During the mod loading process, the various lifecycle events are fired on the mod-specific event bus. Many actions are performed during these events, such as registering objects, preparing for data generation, or communicating with other mods.

Event listeners should be registered either using @EventBusSubscriber(bus = Bus.MOD) or in the mod constructor:

@Mod.EventBusSubscriber(modid = "mymod", bus = Mod.EventBusSubscriber.Bus.MOD)
public class MyModEventSubscriber {
    @SubscribeEvent
    static void onCommonSetup(FMLCommonSetupEvent event) { ... }
}

@Mod("mymod")
public class MyMod {
    public MyMod() {
        FMLModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
    } 

    private void onCommonSetup(FMLCommonSetupEvent event) { ... }
}

Warning

The lifecycle events are fired in parallel: All mods will concurrently receive the same event.

Mods must take care to be thread-safe, like when calling other mods’ API’s or accessing vanilla systems. Defer code for later execution using the DeferredWorkQueue class.

Registry Events

The RegistryEvents are always the first to fire during mod loading, after the mod instance construction. There are two: the NewRegistry event and the Register event.

The RegistryEvent.NewRegistry event allows modders to register their own custom registries, using the RegistryBuilder class.

The RegistryEvent.Register<?> event is for registering objects into the registries. A Register event is fired for each registry.

Data Generation

If the game is setup to run the data generators, then the GatherDataEvent will be the last event to fire. This event is for registering mods’ data providers to the data generators.

Common Setup

FMLCommonSetupEvent is for actions that are common to both physical client and server, such as registering capabilities.

Sided Setup

The sided-setup events are fired on their respective phyiscal sides: FMLClientSetupEvent on the physical client, and FMLDedicatedServerSetupEvent for the dedicated server. This is where physical side-specific initialization should occur, such as registering client-side key bindings.

InterModComms

This is where messages can be sent to mods for cross-mod compatibility. There are two events: the InterModEnqueueEvent and InterModProcessEvent.

InterModComms is the class responsible for holding messages for mods. This class is safe to call during the lifecycle events, as it is backed by a ConcurrentMap.

During the InterModEnqueueEvent, use InterModComms.sendTo to send messages to different mods, then during the InterModProcessEvent, call InterModComms.getMessages to get a stream of all received messages.

Note

There is one last lifecycle event: the FMLLoadCompleteEvent, fired after the InterModComms events, for when the mod loading process is complete.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme