'''Data generation''' (AKA '''datagen''') is a builtin system in Minecraft and Forge that allows mod developers to write code to programmatically generate the [[Using Resources/1.17|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 <code>net.minecraft.data.Main</code>. 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 <code>net.minecraft.data.DataGenerator</code>.
The default configurations in the MDK <code>build.gradle</code> adds the <code>runData</code> 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 <code><nowiki>GatherDataEvent#include()</nowiki></code> methods.
* '''Client Assets'''
** Generates client-only files in <tt>assets</tt>: [[Introduction to Models/1.17|block/item models]], [[BlockState JSONs/1.17|blockstate JSONs]], [[Datageneration/I18n/1.17|language files]], etc.
** <code><nowiki>--client</nowiki></code>, <code><nowiki>includeClient()</nowiki></code>
* '''Server Data'''
** Generates server-only files in <tt>data</tt>: [[Datageneration/Recipes/1.17|recipes]], advancements, [[Datageneration/Tags/1.17|tags]], etc.
** <code><nowiki>--server</nowiki></code>, <code><nowiki>includeServer()</nowiki></code>
* '''Development Tools'''
** Runs some development tools: converting SNBT to NBT and vice-versa, etc.
** <code><nowiki>--dev</nowiki></code>, <code>includeDev()</code>
* '''Reports'''
** Dumps all registered blocks, items, commands, etc.
** <code><nowiki>--reports</nowiki></code>, <code>includeReports()</code>
== Data Providers ==
'''Data providers''' are the classes that define the resources data to be generated. All data providers implement <code>DataProvider</code>. 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 <code>GatherDataEvent</code> is fired on the mod event bus when the data generator is being created, and the <code>DataGenerator</code> can be obtained from the event. Create and register data providers using <code><nowiki>DataGenerator#addProvider</nowiki></code>.
=== Client Assets ===
* <code>net.minecraftforge.common.data.LanguageProvider</code> - for language strings; override <code><nowiki>#addTranslations</nowiki></code>
* <code><nowiki>ModelProvider<?></nowiki></code> - base class for all model providers
** ''These classes are under the <code>net.minecraftforge.client.model.generators</code> package''
*** <code>ItemModelProvider</code> - for item models; override <code>#registerModels</code>
*** <code>BlockStateProvider</code> - for blockstates and their block and item models; override <code>#registerStatesAndModels</code>
*** <code>BlockModelProvider</code> - for block models; override <code>#registerModels</code>
* <code>SoundDefinitionsProvider</code> - for the <code>sounds.json</code> file; override <code>#registerSounds</code>
=== Server Data ===
* ''These classes are under the <code>net.minecraft.data</code> package''
* <code>LootTableProvider</code> - for loot tables; override <code>#getTables</code>
* <code>RecipeProvider</code> - for recipes and their unlocking advancements; override <code>#buildCraftingRecipes</code>
* <code>TagsProvider</code> - for tags; override <code>#addTags</code>
* <code>GlobalLootModifierProvider</code> - for global loot modifiers; override <code>#start</code>
* <code>AdvancementProvider</code> - for advancements; override <code>#registerAdvancements</code>