User Tools

Site Tools


tutorial:datagen_recipe

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:datagen_recipe [2023/06/05 17:47] – Added recipe category mcrafterzztutorial:datagen_recipe [2023/06/05 18:04] – Added example of shaped recipe mcrafterzz
Line 38: Line 38:
 protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) { protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
           ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, SIMPLE_ITEM).input(SIMPLE_BLOCK).offerTo(exporter);           ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, SIMPLE_ITEM).input(SIMPLE_BLOCK).offerTo(exporter);
 +}
 +</code>
 +
 +===== Adding A Shaped Recipe =====
 +In this example, we will create a shaped recipe where a stone block is crafted from ''EXAMPLE_ITEM''s and ''EXAMPLE_BLOCK''s.
 +
 +<code java>
 +public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier("mymod", "simple_block"), new Block(...));
 +public static BlockItem SIMPLE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "simple_item"), new Item(...));
 +// ...
 +
 +@Override
 +protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
 +          ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, Blocks.STONE_BLOCK).pattern("bbb").pattern("iii")
 +                .input('b', SIMPLE_BLOCK)
 +                .input('i', SIMPLE_ITEM)
 +                .criterion(FabricRecipeProvider.hasItem(SIMPLE_ITEM),
 +                        FabricRecipeProvider.conditionsFromItem(SIMPLE_ITEM))
 +                .criterion(FabricRecipeProvider.hasItem(SIMPLE_BLOCK),
 +                        FabricRecipeProvider.conditionsFromItem(SIMPLE_BLOCK))
 +                .offerTo(exporter);
 } }
 </code> </code>
tutorial/datagen_recipe.txt · Last modified: 2023/06/05 18:08 by mcrafterzz