ModLoadedEvent - MeAlam1/BlueLib GitHub Wiki
The ModLoadedEvent
is triggered when a single mod has finished loading and its metadata is available. This event provides the mod's metadata, such as the mod ID, version, description, and more. It's perfect for scenarios where you need to interact with a specific mod immediately after it has been loaded.
This event is ideal for mod developers who want to hook into the mod loading process for individual mods and need access to their metadata for dynamic interaction.
This event gives you access to a single mod's metadata at the point when it has finished loading. You can:
- Inspect the mod's metadata (ID, version, description).
- Apply custom logic based on the specific mod's data.
- Perform actions like loading custom assets, performing checks, or validating configurations related to the mod.
- Log mod loading details for diagnostics or debugging.
- Perform mod-specific configuration when the mod is loaded.
- Verify mod dependencies or check compatibility with other mods.
- Load custom assets or configurations only if a specific mod is present.
Each loaded mod is represented by the ModMeta
record, which contains the following fields:
Field | Type | Description |
---|---|---|
modId |
String |
The internal mod ID used for identification (e.g., examplemod ). |
displayName |
String |
The user-facing name of the mod (e.g., Example Mod ). |
version |
String |
The version of the mod, typically in SemVer (e.g., 1.2.3 ). |
description |
String |
A short description of what the mod does. |
logoFile |
Optional<String> |
The path to the logo file used by the mod, if present. |
NeoForge
Use the mod event bus to listen for the ModLoadedEvent
:
@SubscribeEvent
public void onModLoaded(ModLoadedEvent event) {
ModMeta meta = event.getModData();
System.out.println("Mod loaded: " + meta.modId() + " - Version: " + meta.version());
// Example: Check if it's a specific mod
if (meta.modId().equals("examplemod")) {
System.out.println("ExampleMod has been successfully loaded!");
}
}
Register your event handler:
ModLoadingContext.get().getModEventBus().register(new YourModEventHandler());
Fabric
Use ModLoadedEvent.EVENT
to react when a specific mod has been loaded:
ModLoadedEvent.EVENT.register(modData -> {
System.out.println("Mod loaded: " + modData.modId() + " (version: " + modData.version() + ")");
// Example: Check for a specific mod
if (modData.modId().equals("examplemod")) {
System.out.println("examplemod has been successfully loaded!");
}
});
- The
ModLoadedEvent
provides metadata for a single mod rather than the full list of mods. - This event fires after a mod is loaded, making it ideal for interactions that are specific to one mod.
- You can use this event to trigger dynamic mod-related actions as soon as a mod is available, such as logging, resource loading, or configuration updates.