Skip to content

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.

  1. Make the tag file in data/<mod>/tags/item/<name>.json (tags/items before 1.21) with a values list.
  2. Make a TagKey for it with TagKey.create(Registries.ITEM, id).
  3. Test items with stack.is(YourTags.NAME).

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.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.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.create
  • Registries.ITEM
  • ItemStack.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.create
  • Registries.ITEM
  • ItemStack.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"

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.is
  • Identifier.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"

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.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"

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.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"

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.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"

Uses:

  • ItemTags.bind
  • ITag.INamedTag
  • Item.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"

Uses:

  • TagKey.create
  • Registry.ITEM_REGISTRY
  • ItemStack.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"

Uses:

  • TagKey.create
  • Registry.ITEM_REGISTRY
  • ItemStack.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"

Uses:

  • TagKey.create
  • Registries.ITEM
  • ItemStack.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"

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.