Class ClientTags

java.lang.Object
net.fabricmc.fabric.api.tag.client.v1.ClientTags

@Environment(CLIENT) public final class ClientTags extends Object
Allows the use of tags by directly loading them from the installed mods.

Tags are loaded by the server, either the internal server in singleplayer or the connected server and synced to the client. This can be a pain point for interoperability, as a tag that does not exist on the server because it is part of a mod only present on the client will no longer be available to the client that may wish to query it.

Client Tags resolve that issue by lazily reading the tag json files within the mods on the side of the caller, directly, allowing for mods to query tags such as ConventionalBlockTags even when connected to a vanilla server.

  • Method Details

    • getOrCreateLocalTag

      public static Set<Identifier> getOrCreateLocalTag(TagKey<?> tagKey)
      Loads a tag into the cache, recursively loading any contained tags along with it.
      Parameters:
      tagKey - the TagKey to load
      Returns:
      a set of Identifiers this tag contains
    • isInWithLocalFallback

      public static <T> boolean isInWithLocalFallback(TagKey<T> tagKey, T entry)
      Checks if an entry is in a tag.

      If the synced tag does exist, it is queried. If it does not exist, the tag populated from the available mods is checked.

      Parameters:
      tagKey - the TagKey to being checked
      entry - the entry to check
      Returns:
      if the entry is in the given tag
    • isInWithLocalFallback

      public static <T> boolean isInWithLocalFallback(TagKey<T> tagKey, RegistryEntry<T> registryEntry)
      Checks if an entry is in a tag, for use with entries from a dynamic registry, such as Biomes.

      If the synced tag does exist, it is queried. If it does not exist, the tag populated from the available mods is checked.

      Parameters:
      tagKey - the TagKey to be checked
      registryEntry - the entry to check
      Returns:
      if the entry is in the given tag
    • isInLocal

      public static <T> boolean isInLocal(TagKey<T> tagKey, RegistryKey<T> registryKey)
      Checks if an entry is in a tag provided by the available mods.
      Parameters:
      tagKey - the TagKey to being checked
      registryKey - the entry to check
      Returns:
      if the entry is in the given tag