🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21
This page is written for version:
1.21
PREREQUISITES
Make sure you've completed the datagen setup process first.
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 principal applies for other things. Let your IDE fill in the required code, then replace the registryKey
constructor parameter with the RegistryKey
for your type:
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) {
}
}
NOTE
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.
pack.addProvider(FabricDocsReferenceItemTagProvider::new);
Now that you've created a provider, let's add a tag to it. First, create a TagKey<T>
:
public static final TagKey<Item> SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "smelly_items"));
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
.
getOrCreateTagBuilder(SMELLY_ITEMS)
.add(Items.SLIME_BALL)
.add(Items.ROTTEN_FLESH)
.addOptionalTag(ItemTags.DIRT)
.add(Identifier.ofVanilla("oak_planks"))
.forceAddTag(ItemTags.BANNERS)
.setReplace(true);