Wiki 9Minecraft Datapack Anvil Wiki

Tags

With Datapack Anvil you can add tags on data managed by IDataManager.
We will use the data manager defined in Data Manager for our example.

Data Tag Registry

Once you have created a data manager, if you want to use tags you will need to create a DataTagRegistry, simply use the default constructor and store it in a static field:

public static final DataTagRegistry<MayData> MY_DATA_TAGS = new DataTagRegistry<>();

(I recommend putting your DataTagRegistry in your mod tag class).

then you will simply need to send an IMC to pair the DataTagRegistry with its data manager:

DataTagIMC.enqueue(() -> new DataTagIMC<>(MY_DATA_MANAGER, MyTags.MyData.MY_DATA_TAGS));

Wrapper tags

DataTagRegistry offers a makeWrapperTag method that works the same way as BlockTags.makeWrapperTag and ItemTags.makeWrapperTag:

public static final INamedTag<MyData> MY_DATA_TAG1 = MY_DATA_TAGS.createWrapperTag(new ResourceLocation("mymod", "mydata_tag1"));

Note: In contrary of vanilla tags dp anvil wrapper tags are optional by default meaning that using them if absent or uninitialized will work like using an empty tag.

Datagen

Since vanilla TagsProvider is bound to a Registry you cannot use those for datagen of dpanvil tags. To do so you have to use an AbstractDataTagsProvider that works the same way, in our example it will look like this:

public class MyDataTagsProvider extends AbstractDataTagsProvider<MyData> {

	public MyDataTagsProvider(DataGenerator generatorIn, ExistingFileHelper existingFileHelper) {
		super(generatorIn, MyMod.MY_DATA_MANAGER, "mymod", existingFileHelper);
	}

	@Override
	protected void registerTags() {
		getOrCreateBuilder(MyTags.MyData.MY_DATA_TAG1).add(new ResourceLocation("mymod", "mydata1"), new ResourceLocation("mymod", "mydata2"));
	}
	
	@Override
	public String getName() {
		return "My mod, my data tags";
	}
}

Note: these tags will be stored in the dpanvil_tags folder instead of the traditional tags folder.