Buckets:
| package com.example.examplemod.datagen; | |
| import com.example.examplemod.ExampleMod; | |
| import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | |
| import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | |
| import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; | |
| import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; | |
| import net.minecraft.data.recipe.RecipeExporter; | |
| import net.minecraft.data.recipe.RecipeGenerator; | |
| import net.minecraft.item.Items; | |
| import net.minecraft.recipe.book.RecipeCategory; | |
| import net.minecraft.registry.RegistryKeys; | |
| import net.minecraft.registry.tag.ItemTags; | |
| import net.minecraft.registry.tag.TagKey; | |
| import net.minecraft.registry.RegistryWrapper; | |
| import net.minecraft.util.Identifier; | |
| import java.util.concurrent.CompletableFuture; | |
| /** | |
| * Datagen entrypoint - run via the "runDatagen" Gradle task. Generates | |
| * recipes and item tags automatically instead of hand-writing JSON. | |
| * Fabric's datagen API (v1) is the current standard for 1.21.7 - 1.21.11. | |
| * | |
| * Register in fabric.mod.json -> "entrypoints" -> "fabric-datagen": | |
| * ["com.example.examplemod.datagen.ExampleDataGenerator"] | |
| */ | |
| public class ExampleDataGenerator implements DataGeneratorEntrypoint { | |
| public void onInitializeDataGenerator(FabricDataGenerator generator) { | |
| FabricDataGenerator.Pack pack = generator.createPack(); | |
| pack.addProvider(ExampleRecipeProvider::new); | |
| pack.addProvider(ExampleItemTagProvider::new); | |
| } | |
| /** Generates a shapeless recipe: 4x example_gem -> 1 example_block. */ | |
| private static class ExampleRecipeProvider extends FabricRecipeProvider { | |
| ExampleRecipeProvider(FabricDataOutput output, | |
| CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) { | |
| super(output, registriesFuture); | |
| } | |
| public RecipeGenerator getRecipeGenerator(RegistryWrapper.WrapperLookup lookup, RecipeExporter exporter) { | |
| return new RecipeGenerator(lookup, exporter) { | |
| public void generate() { | |
| createShapeless(RecipeCategory.BUILDING_BLOCKS, ExampleMod.EXAMPLE_BLOCK) | |
| .input(ExampleMod.EXAMPLE_GEM, 4) | |
| .criterion(hasItem(ExampleMod.EXAMPLE_GEM), conditionsFromItem(ExampleMod.EXAMPLE_GEM)) | |
| .offerTo(exporter); | |
| } | |
| }; | |
| } | |
| public String getName() { | |
| return "ExampleMod Recipes"; | |
| } | |
| } | |
| /** Adds example_gem to the c:gems tag for cross-mod compatibility. */ | |
| private static class ExampleItemTagProvider extends FabricTagProvider.ItemTagProvider { | |
| ExampleItemTagProvider(FabricDataOutput output, | |
| CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) { | |
| super(output, registriesFuture); | |
| } | |
| protected void configure(RegistryWrapper.WrapperLookup lookup) { | |
| TagKey<net.minecraft.item.Item> gemsTag = TagKey.of(RegistryKeys.ITEM, Identifier.of("c", "gems")); | |
| getOrCreateTagBuilder(gemsTag).add(ExampleMod.EXAMPLE_GEM); | |
| } | |
| } | |
| } | |
| // Note: FabricDataOutput import resolves from net.fabricmc.fabric.api.datagen.v1.FabricDataOutput | |
Xet Storage Details
- Size:
- 3.37 kB
- Xet hash:
- 3f3c5561fbc3d009f160da658843cfb7511824339bf2722417bc28db8af8caa0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.