====== Tag Generation ====== The ''[[https://github.com/FabricMC/fabric/blob/1.19.2/fabric-data-generation-api-v1/src/main/java/net/fabricmc/fabric/api/datagen/v1/provider/FabricTagProvider.java|FabricTagProvider]]'' class allows you to generate tag json files. This page will follow you through all aspects of this provider. To create a tag generator, create a class that extends ''FabricTagProvider'', where ''T'' is the type of tag you want to generate, and register it at your datagen entrypoint like so: private static class MyTagGenerator extends ItemTagProvider { public MyTagGenerator(FabricDataOutput output, CompletableFuture completableFuture) { super(output, completableFuture); } @Override protected void configure(WrapperLookup arg) { } } // ... @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { // ... fabricDataGenerator.addProvider(MyTagGenerator::new); // ... } The ''FabricTagProvider'' class supports all supported tags, make sure to change the ''Registry'' in the constructor to the type you are generating your tags for. ===== Adding a tag ===== To add a tag, simply call the ''getOrCreateTagBuilder'' method with your supplied ''TagKey'' in the ''configure(WrapperLookup arg)'' method like so: private static final TagKey SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM_KEY, new Identifier("mymod:smelly_items")); @Override protected void configure(WrapperLookup arg) { // This creates a tag builder, where we add slime balls, rotten flesh and everything in the minecraft:dirt item tag. getOrCreateTagBuilder(SMELLY_ITEMS) .add(Items.SLIME_BALL) .add(Items.ROTTEN_FLESH) .addOptionalTag(ItemTags.DIRT); // This will automatically generate "assets/mymod/tags/items/smelly_items.json" in the "generated" folder. } Output from the example above: { "replace": false, "values": [ "minecraft:slime_ball", "minecraft:rotten_flesh", { "id": "#minecraft:dirt", "required": false } ] } ===== Adding stuff to the builder ===== To add an item to your tag builder, simply call ''add(Item item)''. If you want to add a tag to your builder, make sure to call ''addOptionalTag(TagKey tag)'', as the tag's contents may not be loaded during data generation. If you are certain the tag is loaded, call ''addTag(TagKey tag)'' Various overloads exist for ''addTag'', ''addOptionalTag'' and ''addItem'' that accepts ''Identifier''s, ''String''s and ''RegistryKey''s If you want to forcefully add a tag, ignoring the broken format, you can use ''forceAddTag(TagKey tag)'' Finally, if you want your tag to replace pre-existing tags, you can use ''setReplace(boolean replace)'' An example that uses all of these methods can be found here: private static final TagKey SMELLY_ITEMS = TagKey.of(RegistryKeys.ITEM_KEY, new Identifier("mymod:smelly_items")); @Override protected void configure(WrapperLookup arg) { getOrCreateTagBuilder(SMELLY_ITEMS) .add(Items.SLIME_BALL) .add(Items.ROTTEN_FLESH) .addOptionalTag(ItemTags.DIRT) .add(new Identifier("minecraft", "wooden_planks")) .forceAddTag(ItemTags.BANNERS) .setReplace(true) .add(Items.ROTTEN_FLESH.getRegistryEntry().registryKey()); }