Skip to content

Instantly share code, notes, and snippets.

@apple502j
Last active March 3, 2022 08:18
Show Gist options
  • Save apple502j/4d4e57f067f5be408556001086949434 to your computer and use it in GitHub Desktop.
Save apple502j/4d4e57f067f5be408556001086949434 to your computer and use it in GitHub Desktop.

Tag Extension API in 1.18.2

Tag Extension API for Fabric has been removed in 1.18.2. Here are some vanilla replacements:

FabricDataGeneratorTagBuilder

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.

TagFactory

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 from tags/worldgen/biome (singular).

Other parts

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment