• Forums

Navigation

  • Home
  • Contributing to the Docs
  • Getting Started
    • Introduction
    • Structuring Your Mod
    • Versioning
  • Core Concepts
    • Registries
    • Sides
    • Events
    • Mod Lifecycle
    • Resources
    • Internationalization
  • Blocks
    • Introduction
    • Block States
  • Items
    • Introduction
    • BlockEntityWithoutLevelRenderer
  • Networking
    • Introduction
    • SimpleImpl
    • Synchronizing Entities
  • Block Entities
    • Introduction
    • BlockEntityRenderer
  • Game Effects
    • Particles
    • Sounds
  • Data Storage
    • Capabilities
    • Saved Data
    • Codecs
  • Graphical User Interfaces
    • Menus
    • Screens
  • Rendering
    • Model Loaders
      • Introduction
      • Baked Model
      • Transform
      • Item Overrides
  • Resources
    • Client Assets
      • Introduction
      • Models
        • Introduction
        • Texture Tinting
        • Item Properties
    • Server Data
      • Introduction
      • Recipes
        • Introduction
        • Custom Recipes
        • Ingredients
        • Non-Datapack Recipes
      • Loot Tables
      • Global Loot Modifiers
      • Tags
      • Advancements
      • Conditionally-Loaded Data
  • Data Generation
    • Introduction
      • Existing Files
      • Generator Modes
      • Data Providers
    • Client Assets
      • Model Providers
      • Language Providers
      • Sound Providers
    • Server Data
      • Recipe Providers
      • Loot Table Providers
      • Tag Providers
      • Advancement Providers
      • Global Loot Modifier Providers
      • Datapack Registry Object Providers
  • Miscellaneous Features
    • Configuration
    • Key Mappings
    • Game Tests
    • Forge Update Checker
    • Debug Profiler
  • Advanced Topics
    • Access Transformers
  • Contributing to Forge
    • Introduction
    • Pull Request Guidelines
  • Legacy Versions
    • Introduction
    • Porting to This Version

Data Generators

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.

Existing Files

All references to textures or other data files not generated for data generation must reference existing files on the system. This is to ensure that all referenced textures are in the correct places, so typos can be found and corrected.

ExistingFileHelper is the class responsible for validating the existence of those data files. An instance can be retrieved from GatherDataEvent#getExistingFileHelper.

The --existing <folderpath> argument allows the specified folder and its subfolders to be used when validating the existence of files. Additionally, the --existing-mod <modid> argument allows the resources of a loaded mod to be used for validation. By default, only the vanilla datapack and resources are available to the ExistingFileHelper.

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

All of the generators can be included using --all.

Data Providers

Data providers are the classes that actually define what data will be generated and provided. All data providers implement DataProvider. 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; implement #addTranslations
  • net.minecraftforge.common.data.SoundDefinitionsProvider - for sounds.json; implement #registerSounds
  • net.minecraftforge.client.model.generators.ModelProvider<?> - for models; implement #registerModels
    • ItemModelProvider - for item models
    • BlockModelProvider - for block models
  • net.minecraftforge.client.model.generators.BlockStateProvider - for blockstate JSONs and their block and item models; implement #registerStatesAndModels

Server Data

These classes are under the net.minecraftforge.common.data package:

  • GlobalLootModifierProvider - for global loot modifiers; implement #start
  • DatapackBuiltinEntriesProvider for datapack registry objects; pass in RegistrySetBuilder to the constructor

These classes are under the net.minecraft.data package:

  • loot.LootTableProvider - for loot tables; pass in LootTableProvider$SubProviderEntrys to the constructor
  • recipes.RecipeProvider - for recipes and their unlocking advancements; implement #buildRecipes
  • tags.TagsProvider - for tags; implement #addTags
  • advancements.AdvancementProvider - for advancements; pass in AdvancementSubProviders to the constructor
Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme