After the previous tutorial your blocks render correctly in-game, but breaking them drops nothing. That is because Minecraft requires a loot table for each block to know what items to drop. In this tutorial we generate those loot tables automatically using the same datagen setup we already have.
gatherData method.Block Loot Provider
In your NeoForge data package, create a class called ExampleBlockLootTableProvider extending BlockLootSubProvider:
The generate() method is where you define what each block drops. Right now we just call dropSelf so the block drops itself when broken with the correct tool.
getKnownBlocks() tells the generator which blocks this provider is responsible for. Using BlockRegistry.BLOCKS.getEntries() means every block you register will automatically be validated. If you forget to add a loot table for a block, datagen will throw an error rather than silently producing an incomplete jar.
Registering the Provider
Open your NeoForge mod class and update the gatherData method to also accept the loot registries parameter and register the new provider. The updated method looks like this:
The key difference from before is the additional HolderLookup.Provider registries argument obtained from the event, which the loot provider needs to resolve data pack objects.
dropSelf (or other) calls inside generate(). Common helpers include:dropSelf(block): drops the block itselfcreateOreDrop(block, item): drops an ore's yield, affected by FortunecreateSlabItemTable(block): correctly doubles the drop count for slabs
Running Datagen
Run the NeoForge Data configuration. After it finishes, check the common/src/generated/resources/data/examplemod/loot_table/blocks/ folder. You should see a new_dirt.json file that looks like this:
Testing In-Game
Launch the client and place a New Dirt block in survival mode. Break it; it should now drop itself. Try breaking it with a Silk Touch pickaxe to confirm the survives_explosion condition does not affect normal drops.
data/examplemod/loot_table/blocks/ (note: loot_table, not loot_tables). The path changed in 1.21.You can find the source for this tutorial here:
View Source on GitHubData Generation: Crafting Recipes (MultiLoader 1.21+)
Create a RecipeProvider to generate shaped crafting recipes, shapeless recipes, and smelting and blasting recipes via datagen, hooking everything into GatherDataEvent alongside your existing providers.
Continue →