-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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.
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.
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");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.
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.
For more information about the context itself, see Mod Context.
For all available registration helpers, see Registration.