PREREQUISITES
Make sure you've completed the datagen setup process first.
Setup
First, create your own class that extends FabricTagProvider<T>, where T is the type of thing you'd like to provide a tag for. This is your provider. Here we'll show how to create Item tags, but the same principle applies for other things. Let your IDE fill in the required code, then replace the registryKey constructor parameter with the RegistryKey for your type:
java
public class FabricDocsReferenceItemTagProvider extends FabricTagProvider<Item> {
public FabricDocsReferenceItemTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
super(output, RegistryKeys.ITEM, registriesFuture);
}
@Override
protected void configure(RegistryWrapper.WrapperLookup wrapperLookup) {
}
}1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
TIP
You will need a different provider for each type of tag (eg. one FabricTagProvider<EntityType<?>> and one FabricTagProvider<Item>).
To finish setup, add this provider to your DataGeneratorEntrypoint within the onInitializeDataGenerator method.
java
pack.addProvider(FabricDocsReferenceItemTagProvider::new);1
Creating a Tag
Now that you've created a provider, let's add a tag to it. First, create a TagKey<T>:
java
public static final TagKey<Item> SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "smelly_items"));1
Next, call getOrCreateTagBuilder inside your provider's configure method. From there, you can add individual items, add other tags, or make this tag replace pre-existing tags.
If you want to add a tag, use addOptionalTag, as the tag's contents may not be loaded during datagen. If you are certain the tag is loaded, call addTag.
To forcefully add a tag and ignore the broken format, use forceAddTag.
java
getOrCreateTagBuilder(SMELLY_ITEMS)
.add(Items.SLIME_BALL)
.add(Items.ROTTEN_FLESH)
.addOptionalTag(ItemTags.DIRT)
.add(Identifier.ofVanilla("oak_planks"))
.forceAddTag(ItemTags.BANNERS)
.setReplace(true);1
2
3
4
5
6
7
2
3
4
5
6
7




