Changes

4,239 bytes added ,  03:58, 27 July 2021
Copy Datageneration to MC1.16 archive
'''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|assets and data/1.16]] 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|block/item models/1.16]], [[BlockState JSONs|blockstate JSONs/1.16]], [[Datageneration/I18n|language files/1.16]], etc.
** <code><nowiki>--client</nowiki></code>, <code><nowiki>includeClient()</nowiki></code>
* '''Server Data'''
** Generates server-only files in <tt>data</tt>: [[Datageneration/Recipes|recipes/1.16]], advancements, [[Datageneration/Tags|tags/1.16]], 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>IDataProvider</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>

=== 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>#registerRecipes</code>
* <code>TagsProvider</code> - for tags; override <code>#registerTags</code>

{{Tip|An <code>AdvancementProvider</code> class does exists, however it is hardcoded for only the vanilla advancements.}}


[[Category:Data Generation/1.16]]
372

edits