-
Notifications
You must be signed in to change notification settings - Fork 0
Registration
Butterfly API provides registration helpers through ModContext and Registrar.
For most normal registrations, you can use the shortcut methods directly on your ModContext.
public static final ModContext MOD =
ButterflyApi.mod("example_mod", "Example Mod");Register an item with:
public static final Item EXAMPLE_ITEM = MOD.item(
"example_item",
settings -> new Item(settings)
);This registers:
example_mod:example_item
The factory receives item settings containing the correct 1.21.11 registry key.
Register a block and matching block item with:
public static final Block EXAMPLE_BLOCK = MOD.block(
"example_block",
settings -> new Block(settings)
);By default, block(...) registers both:
example_mod:example_block
as a block and as an item.
Use blockOnly(...) when the block should not receive a matching item.
Block block = new Block(MOD.blockSettings("example_block"));
MOD.blockOnly("example_block", block);The door(...) helper registers a block with a TallBlockItem instead of a normal BlockItem.
MOD.door("example_door", EXAMPLE_DOOR);For more control, use blockBuilder(...).
public static final BlockRegistration<Block> EXAMPLE_BLOCK =
MOD.blockBuilder("example_block", Block::new)
.settings(settings -> settings.strength(2.0F))
.register();The builder uses a normal block item by default.
MOD.blockBuilder("example_block", Block::new)
.itemSettings(settings -> settings.maxCount(16))
.register();MOD.blockBuilder("example_block", Block::new)
.noItem()
.register();MOD.blockBuilder("example_door", settings -> new DoorBlock(...))
.tallBlockItem()
.register();MOD.blockBuilder("example_block", Block::new)
.itemFactory(block -> new CustomBlockItem(
block,
MOD.itemSettings("example_block")
))
.register();register() returns a BlockRegistration containing:
registration.block();
registration.item();The item may be null when .noItem() is used.
Create and register a normal sound event with:
public static final SoundEvent EXAMPLE_SOUND =
MOD.sound("example_sound");You can also provide an existing SoundEvent:
MOD.sound("example_sound", soundEvent);Butterfly API also provides helpers for:
MOD.entity(...)
MOD.blockEntityType(...)
MOD.screenHandler(...)
MOD.statusEffect(...)
MOD.potion(...)
MOD.recipeSerializer(...)
MOD.recipeType(...)
MOD.particle(...)
MOD.tab(...)For registries without a dedicated shortcut, use:
MOD.register(registry, "path", value);Butterfly API automatically creates the identifier using your mod namespace.
The underlying registrar can be accessed directly:
MOD.registrar();For normal usage, the shortcut methods on ModContext are usually simpler.
Minecraft 1.21.11 handles enchantments and painting variants through data-driven dynamic registries.
Because of this:
MOD.enchantment(...)
MOD.painting(...)do not perform normal static registry registration.
Their actual registry entries should be defined through Minecraft's data-driven systems.