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
    • customTagTypes

      private static Map<ResourceLocation,ITagCollection<?>> customTagTypes
    • customTagTypeNames

      private static Set<ResourceLocation> customTagTypeNames
    • tagTypesSet

      private static boolean tagTypesSet
  • Constructor Details

    • ForgeTagHandler

      public ForgeTagHandler()
  • Method Details

    • getTagRegistry

      @Nullable private static <T extends IForgeRegistryEntry<T>> TagRegistry<T> getTagRegistry(IForgeRegistry<T> registry)
    • validateRegistrySupportsTags

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

      public static <T extends IForgeRegistryEntry<T>> ITag.INamedTag<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>> ITag.INamedTag<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.
    • getCustomTagTypes

      public static Map<ResourceLocation,ITagCollection<?>> getCustomTagTypes()
      Gets a map of registry name to tag collection for all custom tag types.
    • setCustomTagTypes

      public static void setCustomTagTypes(Set<ResourceLocation> customTagTypes)
      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,TagCollectionReader<?>> createCustomTagTypeReaders()
      Creates a map for custom tag type to tag reader
    • resetCachedTagCollections

      public static void resetCachedTagCollections(boolean makeEmpty, boolean withOptional)
      Resets the cached collections for the various custom tag types.
    • populateTagCollectionManager

      public static ITagCollectionSupplier populateTagCollectionManager(ITagCollection<Block> blockTags, ITagCollection<Item> itemTags, ITagCollection<Fluid> fluidTags, ITagCollection<EntityType<?>> entityTypeTags)
      Used to ensure that all custom tag types have a defaulted collection when vanilla is initializing a defaulted TagCollectionManager
    • updateCustomTagTypes

      public static void updateCustomTagTypes(List<ForgeTagHandler.TagCollectionReaderInfo> tagCollectionReaders)
      Updates the custom tag types' tags from reloading via NetworkTagManager
    • updateCustomTagTypes

      public static void updateCustomTagTypes(FMLPlayMessages.SyncCustomTagTypes packet)
      Updates the custom tag types' tags from packet
    • getCustomTagTypeReloadResults

      public static CompletableFuture<List<ForgeTagHandler.TagCollectionReaderInfo>> getCustomTagTypeReloadResults(IResourceManager resourceManager, Executor backgroundExecutor, Map<ResourceLocation,TagCollectionReader<?>> readers)
      Gets the completable future containing the reload results for all custom tag types.
    • reinjectOptionalTagsCustomTypes

      public static void reinjectOptionalTagsCustomTypes()
      Add all the missing optional tags back into the custom tag types tag collections
    • withNoCustom

      public static ITagCollectionSupplier withNoCustom(ITagCollectionSupplier tagCollectionSupplier)
      Gets an ITagCollectionSupplier with empty custom tag type collections to allow for checking if the client is requiring any tags of custom tag types.
    • withSpecificCustom

      public static ITagCollectionSupplier withSpecificCustom(ITagCollectionSupplier tagCollectionSupplier, Map<ResourceLocation,ITagCollection<?>> customTagTypes)
      Gets an ITagCollectionSupplier with specific custom tag types for testing if any tags are missing.