tutorial:datagen_setup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:datagen_setup [2022/12/22 11:43] – jmanc3 | tutorial:datagen_setup [2024/01/22 22:46] – arkosammy12 | ||
---|---|---|---|
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 ===== | ||
- | First we'll add a new gradle task which will take the code we write to generate data and spit out files Minecraft can read. Every time you modify the code that //generates// advancements (or anything else datagen can make like loot tables and such) you'll have to run the gradle task '' | + | The recommended way to enable |
- | <code groovy> | + | {{https:// |
- | // ... (The rest of the file) | + | Doing so would' |
- | loom { | + | ===== Manually Enabling |
- | runs { | + | |
- | // | + | |
- | // This adds a new gradle task that runs the datagen API: " | + | |
- | // | + | |
- | datagenClient { | + | |
- | inherit client | + | |
- | name "Data Generation" | + | |
- | vmArg " | + | |
- | vmArg " | + | |
- | vmArg " | + | |
- | runDir "build/ | + | First open up your '' |
- | } | + | |
- | } | + | <code groovy build.gradle [highlight_lines_extra=" |
- | } | + | |
// | // | ||
- | // Adds the generated files into the jar you distribute to players. | + | // ... (The rest of the file) |
// | // | ||
+ | |||
sourceSets { | sourceSets { | ||
main { | main { | ||
Line 40: | Line 32: | ||
</ | </ | ||
- | You'll notice it makes use of the variable | + | Next find the '' |
- | <code properties> | + | < |
+ | |||
+ | // | ||
+ | // ... (The rest of the file) | ||
+ | // | ||
+ | |||
+ | loom { | ||
+ | |||
+ | // ... (Whatever exists here) | ||
+ | |||
+ | runs { | ||
+ | // This adds a new gradle task that runs the datagen API: " | ||
+ | datagen { | ||
+ | inherit server | ||
+ | name "Data Generation" | ||
+ | vmArg " | ||
+ | vmArg " | ||
+ | vmArg " | ||
+ | |||
+ | runDir " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // ... (The rest of the file) | ||
+ | |||
+ | </ | ||
+ | |||
+ | * NOTE: You may have to change the line '' | ||
+ | |||
+ | You'll notice the code we just added to the '' | ||
+ | |||
+ | <code properties gradle.properties> | ||
// .. (The rest of the file) | // .. (The rest of the file) | ||
Line 50: | Line 74: | ||
</ | </ | ||
- | Next we'll define a new class in our project '' | + | Next we'll define a new class in our project '' |
- | * The '' | + | * The '' |
- | <code java> | + | < |
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | ||
- | public class DataGeneration | + | public class ExampleModDataGenerator |
@Override | @Override | ||
- | public void onInitializeDataGenerator(FabricDataGenerator | + | public void onInitializeDataGenerator(FabricDataGenerator |
+ | FabricDataGenerator.Pack pack = generator.createPack(); | ||
+ | // Adding a provider example: | ||
+ | // | ||
+ | // pack.addProvider(AdvancementsProvider:: | ||
} | } | ||
+ | |||
} | } | ||
</ | </ | ||
- | Now we need to tell fabric about this entry point in our '' | + | Now we need to tell fabric about this entry point in our '' |
- | <code javascript [highlight_lines_extra=" | + | <code javascript |
{ | { | ||
Line 76: | Line 105: | ||
" | " | ||
" | " | ||
- | "DataGeneration" | + | "com.example.ExampleModDataGenerator" |
], | ], | ||
" | " | ||
- | "AdvancementsTutorial" | + | "com.example.ExampleMod" |
], | ], | ||
" | " | ||
- | "AdvancementsTutorialClient" | + | "com.example.ExampleModClient" |
] | ] | ||
}, | }, | ||
Line 91: | Line 120: | ||
</ | </ | ||
- | Before continuing further let's see if what we have so far is working, or if we have any errors. Run the '' | + | Before continuing further let's see if what we have so far is working, or if we have any errors. Run the '' |
- | <code bash> | + | <code batch Windows> |
- | ./ | + | gradlew runDatagen |
+ | </ | ||
+ | |||
+ | <code bash Linux> | ||
+ | ./ | ||
</ | </ | ||
Read the output and make sure there are no errors. | Read the output and make sure there are no errors. | ||
- | * You can safely ignore: '' | + | * 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. | 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 '' | + | There should be a new folder in '' |
+ | |||
+ | ==== IDE Integration (Optional) ==== | ||
+ | |||
+ | Because we don't want to be opening the terminal all the time, we can setup a configuration in '' | ||
+ | |||
+ | First open the '' | ||
+ | |||
+ | Next click the '' | ||
+ | |||
+ | Inside the '' | ||
====== Adding Providers ====== | ====== Adding Providers ====== | ||
Line 118: | Line 161: | ||
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 file, but we recommend it stays in your datagen entrypoint class.// | //If you want, you can place this class in a seperate file, but we recommend it stays in your datagen entrypoint class.// | ||
<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, Registries.ITEM); // for versions 1.19.2 and below, use 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,15,16,17,18"]> |
- | // 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 DataGeneration 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.txt · Last modified: 2024/03/15 05:06 by shnupbups