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 15:20] nexus-dinotutorial:datagen_recipe [2023/06/05 18:07] – Add criterion for shapeless as well mcrafterzz
Line 1: Line 1:
-''[[https://github.com/FabricMC/fabric/blob/1.19.2/fabric-data-generation-api-v1/src/testmod/java/net/fabricmc/fabric/test/datagen/DataGeneratorTestEntrypoint.java|FabricRecipeProvider]]''+====== Recipe Generation ====== 
 + 
 +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> 
 +private static class MyRecipeGenerator extends FabricRecipeProvider { 
 + private MyRecipeGenerator(FabricDataOutput generator) { 
 +                super(generator); 
 +        } 
 +         
 +        @Override 
 + protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) { 
 +                  // ... 
 +        } 
 +
 + 
 +// ... 
 + 
 +@Override 
 +public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { 
 +    // ..
 +    fabricDataGenerator.addProvider(MyRecipeGenerator::new); 
 +    // ... 
 +
 +</code> 
 + 
 +===== Adding A Shapeless Recipe ===== 
 +Now that you have your recipe generator, you can call different methods depending on what you want, in this example, we will create a recipe where a ''EXAMPLE_ITEM'' is given from ''EXAMPLE_BLOCK''
 + 
 +<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) { 
 +          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> 
 + 
 +===== Adding A Smelting/Blasting/Smoking Recipe ===== 
 +Smelting/Blasting/Smoking recipes are quite similar to crafting recipesThe difference is that you use the ''CookingRecipeJsonBuilder'': 
 +<code java
 +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 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 RAW_EXAMPLE = Registry.register(Registry.ITEM, new Identifier("mymod", "raw_example"), new Item(...)); 
 +public static final Item EXAMPLE_INGOT = Registry.register(Registry.ITEM, new Identifier("mymod", "example_ingot"), new Item(...)); 
 + 
 +// Alternatively, you can just do List.of(...), but this is personal preference... 
 +public static final List<ItemConvertible> SMELTABLE_TO_EXAMPLE_INGOT = Util.make(Lists.newArrayList(), list -> { 
 +      list.add(EXAMPLE_ORE); 
 +      list.add(DEEPSLATE_EXAMPLE_ORE); 
 +      list.add(RAW_EXAMPLE); 
 +}); 
 + 
 +@Override 
 +protected void generateRecipes(Consumer<RecipeJsonProvider> exporter) { 
 + RecipeProvider.offerSmelting(exporter, SMELTABLE_TO_EXAMPLE_INGOT, EXAMPLE_INGOT, 0.45F, 300, "example"); 
 +
 +</code> 
 + 
 +Mojang has a lot of utility methods in ''RecipeProvider'' are available to use as well thanks to access wideners :)
tutorial/datagen_recipe.txt · Last modified: 2023/06/05 18:08 by mcrafterzz