How to make an item tag in a Minecraft mod
A tag is a named list of items (or blocks, entities…) in data/<mod>/tags/item/<name>.json (tags/items before 1.21), which any data pack can add to. In code it is a TagKey, TagKey.create(Registries.ITEM, id) (ItemTags.bind on 1.16.5), and stack.is(tag) asks whether an item is in it. Recipes and loot tables name it as #<mod>:<name>.
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Make the tag file in data/<mod>/tags/item/<name>.json (tags/items before 1.21) with a values list.
- Make a TagKey for it with TagKey.create(Registries.ITEM, id).
- Test items with stack.is(YourTags.NAME).
What you can change
Section titled “What you can change”The example uses these values. Change them in the code.
| Setting | In the example | What it does |
|---|---|---|
| item | minecraft:diamond |
An item the tag starts with. |
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric and Forge 1.20.1
Section titled “Fabric and Forge 1.20.1”Uses:
TagKey.createRegistries.ITEMItemStack.is
In 1.20.1 the tag folder is tags/items (plural); from 1.21 it is tags/item.
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registries.ITEM, new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric and NeoForge 1.20.2 to 1.20.6, NeoForge 1.20.1, Fabric 1.19.3 to 1.20
Section titled “Fabric and NeoForge 1.20.2 to 1.20.6, NeoForge 1.20.1, Fabric 1.19.3 to 1.20”Uses:
TagKey.createRegistries.ITEMItemStack.is
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registries.ITEM, new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric and NeoForge 1.21 to 1.21.1, Fabric and NeoForge 1.21.2 to 1.21.10
Section titled “Fabric and NeoForge 1.21 to 1.21.1, Fabric and NeoForge 1.21.2 to 1.21.10”Uses:
TagKey.createRegistries.ITEMItemStack.is
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/item/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/item/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric and NeoForge 1.21.11 to 26.3
Section titled “Fabric and NeoForge 1.21.11 to 26.3”Uses:
TagKey.createRegistries.ITEMItemStack.isIdentifier.fromNamespaceAndPath
Since 1.21.11 ResourceLocation is called Identifier (net.minecraft.resources.Identifier).
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.Identifier;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/item/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/item/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric 1.18.2 to 1.19.2
Section titled “Fabric 1.18.2 to 1.19.2”Uses:
TagKey.createRegistries.ITEMItemStack.is
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.Registry;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric 1.18 to 1.18.1
Section titled “Fabric 1.18 to 1.18.1”Uses:
TagKey.createRegistries.ITEMItemStack.is
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.fabricmc.fabric.api.tag.TagFactory;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.Tag;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final Tag.Named<Item> GEMS = TagFactory.ITEM.create(new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Fabric 1.16.5 to 1.17.1
Section titled “Fabric 1.16.5 to 1.17.1”Uses:
TagKey.createRegistries.ITEMItemStack.is
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.fabricmc.fabric.api.tag.TagRegistry;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.Tag;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final Tag<Item> GEMS = TagRegistry.item(new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
ItemTags.bindITag.INamedTagItem.is
In 1.16.5 the tag folder is tags/items (plural); tags are made with ItemTags.bind(name) and read with item.is(tag).
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.item.Item;import net.minecraft.tags.ITag;import net.minecraft.tags.ItemTags;import net.minecraft.util.ResourceLocation;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.getItem().is(ModTags.NAME).public final class ModTags { public static final ITag.INamedTag<Item> GEMS = ItemTags.bind(new ResourceLocation(ExampleMod.MOD_ID, "gems").toString());
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Forge 1.17.1
Section titled “Forge 1.17.1”Uses:
TagKey.createRegistry.ITEM_REGISTRYItemStack.is
On 1.17.1 the tag folder is tags/items (plural); from 1.21 it is tags/item.
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.tags.ItemTags;import net.minecraft.tags.Tag;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final Tag.Named<Item> GEMS = ItemTags.bind(ExampleMod.MOD_ID + ":gems");
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Forge 1.18.2 to 1.19.2
Section titled “Forge 1.18.2 to 1.19.2”Uses:
TagKey.createRegistry.ITEM_REGISTRYItemStack.is
In 1.19.2 the tag folder is tags/items (plural); from 1.21 it is tags/item.
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.Registry;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Forge 1.19.3 to 1.20
Section titled “Forge 1.19.3 to 1.20”Uses:
TagKey.createRegistries.ITEMItemStack.is
In 1.19.3 the tag folder is tags/items (plural); from 1.21 it is tags/item.
src/main/java/com/example/examplemod/registry/ModTags.java
package com.example.examplemod.registry;
import com.example.examplemod.ExampleMod;import net.minecraft.core.registries.Registries;import net.minecraft.resources.ResourceLocation;import net.minecraft.tags.TagKey;import net.minecraft.world.item.Item;
// The mod's tags: data/examplemod/tags/items/<name>.json lists what is in each; test an item with stack.is(ModTags.NAME).public final class ModTags { public static final TagKey<Item> GEMS = TagKey.create(Registries.ITEM, new ResourceLocation(ExampleMod.MOD_ID, "gems"));
private ModTags() { }}In src/main/resources/data/examplemod/tags/items/gems.json, add this to the list at /values:
"minecraft:diamond"Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/data-generation/tags
- https://docs.neoforged.net/docs/1.21.1/resources/server/tags
Related how-tos
Section titled “Related how-tos”In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.