-
Notifications
You must be signed in to change notification settings - Fork 4
VariantLoadedEvent
Aram edited this page May 4, 2025
·
1 revision
The VariantLoadedEvent is fired for each individual variant during the variant registration process. This provides a precise hook for developers to accept, reject, or react to specific variants for an entity.
There are two phases to this event:
- Pre – lets you cancel the loading of a specific variant.
- Post – runs after the variant is fully loaded and registered.
Use this when you need granular control over which variants are accepted or when you want to perform actions per variant (rather than once for all variants).
- Allows you to cancel the registration of a specific variant.
- Useful for conditional filtering based on user settings, mod compatibility, or world data.
- Lets you respond to the loading of a specific variant.
- Ideal for logging, transformation, or injecting additional logic after registration.
- Skip loading a variant based on player config.
- Log each variant as it's registered.
- Modify entity behavior or model based on the variant name.
- Prevent a specific variant from loading in certain dimensions or biomes.
NeoForge
Use the mod event bus to listen to both Pre and Post phases:
@SubscribeEvent
public void onPreVariantLoad(VariantLoadedEvent.Pre event) {
if (event.getEntity().equals("dragon") && event.getVariant().equals("lava")) {
event.setCanceled(true); // Skip the "lava" variant
}
}
@SubscribeEvent
public void onPostVariantLoad(VariantLoadedEvent.Post event) {
System.out.println("Loaded variant: " + event.getVariant() + " for entity: " + event.getEntity());
}Register your listener:
ModLoadingContext.get().getModEventBus().register(new YourModEventHandler());Fabric
Use VariantLoadedEvent.ALLOW_VARIANT_TO_LOAD to conditionally allow or deny a specific variant:
VariantLoadedEvent.ALLOW_VARIANT_TO_LOAD.register((entityName, variantName) -> {
if (entityName.equals("dragon") && variantName.equals("ice")) {
return false; // Skip "ice" variant
}
return true;
});Use VariantLoadedEvent.POST to react after a variant has been registered:
VariantLoadedEvent.POST.register((entityName, variantName) -> {
System.out.println("Loaded variant: " + variantName + " for entity: " + entityName);
});- The
entityNameidentifies which entity is being processed. - The
variantstring refers to the specific variant ID or name being registered. - You can use this event in tandem with datapack-driven systems that define variants in JSON.
-
VariantLoadedEventoffers more granular control thanAllVariantsLoadedEvent, which processes all variants at once.
Variant Loader
Data Pipeline
Network & Packets
Logging
Markdown
Utility Classes
- Conversion
- Math
- Minecraft
- Schedular