AllVariantsLoadedEvent - MeAlam1/BlueLib GitHub Wiki


AllVariantsLoadedEvent

The AllVariantsLoadedEvent is fired once all known variants for a particular entity have been registered. This allows mod developers to modify, add, or reject variants at the correct time in the loading lifecycle.

There are two phases to this event:

  • Pre – allows cancellation or conditional filtering of variants.
  • Post – triggered after all variants have been loaded.

Use this to dynamically adjust behavior or content related to entities with multiple variants (e.g., dragon types, mob skins, etc.).


How to Use

Pre Phase (Before Variants Are Fully Registered)

  • Can be used to cancel or prevent certain variants from being loaded.
  • Only available if the event is cancellable (NeoForge) or returns false (Fabric).

Post Phase (After All Variants Are Registered)

  • Used to react to the final set of loaded variants (e.g., logging, applying transformations).

Example Use Cases

  • Remove certain variants based on config or biome rules.
  • Inject additional custom variants dynamically.
  • Log or validate the final list of variants after load.

NeoForge Usage

NeoForge

Listening to the Event

You can listen to both Pre and Post events on the mod event bus:

@SubscribeEvent
public void onPreVariantsLoad(AllVariantsLoadedEvent.Pre event) {
    if (event.getEntity().equals("example_entity")) {
        event.setCanceled(true); // prevent all variants for this entity from loading
    }
}

@SubscribeEvent
public void onPostVariantsLoad(AllVariantsLoadedEvent.Post event) {
    System.out.println("All variants loaded for: " + event.getEntity());
}

Event Bus Registration

Register your event handler on the mod event bus:

ModLoadingContext.get().getModEventBus().register(new YourModEventHandler());

Fabric Usage

Fabric

Pre Listener (Cancelable)

Use AllVariantsLoadedEvent.ALLOW_ALL_VARIANTS_TO_LOAD to allow or deny variant loading:

AllVariantsLoadedEvent.ALLOW_ALL_VARIANTS_TO_LOAD.register(entityName -> {
    if (entityName.equals("example_entity")) {
        return false; // deny loading all variants for this entity
    }
    return true;
});

Post Listener

Use AllVariantsLoadedEvent.POST to react after all variants have been loaded:

AllVariantsLoadedEvent.POST.register(entityName -> {
    System.out.println("All variants loaded for: " + entityName);
});

Notes

  • The entityName string is used to identify which entity's variants are being handled.
  • You can use this event to interact with datapack-driven systems, especially if your entities or variants are defined in JSON.

⚠️ **GitHub.com Fallback** ⚠️