Tags are named sets of blocks, items or other registry objects that game mechanics and recipe ingredients can reference without knowing the exact members. In this tutorial we generate block and item tag files using datagen, add our custom block to the vanilla tool-requirement tags so it can only be harvested correctly, and create a custom mod-scoped item tag for use in recipes.
gatherData method.Why Tags Matter
Without the correct tool tags, your block will drop its item regardless of what the player digs with. Adding BlockTags.MINEABLE_WITH_PICKAXE tells Minecraft that a pickaxe is the correct tool, and adding BlockTags.NEEDS_IRON_TOOL makes it so that only an iron-tier pickaxe or better actually harvests the block. Without that second tag the block is diggable with any pickaxe, even wooden.
Item tags serve a different purpose: they let recipe ingredients match a group of items rather than a single specific one. We will create an examplemod:mod_items tag containing all items from this mod, which can then be used as a recipe ingredient in future tutorials.
Block Tags Provider
In your NeoForge data package, create a class called ExampleBlockTagsProvider extending BlockTagsProvider:
The tag(...).add(...) pattern appends your block to an existing vanilla tag file without replacing its other members. The replace: false flag is written into the JSON automatically, which is what tells the game to merge rather than overwrite.
BlockTags.MINEABLE_WITH_AXE, BlockTags.MINEABLE_WITH_SHOVEL, BlockTags.NEEDS_STONE_TOOL and BlockTags.NEEDS_DIAMOND_TOOL. Pick the tool type and tier that fits your block's material.Item Tags Provider
In the same package, create ExampleItemTagsProvider extending ItemTagsProvider. The item tags provider depends on the block tags provider because it can copy block tags across to matching item tags, so it takes a CompletableFuture<TagLookup<Block>> as a constructor argument:
The modItems tag key declares a new tag under your mod's namespace. You can reference this key anywhere a TagKey<Item> is accepted, for example as an ingredient in a ShapedRecipeBuilder definition.
copy(blockTag, itemTag) inside addTags to mirror a block tag to its item equivalent. This is commonly done for material tags such as Tags.Blocks.STONE so that both the placed block and the item form share the same logical group.Registering the Providers
Open gatherData and add both providers. The block tags provider must be constructed first so its contentsGetter() can be passed to the item tags provider:
Running Datagen
Run the NeoForge Data configuration. Afterwards, check the generated resources folder for two new directories:
data/minecraft/tags/block/mineable/pickaxe.jsonanddata/minecraft/tags/block/needs_iron_tool.jsonshould each containexamplemod:new_dirtin theirvaluesarray.data/examplemod/tags/item/mod_items.jsonshould list bothexamplemod:iron_stickandexamplemod:new_dirt.
Testing In-Game
Launch the client in survival mode and try to break a New Dirt block with your fist and then with a wooden pickaxe. Neither should produce a drop. Switch to an iron pickaxe and break it; the block should drop itself, as expected from the loot table tutorial. This confirms both tool-type and tool-tier tags are working.
data/minecraft/tags/block/ (the vanilla namespace) and not in data/examplemod/tags/block/. Tool requirement tags must be in the minecraft namespace to be recognised by the game.You can find the source for this tutorial here:
View Source on GitHubCustom Food Items (MultiLoader 1.21+)
Build edible items using FoodProperties.Builder, configure nutrition and saturation, apply status effects on eating, and wire up the model and creative tab entries through datagen.
Continue →