Skip to content

Quick Start

Moth edited this page Aug 9, 2026 · 1 revision

Quick Start

The easiest way to begin using Butterfly API is to create a ModContext for your mod.

A ModContext gives you access to Butterfly API's registration helpers, identifiers, creative tabs, client helpers, and other utilities.

Create a ModContext

Inside your main mod class:

package com.example;

import moth.butterflyapi.ButterflyApi;
import moth.butterflyapi.mod.ModContext;
import net.fabricmc.api.ModInitializer;

public class ExampleMod implements ModInitializer {

    public static final ModContext MOD =
            ButterflyApi.mod("example_mod", "Example Mod");

    @Override
    public void onInitialize() {
    }
}

Replace:

example_mod

with your mod ID, and:

Example Mod

with your mod's display name.

You should normally create one ModContext and reuse it throughout your mod.

Register an Item

You can now use the context to register content.

For example:

import net.minecraft.item.Item;

public static final Item EXAMPLE_ITEM = MOD.item(
        "example_item",
        settings -> new Item(settings)
);

This registers:

example_mod:example_item

Butterfly API automatically creates the correct registry key and item settings before the item is constructed.

Create Identifiers

You can also create namespaced identifiers using:

MOD.id("example_item");

This produces:

example_mod:example_item

Instead of repeatedly writing:

Identifier.of("example_mod", "example_item");

Keyed Settings

Minecraft 1.21.11 expects blocks and items to have their registry keys attached to their settings before construction.

Butterfly API provides:

MOD.itemSettings("example_item");

and:

MOD.blockSettings("example_block");

These create settings containing the correct registry key for your mod.

When using Butterfly API's factory-based registration methods, this is handled automatically.

Common ModContext Helpers

Your context provides access to:

MOD.id(...)
MOD.item(...)
MOD.block(...)
MOD.sound(...)

MOD.registrar()
MOD.tabs()
MOD.client()

There are additional registration methods for other Minecraft registry types.

Next

For more information about the context itself, see Mod Context.

For all available registration helpers, see Registration.

Clone this wiki locally