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 [2023/06/16 18:20] – Update to ItemTagProvider slainlight | 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 ===== | ||
- | 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 { | + | |
- | | + | fabricApi |
- | resources { | + | |
- | srcDirs += [ | + | |
- | ' | + | |
- | ] | + | |
- | } | + | |
- | | + | |
} | } | ||
</ | </ | ||
- | You'll notice it makes use of the variable | + | If you're using version 1.21.4 or above, please replace |
- | < | + | < |
- | // .. (The rest of the file) | + | fabricApi { |
- | + | configureDataGeneration() { | |
- | modid=the-name-of-your-mod-change-me-please | + | |
- | + | } | |
- | // .. (The rest of the file) | + | } |
</ | </ | ||
- | 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 |
- | // This is where providers are added | + | 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 67: | ||
" | " | ||
" | " | ||
- | "DataGeneration" | + | "com.example.ExampleModDataGenerator" |
], | ], | ||
" | " | ||
- | "AdvancementsTutorial" | + | "com.example.ExampleMod" |
], | ], | ||
" | " | ||
- | "AdvancementsTutorialClient" | + | "com.example.ExampleModClient" |
] | ] | ||
}, | }, | ||
Line 91: | Line 82: | ||
</ | </ | ||
- | 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 '' |
====== Adding Providers ====== | ====== Adding Providers ====== | ||
Line 118: | 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.ItemTagProvider { | + | import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; |
- | public | + | import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; |
+ | 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 | ||
super(output, | super(output, | ||
} | } | ||
- | | + | |
@Override | @Override | ||
protected void configure(RegistryWrapper.WrapperLookup arg) { | 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 configure(WrapperLookup arg) { | + | |
- | // 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 |
- | pack.addProvider(MyTagGenerator:: | + | |
+ | // 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.1686939600.txt.gz · Last modified: 2023/06/16 18:20 by slainlight