Views
Actions
Datageneration/1.17
Data generation (AKA datagen) is a builtin system in Minecraft and Forge that allows mod developers to write code to programmatically generate the assets and data files of mods.
Using datageneration offers some notable benefits:
- Asset and data files can be automatically generated by code without needing to manually type them out, saving effort and time.
- The structure of the datagenerated files may be changed without affecting the code which generates them, allowing for files to be cleanly regenerated when the format is changed.
- Mod developers can mix and match datagenerated resources with pre-existing or manually-made resources.
- Similar and repeated assets and data files can be programmatically generated for any number of objects, with the least amount of effort needed to define in code.
The data generation 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 managing and orchestrating data generation is net.minecraft.data.DataGenerator
.
The default configurations in the MDK build.gradle
adds the runData
task for running the data generators.
Generator Modes
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 GatherDataEvent#include()
methods.
- Client Assets
- Generates client-only files in assets: block/item models, blockstate JSONs, language files, etc.
--client
,includeClient()
- Server Data
- Development Tools
- Runs some development tools: converting SNBT to NBT and vice-versa, etc.
--dev
,includeDev()
- Reports
- Dumps all registered blocks, items, commands, etc.
--reports
,includeReports()
Data Providers
Data providers are the classes that define the resources data to be generated. All data providers implement DataProvider
. Minecraft has abstract implementations for most assets and data, so mod developers only need to extend those abstract classes and override the specified method.
The 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 DataGenerator#addProvider
.
Client Assets
net.minecraftforge.common.data.LanguageProvider
- for language strings; override#addTranslations
ModelProvider<?>
- base class for all model providers- These classes are under the
net.minecraftforge.client.model.generators
packageItemModelProvider
- for item models; override#registerModels
BlockStateProvider
- for blockstates and their block and item models; override#registerStatesAndModels
BlockModelProvider
- for block models; override#registerModels
- These classes are under the
SoundDefinitionsProvider
- for thesounds.json
file; override#registerSounds
Server Data
- These classes are under the
net.minecraft.data
package LootTableProvider
- for loot tables; override#getTables
RecipeProvider
- for recipes and their unlocking advancements; override#buildCraftingRecipes
TagsProvider
- for tags; override#addTags
GlobalLootModifierProvider
- for global loot modifiers; override#start
AdvancementProvider
- for advancements; override#registerAdvancements