Class ForgeTagHandler

java.lang.Object
net.minecraftforge.common.ForgeTagHandler

public class ForgeTagHandler extends Object
  • Field Details

    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
    • customTagTypeNames

      private static Set<ResourceLocation> customTagTypeNames
    • tagTypesSet

      private static boolean tagTypesSet
  • Constructor Details

    • ForgeTagHandler

      public ForgeTagHandler()
  • Method Details

    • getTagHelper

      @Nullable private static <T extends IForgeRegistryEntry<T>> StaticTagHelper<T> getTagHelper(IForgeRegistry<T> registry)
    • validateRegistrySupportsTags

      private static void validateRegistrySupportsTags(IForgeRegistry<?> registry)
    • makeWrapperTag

      public static <T extends IForgeRegistryEntry<T>> Tag.Named<T> makeWrapperTag(IForgeRegistry<T> registry, ResourceLocation name)
      Helper method that creates a named tag for a forge registry, erroring if the registry doesn't support custom tag types. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registry - Registry the tag is for
      name - Name of the tag
      Returns:
      A named tag
    • createOptionalTag

      public static <T extends IForgeRegistryEntry<T>> Tags.IOptionalNamedTag<T> createOptionalTag(IForgeRegistry<T> registry, ResourceLocation name)
      Helper method that creates an optional tag for a forge registry, erroring if the registry doesn't support custom tag types. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registry - Registry the tag is for
      name - Name of the tag
      Returns:
      An optional tag
    • createOptionalTag

      public static <T extends IForgeRegistryEntry<T>> Tags.IOptionalNamedTag<T> createOptionalTag(IForgeRegistry<T> registry, ResourceLocation name, @Nullable Set<Supplier<T>> defaults)
      Helper method that creates an optional tag for a forge registry, erroring if the registry doesn't support custom tag types. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registry - Registry the tag is for
      name - Name of the tag
      defaults - Default values for the optional tag
      Returns:
      An optional tag
    • makeWrapperTag

      public static <T extends IForgeRegistryEntry<T>> Tag.Named<T> makeWrapperTag(ResourceLocation registryName, ResourceLocation name)
      Helper method for creating named tags for custom forge registries. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registryName - Name of the registry the tag is for
      name - Name of the tag
      Returns:
      A named tag
    • createOptionalTag

      public static <T extends IForgeRegistryEntry<T>> Tags.IOptionalNamedTag<T> createOptionalTag(ResourceLocation registryName, ResourceLocation name)
      Helper method for creating optional tags for custom forge registries. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registryName - Name of the registry the tag is for
      name - Name of the tag
      Returns:
      An optional tag
    • createOptionalTag

      public static <T extends IForgeRegistryEntry<T>> Tags.IOptionalNamedTag<T> createOptionalTag(ResourceLocation registryName, ResourceLocation name, @Nullable Set<Supplier<T>> defaults)
      Helper method for creating optional tags for custom forge registries. If the custom tag types have not been set yet, this method falls back and creates the tag reference delaying adding it to the tag registry to allow for statically initializing and referencing the tag.
      Type Parameters:
      T - Type of the registry
      Parameters:
      registryName - Name of the registry the tag is for
      name - Name of the tag
      defaults - Default values for the optional tag
      Returns:
      An optional tag
    • getCustomTagTypeNames

      public static Set<ResourceLocation> getCustomTagTypeNames()
      Gets the all the registry names of registries that support custom tag types.
    • setCustomTagTypes

      public static void setCustomTagTypes(Set<ResourceLocation> customTagTypesNames)
      Sets the set containing the resource locations representing the registry name of each forge registry that supports custom tag types.
    • createCustomTagTypeReaders

      public static Map<ResourceLocation,​TagLoader<?>> createCustomTagTypeReaders()
      Creates a map for custom tag type to tag reader
    • getWrapperRegistry

      public static <T> Optional<? extends Registry<T>> getWrapperRegistry(ResourceKey<? extends Registry<T>> key, Optional<? extends Registry<T>> vanillaReg)
      Wraps the forge registry if it supports tags into the internal registry for use in serialization
    • reinjectOptionalTags

      public static TagContainer reinjectOptionalTags(TagContainer tagCollectionSupplier)
      Helper to reinject missing optional tags.