Data generators are a way to programmatically generate the assets and data of mods. It allows the definition of the contents of these files in the code and their automatic generation, without worrying about the specifics.
The data generator system is loaded by the main class
net.minecraft.data.Main. Different command-line arguments can be passed to customize which mods’ data are gathered, what existing files are considered, etc. The class responsible for data generation is
The default configurations in the MDK
build.gradle adds the
runData task for running the data generators.
All references to textures or other data files not generated for data generation must reference existing files on the system. This is to ensure that all referenced textures are in the correct places, so typos can be found and corrected.
ExistingFileHelper is the class responsible for validating the existence of those data files. An instance can be retrieved from
--existing <folderpath> argument allows the specified folder and its subfolders to be used when validating the existence of files. Additionally, the
--existing-mod <modid> argument allows the resources of a loaded mod to be used for validation. By default, only the vanilla datapack and resources are available to the
The data generator can be configured to run 4 different data generations, which are configured from the command-line parameters, and can be checked from
- Client Assets
- Generates client-only files in
assets: block/item models, blockstate JSONs, language files, etc.
- Server Data
- Generates server-only files in
data: recipes, advancements, tags, etc.
- Development Tools
- Runs some development tools: converting SNBT to NBT and vice-versa, etc.
- Dumps all registered blocks, items, commands, etc.
All of the generators can be included using
Data providers are the classes that actually define what data will be generated and provided. All data providers implement
DataProvider. Minecraft has abstract implementations for most assets and data, so modders need only to extend and override the specified method.
GatherDataEvent is fired on the mod event bus when the data generator is being created, and the
DataGenerator can be obtained from the event. Create and register data providers using
net.minecraftforge.common.data.LanguageProvider- for language strings; implement
net.minecraftforge.client.model.generators.ModelProvider<?>- for models; implement
ItemModelProvider- for item models
BlockModelProvider- for block models
net.minecraftforge.client.model.generators.BlockStateProvider- for blockstate JSONs and their block and item models; implement
These classes are under the
GlobalLootModifierProvider- for global loot modifiers; implement
DatapackBuiltinEntriesProviderfor datapack registry objects; pass in
RegistrySetBuilderto the constructor
These classes are under the
loot.LootTableProvider- for loot tables; pass in
LootTableProvider$SubProviderEntrys to the constructor
recipes.RecipeProvider- for recipes and their unlocking advancements; implement
tags.TagsProvider- for tags; implement
advancements.AdvancementProvider- for advancements; pass in
AdvancementSubProviders to the constructor