Registry And Content
Register items, blocks, block items, foods, menus, block entities, sounds and creative tabs with RegistryApi.
Some APIs may still change or behave unevenly because they do not have enough real-world use cases and test coverage yet.
Registry And Content
RegistryApi is the main adapter service for content mods. It accepts stable specs for common content and returns native Minecraft objects for the selected version.
RegistryApi registries = MinecraftApi.registries(context);
Items With ItemSpec
Use ItemSpec for generated or simple items. The adapter converts max stack size, durability, rarity, food, tool and armor intent into native item properties.
Item widget = registries.registerItem(ItemSpec.builder("my_mod:widget")
.maxStackSize(16)
.rarity(ItemRarity.UNCOMMON)
.build());
Use registerCustomItem when the item needs a native subclass.
Item wand = registries.registerCustomItem("my_mod:wand",
properties -> new WandItem(properties.stacksTo(1)));
Food, Tools And Armor
Use FoodSpec, ToolSpec and ArmorSpec when item behavior is simple enough to describe as data. Use native Minecraft materials or subclasses when behavior depends on version-specific systems.
FoodSpec meal = FoodSpec.builder()
.nutrition(8)
.saturationModifier(0.8F)
.build();
registries.registerItem(ItemSpec.builder("my_mod:packed_lunch")
.food(meal)
.maxStackSize(8)
.build());
Blocks With BlockSpec
Use BlockSpec for common block properties.
BlockEntry machine = registries.registerBlockWithItem(
BlockSpec.builder("my_mod:machine")
.material(BlockMaterial.METAL)
.strength(3.0F, 6.0F)
.requiresCorrectTool()
.sound(BlockSound.METAL)
.item(ItemSpec.builder("my_mod:machine").maxStackSize(32).build())
.build());
The returned BlockEntry gives you both the native block and its native block item:
Block machineBlock = machine.block();
BlockItem machineItem = machine.item();
Use registerCustomBlock when your block owns real Minecraft behavior.
Block oven = registries.registerCustomBlock("my_mod:oven",
properties -> new OvenBlock(properties.strength(3.5F)));
registries.registerBlockItem("my_mod:oven", oven);
Logic Delegates
ItemLogic and BlockLogic are for simple generated behavior that should stay stable. They let an adapter-owned native wrapper call your logic. If the behavior grows complex, graduate to a native subclass.
registries.registerItem("my_mod:clicker", logic);
registries.registerBlock("my_mod:signal_block", blockLogic);
Menus And Block Entities
Use the adapter factories to avoid repeating version-specific registration boilerplate.
BlockEntityType<OvenBlockEntity> ovenEntity = registries.registerBlockEntity(
"my_mod:oven",
OvenBlockEntity::new,
oven);
MenuType<OvenMenu> ovenMenu = registries.registerMenu(
"my_mod:oven",
OvenMenu::new);
Your block entity and menu classes are still native Minecraft classes. Nows only handles the registration boundary.
Recipes, Sounds And Creative Tabs
Register custom recipe types and serializers through RegistryApi when the recipe itself is native.
RecipeType<OvenRecipe> type = registries.registerRecipeType("my_mod:oven");
RecipeSerializer<OvenRecipe> serializer = registries.registerRecipeSerializer(
"my_mod:oven",
OvenRecipeSerializer.create());
Register common sound events and creative tabs through the adapter too:
SoundEvent ding = registries.registerVariableRangeSound("my_mod:oven_ding");
CreativeModeTab tab = registries.registerCreativeTab(
"my_mod:main",
MinecraftApi.text(context).translatable("itemGroup.my_mod.main"),
() -> registries.itemStack(ItemStackSpec.of("my_mod:machine", 1)),
(parameters, output) -> output.accept(machineItem));
Lookup Helpers
Use Optional-returning lookups when missing content is allowed. Use getItem, getBlock and getCreativeTab when missing content is a programmer error.
registries.item("minecraft:diamond").ifPresent(item -> {
ItemStack stack = new ItemStack(item);
});
Block stone = registries.getBlock("minecraft:stone");