Datageneration

From Forge Community Wiki
Revision as of 10:50, 25 October 2020 by Unbekannt (talk | contribs) (Intial Import dokuwiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 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 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
    • Generates server-only files in data: recipes, advancements, tags, etc.
    • --server, includeServer()
  • 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 actually define what data will be generated and provided. All data providers implement IDataProvider. Minecraft has abstract implementations for most assets and data, so modders need only to extend 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 package
      • ItemModelProvider - for item models; override #registerModels
      • BlockStateProvider - for blockstates and their block and item models; override #registerStatesAndModels
      • BlockModelProvider - for block models; override #registerModels

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

Tip

An AdvancementProvider class does exists, however it is hardcoded for only the vanilla advancements.