tutorial:datagen_setup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:datagen_setup [2022/08/29 18:39] – Fix issue in example gradle script. modmuss50 | tutorial:datagen_setup [2025/03/25 00:41] (current) – [IDE Integration (Optional)] removed the section solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Getting started with Data Generation ====== | ====== Getting started with Data Generation ====== | ||
- | Data Generation is a new module of the Fabric API, it allows you to dynamically | + | Data Generation is a module of Fabric API which allows you to programmatically |
+ | |||
+ | ===== Enabling Data Generation ===== | ||
- | To implement | + | The recommended way to enable the data generation |
- | <code groovy> | + | {{https://i.imgur.com/NjIARzL.png}} |
- | loom { | + | |
- | runs { | + | |
- | | + | |
- | datagenClient { | + | |
- | inherit client | + | |
- | name "Data Generation" | + | |
- | vmArg " | + | |
- | vmArg " | + | |
- | vmArg " | + | |
- | runDir "build/datagen" | + | Doing so would' |
- | } | + | |
- | | + | ===== Manually Enabling Data Generation ===== |
+ | |||
+ | First open up your '' | ||
+ | |||
+ | <code groovy build.gradle [highlight_lines_extra="5, | ||
+ | |||
+ | // | ||
+ | // ... (The rest of the file) | ||
+ | // | ||
+ | |||
+ | fabricApi { | ||
+ | | ||
} | } | ||
+ | </ | ||
- | // Add the datagenned files into the jar. | + | If you're using version 1.21.4 or above, please replace |
- | sourceSets | + | |
- | | + | <code groovy> |
- | | + | fabricApi |
- | srcDirs += [ | + | |
- | ' | + | |
- | ] | + | |
- | } | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | Next, create | + | Next we'll define |
+ | |||
+ | * The '' | ||
+ | |||
+ | <code java ExampleModDataGenerator.java> | ||
+ | import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | ||
+ | import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | ||
+ | |||
+ | public class ExampleModDataGenerator implements DataGeneratorEntrypoint { | ||
- | <code java> | ||
- | public class MyModDatagen implements DataGeneratorEntrypoint { | ||
@Override | @Override | ||
- | public void onInitializeDataGenerator(FabricDataGenerator | + | public void onInitializeDataGenerator(FabricDataGenerator |
- | // ... | + | FabricDataGenerator.Pack pack = generator.createPack(); |
+ | |||
+ | // Adding a provider example: | ||
+ | // | ||
+ | // pack.addProvider(AdvancementsProvider:: | ||
} | } | ||
+ | |||
} | } | ||
</ | </ | ||
- | This will register your datagen entrypoint, allowing '' | + | Now we need to tell fabric about this entry point in our '' |
+ | |||
+ | <code javascript fabric.mod.json [highlight_lines_extra=" | ||
+ | { | ||
+ | |||
+ | // ... (The rest of the file) | ||
- | <code javascript> | + | |
- | " | + | |
" | " | ||
- | | + | |
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
] | ] | ||
+ | }, | ||
+ | |||
+ | // ... (The rest of the file) | ||
+ | |||
} | } | ||
</ | </ | ||
+ | |||
+ | Before continuing further let's see if what we have so far is working, or if we have any errors. Run the '' | ||
+ | |||
+ | <code batch Windows> | ||
+ | gradlew runDatagen | ||
+ | </ | ||
+ | |||
+ | <code bash Linux> | ||
+ | ./gradlew runDatagen | ||
+ | </ | ||
+ | |||
+ | Read the output and make sure there are no errors. | ||
+ | |||
+ | * You can safely ignore: '' | ||
+ | |||
+ | If you do get an error, it's usually pretty explicit about what's missing or wrong, but if you can't seem to figure it out, you might want to head over to the discord, and get some help. | ||
+ | |||
+ | There should be a new folder in '' | ||
+ | |||
====== Adding Providers ====== | ====== Adding Providers ====== | ||
- | This is a generic guide on how to add a provider, for more in depth infomation | + | This is a generic guide on how to add a provider, for more in depth information |
* [[tutorial: | * [[tutorial: | ||
Line 67: | Line 114: | ||
In this example, we will be creating a tag provider, as it is the simplest to understand. | In this example, we will be creating a tag provider, as it is the simplest to understand. | ||
- | Firstly, inside your '' | + | Firstly, inside your '' |
- | //If you want, you can place this class in a seperate | + | //If you want, you can place this class in a separate |
<code java> | <code java> | ||
- | private static class MyTagGenerator extends FabricTagProvider< | + | import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; |
- | public MyTagGenerator(FabricDataGenerator dataGenerator) { | + | import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; |
- | super(dataGenerator, Registry.ITEM); | + | import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; |
+ | import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; | ||
+ | import net.minecraft.item.Item; | ||
+ | import net.minecraft.item.Items; | ||
+ | import net.minecraft.registry.RegistryKeys; | ||
+ | import net.minecraft.registry.RegistryWrapper; | ||
+ | import net.minecraft.registry.tag.ItemTags; | ||
+ | import net.minecraft.registry.tag.TagKey; | ||
+ | import net.minecraft.util.Identifier; | ||
+ | import java.util.concurrent.CompletableFuture; | ||
+ | |||
+ | public class ExampleModDataGenerator implements DataGeneratorEntrypoint { | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeDataGenerator(FabricDataGenerator generator) { | ||
+ | FabricDataGenerator.Pack pack = generator.createPack(); | ||
+ | |||
+ | pack.addProvider(MyTagGenerator:: | ||
+ | } | ||
+ | |||
+ | | ||
+ | public MyTagGenerator(FabricDataOutput output, CompletableFuture< | ||
+ | super(output, completableFuture); | ||
} | } | ||
@Override | @Override | ||
- | protected void generateTags() { | + | protected void configure(RegistryWrapper.WrapperLookup arg) { |
- | + | ||
} | } | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | We will add some basic tags inside '' | + | We will add some basic tags inside '' |
- | <code java> | + | <code java [highlight_lines_extra="9, |
- | // We will create an item tag called | + | public class ExampleModDataGenerator implements DataGeneratorEntrypoint { |
- | private static final TagKey< | + | |
- | @Override | + | // ... (The rest of the file) |
- | protected void generateTags() { | + | |
- | // This creates a tag builder, where we add slime balls, rotten flesh and everything in the minecraft: | + | |
- | | + | |
- | | + | |
- | .add(Items.ROTTEN_FLESH) | + | |
- | .addOptionalTag(ItemTags.DIRT); | + | |
- | // This will automatically generate " | + | |
- | } | + | |
- | </ | + | |
- | Now, we will need to register this provider to the data generator in the '' | + | private static |
- | <code java> | + | // ... (The rest of the file) |
- | public class MyModDatagen implements DataGeneratorEntrypoint { | + | |
- | @Override | + | private static final TagKey<Item> SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM, |
- | | + | |
- | | + | @Override |
+ | | ||
+ | // This creates a tag builder, where we add slime balls, rotten flesh and everything in the minecraft: | ||
+ | // This will automatically generate " | ||
+ | getOrCreateTagBuilder(SMELLY_ITEMS) | ||
+ | .add(Items.SLIME_BALL) | ||
+ | .add(Items.ROTTEN_FLESH) | ||
+ | .addOptionalTag(ItemTags.DIRT); | ||
+ | } | ||
} | } | ||
} | } | ||
</ | </ | ||
- | When we run '' | + | When we run '' |
<file javascript smelly_items.json> | <file javascript smelly_items.json> |
tutorial/datagen_setup.1661798370.txt.gz · Last modified: 2022/08/29 18:39 by modmuss50