Skip to content

Mod Context

Moth edited this page Aug 9, 2026 · 1 revision

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.

Creating a ModContext

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.

Identifiers

MOD.id("example_item");

Returns:

example_mod:example_item

Registry Keys

Butterfly API can create block and item registry keys for your namespace.

MOD.blockKey("example_block");
MOD.itemKey("example_item");

Block and Item Settings

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.

Registration Helpers

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 Tabs

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.

Plushes

Create a plush definition with:

MOD.plush("example_plush");

See Plush API.

Client Helpers

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.

Logger

Each context also provides a logger:

MOD.logger();

For example:

MOD.logger().info("Example Mod initialized!");

Mod Information

You can retrieve the context's mod ID and name with:

MOD.modId();
MOD.modName();

Related Pages

Clone this wiki locally