Views
Actions
Difference between revisions of "Datageneration"
(Categorize with Category:Data Generation by SizableShrimp#0755) |
(Update to 1.17) |
||
Line 27: | Line 27: | ||
== Data Providers == | == Data Providers == | ||
− | '''Data providers''' are the classes that define the resources data to be generated. All data providers implement <code> | + | '''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>. | 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>. | ||
Line 38: | Line 38: | ||
*** <code>BlockStateProvider</code> - for blockstates and their block and item models; override <code>#registerStatesAndModels</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>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 === | === Server Data === | ||
Line 44: | Line 45: | ||
* <code>RecipeProvider</code> - for recipes and their unlocking advancements; override <code>#registerRecipes</code> | * <code>RecipeProvider</code> - for recipes and their unlocking advancements; override <code>#registerRecipes</code> | ||
* <code>TagsProvider</code> - for tags; override <code>#registerTags</code> | * <code>TagsProvider</code> - for tags; override <code>#registerTags</code> | ||
+ | * <code>GlobalLootModifierProvider</code> - for global loot modifiers; override <code>#start</code> | ||
{{Tip|An <code>AdvancementProvider</code> class does exists, however it is hardcoded for only the vanilla advancements.}} | {{Tip|An <code>AdvancementProvider</code> class does exists, however it is hardcoded for only the vanilla advancements.}} |
Revision as of 22:53, 31 July 2021
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#registerRecipes
TagsProvider
- for tags; override#registerTags
GlobalLootModifierProvider
- for global loot modifiers; override#start
AdvancementProvider
class does exists, however it is hardcoded for only the vanilla advancements.