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 revision
Previous revision
Last revisionBoth sides next revision
tutorial:datagen_recipe [2022/09/10 18:18] nexus-dinotutorial:datagen_recipe [2023/06/05 18:07] – Add criterion for shapeless as well mcrafterzz
Line 1: Line 1:
-To generate recipe jsons, you have to use the ''[[https://github.com/FabricMC/fabric/blob/1.19.2/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricRecipeProvider.java|FabricRecipeProvider]]''+====== Recipe Generation ======
  
-To get started, create a class that extends ''FabricRecipeProvider'', and register it in your datagen entrypoint like so: +Before reading this, make sure you've read [[datagen_setup|Getting started with Data Generation]], and have a class that implements ''DataGenerationEntrypoint'' 
 + 
 +To begin, create a class that extends ''FabricRecipeProvider'', and register it in your datagen entrypoint like so: 
  
 <code java> <code java>
 private static class MyRecipeGenerator extends FabricRecipeProvider { private static class MyRecipeGenerator extends FabricRecipeProvider {
- private MyRecipeGenerator(FabricDataGenerator generator) {+ private MyRecipeGenerator(FabricDataOutput generator) {
                 super(generator);                 super(generator);
         }         }
Line 35: Line 37:
 @Override @Override
 protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) { protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) {
-          ShapelessRecipeJsonBuilder.create(SIMPLE_ITEM).input(SIMPLE_BLOCK).offerTo(exporter);+          ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, SIMPLE_ITEM).input(SIMPLE_BLOCK).criterion(FabricRecipeProvider.hasItem(SIMPLE_ITEM),  
 +          FabricRecipeProvider.conditionsFromItem(SIMPLE_ITEM)).criterion(FabricRecipeProvider.hasItem(SIMPLE_BLOCK ),  
 +          FabricRecipeProvider.conditionsFromItem(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>
Line 44: Line 69:
 public static final Block EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "example_ore"), new Block(...)); public static final Block EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "example_ore"), new Block(...));
 public static final Block DEEPSLATE_EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "deepslate_example_ore"), new Block(...)); public static final Block DEEPSLATE_EXAMPLE_ORE = Registry.register(Registry.BLOCK, new Identifier("mymod", "deepslate_example_ore"), new Block(...));
-public static final Item EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "example_ore"), new BlockItem(EXAMPLE_ORE, ...));+public static final Item EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "example_ore"), new BlockItem(DEEPSLATE_EXAMPLE_ORE, ...));
 public static final Item DEEPSLATE_EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "deepslate_example_ore"), new BlockItem(EXAMPLE_ORE, ...)); public static final Item DEEPSLATE_EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, new Identifier("mymod", "deepslate_example_ore"), new BlockItem(EXAMPLE_ORE, ...));
 public static final Item RAW_EXAMPLE = Registry.register(Registry.ITEM, new Identifier("mymod", "raw_example"), new Item(...)); public static final Item RAW_EXAMPLE = Registry.register(Registry.ITEM, new Identifier("mymod", "raw_example"), new Item(...));
tutorial/datagen_recipe.txt · Last modified: 2023/06/05 18:08 by mcrafterzz