Changes

3,521 bytes added ,  10:50, 25 October 2020
Intial Import dokuwiki
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 <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 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.
* <code>Client Assets</code>
** Generates client-only files in <code>assets</code>: <code>block</code>/<code>item</code> models, <code>blockstate JSON</code>s, language files, etc.
** <code><nowiki>--client</nowiki></code>, <code><nowiki>includeClient()</nowiki></code>
* <code>Server Data</code>
** Generates server-only files in <code>data</code>: <code>recipes</code>, <code>advancements</code>, <code>tags</code>, etc.
** <code><nowiki>--server</nowiki></code>, <code><nowiki>includeServer()</nowiki></code>
* <code>Development Tools</code>
** Runs some development tools: converting SNBT to NBT and vice-versa, etc.
** <code><nowiki>--dev</nowiki></code>, <code>includeDev()</code>
* <code>Reports</code>
** Dumps all registered blocks, items, commands, etc.
** <code><nowiki>--reports</nowiki></code>, <code>includeReports()</code>

== Data Providers ==
Data providers are the classes that actually define what data will be generated and provided. All data providers implement <code>IDataProvider</code>. Minecraft has abstract implementations for most assets and data, so modders need only to extend 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>

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