Interface PostFlattenTagRegistrar<T>

Type Parameters:
T - the type of value in the tag
All Superinterfaces:
Registrar

@Experimental @NullMarked @NonExtendable public interface PostFlattenTagRegistrar<T> extends Registrar
Registrar for tags after they have been flattened. Flattened tags are tags which have any nested tags resolved to the tagged values the nested tags point to. This registrar, being a post-flatten registrar, allows for modification after that flattening has happened, when tags only point to individual entries and not other nested tags.

An example of a custom enchant being registered to the vanilla #minecraft:in_enchanting_table tag:


 class YourBootstrapClass implements PluginBootstrap {

     public static final TypedKey<Enchantment> CUSTOM_POINTY_ENCHANT = EnchantmentKeys.create(Key.key("papermc:pointy"));

     @Override
     public void bootstrap(BootstrapContext context) {
         final LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
         manager.registerEventHandler(LifecycleEvents.TAGS.postFlatten(RegistryKey.ENCHANTMENT), event -> {
             final PostFlattenTagRegistrar<Enchantment> registrar = event.registrar();
             registrar.addToTag(
                 EnchantmentTagKeys.IN_ENCHANTING_TABLE,
                 Set.of(CUSTOM_POINTY_ENCHANT)
             );
         });
     }
 }
 
See Also:
  • Method Details

    • registryKey

      RegistryKey<T> registryKey()
      Get the registry key for this tag registrar.
      Returns:
      the registry key
    • getAllTags

      @Contract(value="-> new", pure=true) @Unmodifiable Map<TagKey<T>,Collection<TypedKey<T>>> getAllTags()
      Get a copy of all tags currently held in this registrar.
      Returns:
      an immutable map of all tags
    • hasTag

      @Contract(pure=true) boolean hasTag(TagKey<T> tagKey)
      Checks if this registrar has a tag with the given key.
      Parameters:
      tagKey - the key to check for
      Returns:
      true if the tag exists, false otherwise
    • getTag

      @Contract(value="_ -> new", pure=true) @Unmodifiable Collection<TypedKey<T>> getTag(TagKey<T> tagKey)
      Get the tag with the given key. Use hasTag(TagKey) to check if a tag exists first.
      Parameters:
      tagKey - the key of the tag to get
      Returns:
      an immutable list of tag entries
      Throws:
      NoSuchElementException - if the tag does not exist
      See Also:
    • addToTag

      @Contract(mutates="this") void addToTag(TagKey<T> tagKey, Collection<TypedKey<T>> values)
      Adds values to the given tag. If the tag does not exist, it will be created.
      Parameters:
      tagKey - the key of the tag to add to
      values - the values to add
      See Also:
    • setTag

      @Contract(mutates="this") void setTag(TagKey<T> tagKey, Collection<TypedKey<T>> values)
      Sets the values of the given tag. If the tag does not exist, it will be created. If the tag does exist, it will be overwritten.
      Parameters:
      tagKey - the key of the tag to set
      values - the values to set
      See Also: