tutorial:datagen_recipe
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:datagen_recipe [2022/09/10 15:20] – nexus-dino | tutorial:datagen_recipe [2023/06/05 18:08] (current) – Remove spaces 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]], | ||
+ | |||
+ | To begin, create a class that extends '' | ||
+ | |||
+ | <code java> | ||
+ | private static class MyRecipeGenerator extends FabricRecipeProvider { | ||
+ | private MyRecipeGenerator(FabricDataOutput generator) { | ||
+ | super(generator); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void generateRecipes(Consumer< | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // ... | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { | ||
+ | | ||
+ | fabricDataGenerator.addProvider(MyRecipeGenerator:: | ||
+ | | ||
+ | } | ||
+ | </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 '' | ||
+ | |||
+ | <code java> | ||
+ | public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, | ||
+ | public static BlockItem SIMPLE_ITEM = Registry.register(Registry.ITEM, | ||
+ | // ... | ||
+ | |||
+ | @Override | ||
+ | protected void generateRecipes(Consumer< | ||
+ | ShapelessRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, | ||
+ | FabricRecipeProvider.conditionsFromItem(SIMPLE_ITEM)).criterion(FabricRecipeProvider.hasItem(SIMPLE_BLOCK), | ||
+ | FabricRecipeProvider.conditionsFromItem(SIMPLE_BLOCK)).offerTo(exporter); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Adding A Shaped Recipe ===== | ||
+ | In this example, we will create a shaped recipe where a stone block is crafted from '' | ||
+ | |||
+ | < | ||
+ | public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, | ||
+ | public static BlockItem SIMPLE_ITEM = Registry.register(Registry.ITEM, | ||
+ | // ... | ||
+ | |||
+ | @Override | ||
+ | protected void generateRecipes(Consumer< | ||
+ | ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, | ||
+ | .input(' | ||
+ | .input(' | ||
+ | .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/ | ||
+ | < | ||
+ | public static final Block EXAMPLE_ORE = Registry.register(Registry.BLOCK, | ||
+ | public static final Block DEEPSLATE_EXAMPLE_ORE = Registry.register(Registry.BLOCK, | ||
+ | public static final Item EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, | ||
+ | public static final Item DEEPSLATE_EXAMPLE_ORE_ITEM = Registry.register(Registry.ITEM, | ||
+ | public static final Item RAW_EXAMPLE = Registry.register(Registry.ITEM, | ||
+ | public static final Item EXAMPLE_INGOT = Registry.register(Registry.ITEM, | ||
+ | |||
+ | // Alternatively, | ||
+ | public static final List< | ||
+ | list.add(EXAMPLE_ORE); | ||
+ | list.add(DEEPSLATE_EXAMPLE_ORE); | ||
+ | list.add(RAW_EXAMPLE); | ||
+ | }); | ||
+ | |||
+ | @Override | ||
+ | protected void generateRecipes(Consumer< | ||
+ | RecipeProvider.offerSmelting(exporter, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Mojang has a lot of utility methods in '' |
tutorial/datagen_recipe.1662823230.txt.gz · Last modified: 2022/09/10 15:20 by nexus-dino