So far the English language file for our mod has been hand-written JSON. Like models and blockstates, translation keys can be generated automatically using datagen. Switching to a LanguageProvider gives you type-safe references to your registered objects rather than hand-coded string keys, which makes it easy to stay in sync as your registry grows.
gatherClientData listener.Language Provider
In your NeoForge data package, create a class called ExampleLanguageProvider extending LanguageProvider:
The constructor passes your mod ID and the locale code ("en_us") to the parent. To support additional languages, create a second subclass with a different locale string and register it the same way.
add(Block, String) and add(Item, String) automatically derive the correct translation key from the registry object, so you never have to write "block.examplemod.new_dirt" by hand. For keys that have no typed helper, such as creative tab titles, use the raw add(String key, String value) overload.
LanguageProvider source for the full list. If a registry object does not have a dedicated overload, fall back to add(registryObject.get().getDescriptionId(), "Name").Registering the Provider
Language files are client-side assets, so the provider goes into the gatherClientData listener alongside the model provider:
Because ExampleLanguageProvider has a single-argument constructor that takes PackOutput, it can be passed as a constructor reference directly. For providers whose constructors take additional arguments, use a lambda as shown for the model provider.
Running Datagen
Before running, delete the hand-written src/main/resources/assets/examplemod/lang/en_us.json from the common project so the generated file does not conflict with it. Then run the NeoForge Data configuration. Afterwards you will find:
assets/examplemod/lang/en_us.jsoninside the generated resources folder
item.examplemod.new_dirt and block.examplemod.new_dirt when you call add(Block, String). Both keys are needed because the block and its item each have their own description ID.You can find the source for this tutorial here:
View Source on GitHubData Generation: Advancements (MultiLoader 26.1+)
Build a small advancement tree using AdvancementProvider and AdvancementSubProvider, define a root node and a child advancement with InventoryChangeTrigger criteria, and generate the JSON via datagen.
Continue →