Tag Extension API for Fabric has been removed in 1.18.2. Here are some vanilla replacements:
Vanilla ObjectBuilder
contains addOptional
(corresponding to addOptionalObject
in FAPI) and addOptionalTag
. They both return the builder itself, unlike FAPI provided ones that do not have return values. The arguments are the same, all taking one Identifier
.
There is a generic method TagKey#of
which can be used to create TagKey
for any registries (blocks, items, biomes, villager professions, custom registry items, etc). You can also use BlockTags#register
, etc provided you use accessor or access widener to make it public.
One thing to note is that Tag.Identified
has become TagKey
. TagKey
, like RegistryKey
, does not hold the value(s) itself - you have to query the values from the registry. For example, Registry.BLOCK.iterateEntries(tagKey)
will return an iterable of RegistryEntry
. The following code in 1.18.1:
public class Example {
public static final Tag<Block> CONCRETES = TagFactory.BLOCK.create(new Identifier("example:concretes"));
public void listConcretes(Consumer<Identifier> idConsumer) {
CONCRETES.values().forEach(block -> idConsumer.accept(Registry.BLOCK.getId(block)));
}
}
will become:
public class Example {
public static final TagKey<Block> CONCRETES = TagKey.of(Registry.BLOCK_KEY, new Identifier("example:concretes"));
public void listConcretes(Consumer<Identifier> idConsumer) {
// Iterate using for loop
for (RegistryEntry<Block> block : Registry.BLOCK.iterateEntries(COCRETES)) {
// RegistryEntry#getKey returns Optional<RegistryKey>.
block.getKey().map(RegistryKey::getValue).map(idConsumer::accept);
}
}
}
Some notes:
- The aforementioned method of getting entries only works for non-dynamic registry entries (e.g. blocks, items). To get entries for biomes and other data-driven parts, you need to get the registry via
DynamicRegistryManager
(like before), e.g.dynamicRegistryManager.getManaged(Registry.BIOME_KEY).iterateEntries(...)
- Biome tags were previously located under
tags/biomes
when using Fabric API. Vanilla loads the tags fromtags/worldgen/biome
(singular).
These do not currently have vanilla replacements, however I could not find the code usage for them:
FabricTagBuilder#clearTagEntries
FabricTag#hasBeenReplaced
There's also TagRegistry
but it's deprecated.