-
Notifications
You must be signed in to change notification settings - Fork 0
Mod Context
ModContext is the main entry point for Butterfly API's helper systems.
Instead of repeatedly creating identifiers, registry keys, settings, registrars, and other helpers for your mod, you create one ModContext and reuse it.
import moth.butterflyapi.ButterflyApi;
import moth.butterflyapi.mod.ModContext;
public static final ModContext MOD =
ButterflyApi.mod("example_mod", "Example Mod");The first value is your mod ID:
example_mod
The second is your mod's display name:
Example Mod
You should normally create one context and reuse it throughout your mod.
MOD.id("example_item");Returns:
example_mod:example_item
Butterfly API can create block and item registry keys for your namespace.
MOD.blockKey("example_block");
MOD.itemKey("example_item");Minecraft 1.21.11 expects block and item settings to contain their registry key before construction.
Use:
MOD.blockSettings("example_block");
MOD.itemSettings("example_item");For example:
public static final Item EXAMPLE_ITEM =
new Item(MOD.itemSettings("example_item"));When using Butterfly API's factory-based registration methods, these settings are created automatically.
ModContext provides shortcuts for registering content.
Examples include:
MOD.item(...)
MOD.block(...)
MOD.blockOnly(...)
MOD.blockBuilder(...)
MOD.door(...)
MOD.sound(...)
MOD.entity(...)
MOD.blockEntityType(...)
MOD.screenHandler(...)
MOD.statusEffect(...)
MOD.potion(...)
MOD.recipeSerializer(...)
MOD.recipeType(...)
MOD.particle(...)See Registration for the complete registration reference.
Creative tab helpers are available through:
MOD.tabs();You can also use shortcuts such as:
MOD.tabBuilder("example_tab");
MOD.tabKey("example_tab");
MOD.tabTranslationKey("example_tab");See Creative Tabs.
Create a plush definition with:
MOD.plush("example_plush");See Plush API.
Client registration helpers are available through:
MOD.client();There are also direct shortcuts such as:
MOD.cutout(...)
MOD.translucent(...)
MOD.entityRenderer(...)
MOD.blockEntityRenderer(...)
MOD.screen(...)
MOD.modelLayer(...)
MOD.particleFactory(...)These helpers may only be used on the physical client.
See Client Registration.
Each context also provides a logger:
MOD.logger();For example:
MOD.logger().info("Example Mod initialized!");You can retrieve the context's mod ID and name with:
MOD.modId();
MOD.modName();