Class ResourceCacheManager

java.lang.Object
net.minecraftforge.resource.ResourceCacheManager

@Internal public class ResourceCacheManager extends Object
Cache manager for resources.

This class handles caching the resource listing calls on a pack, pack type and namespace level.

  • Field Details

    • RESOURCE_CACHE

      private static final org.slf4j.Marker RESOURCE_CACHE
      Logging marker to handle the hiding of the entries from the debug file.
    • supportsReloading

      private final boolean supportsReloading
      Indicates if the underlying namespaced managers need to support reloading. Disabled for the (in-jar / downloaded) default vanilla pack.
    • indexOnThreadConfigurationKey

      private final String indexOnThreadConfigurationKey
      The config key which can be used to check if the indexing of the file-tree should happen off-thread or on-thread and block the process accordingly.
    • pathBuilder

      private final BiFunction<PackType,String,Path> pathBuilder
      The path builder (different users have different requirements for how they want to handle this)
    • managersByNamespace

      The individual sub managers by pack type and namespace
  • Constructor Details

    • ResourceCacheManager

      @Deprecated(since="1.19.2", forRemoval=true) public ResourceCacheManager(boolean supportsReloading, ForgeConfigSpec.BooleanValue indexOffThreadConfig, BiFunction<PackType,String,Path> pathBuilder)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new instance of a resource cache manager.
      Parameters:
      supportsReloading - True to make the namespace specific managers support reloading the cache.
      indexOffThreadConfig - True to index the file-tree off-thread.
      pathBuilder - The path builder to use.
    • ResourceCacheManager

      public ResourceCacheManager(boolean supportsReloading, String indexOnThreadConfigurationKey, BiFunction<PackType,String,Path> pathBuilder)
  • Method Details

    • shouldUseCache

      public static boolean shouldUseCache()
      Indicates if the caching system is enabled or not.
      Returns:
      true if the caching system is enabled, false otherwise.
    • shouldIndexOnThread

      public boolean shouldIndexOnThread()
      Indicates if this cache manager requires the indexing of the file-tree to happen on the main thread.
      Returns:
      true if the indexing of the file-tree should happen on the main thread, false otherwise.
    • shouldIndexOffThread

      @Deprecated(forRemoval=true, since="1.19.2") public boolean shouldIndexOffThread()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Indicates if this cache manager requires the indexing of the file-tree to happen off the main thread.
      Returns:
      true if the indexing of the file-tree should happen off the main thread, true otherwise.
    • index

      public void index(String namespace)
      Invoked to trigger indexing of a given namespaces resources.
      Parameters:
      namespace - The namespace to index.
    • createWalkingStream

      private Stream<Path> createWalkingStream(Path path) throws IOException
      Handling method to create a new stream of paths in the target directory, which can then be walked. The caller needs to close the stream manually.
      Parameters:
      path - The path to walk.
      Returns:
      A stream of paths which reside in the given path.
      Throws:
      IOException - Thrown when the path does not exist or reading of path information failed.
    • getResources

      public Collection<ResourceLocation> getResources(PackType type, String resourceNamespace, Path inputPath, Predicate<ResourceLocation> filter)
      Returns the cached resources for the given pack type, namespace, path prefix and filter.
      Parameters:
      type - The type of pack to look up in (data or resource)
      resourceNamespace - The namespace of the resources to look up.
      inputPath - The input path prefix to check for.
      filter - The ternary filter to apply.
      Returns:
      A collection of resource locations which match the given filter, have the input path as prefix, are in the right pack type and have the given namespace as namespace.
    • getNamespaces

      public Set<String> getNamespaces(PackType type)
      Looks up all already indexed namespaces. Note even though a namespace might be returned from this method, it does not mean that the indexing has completed on that namespace if it is running off-thread.
      Parameters:
      type - The type of the pack to get the namespaces for.
      Returns:
      The namespaces which are known for the given pack type.
    • hasCached

      public boolean hasCached(PackType packType, String namespace)
      Indicates if the given namespace is completely cached for the given pack type.
      Parameters:
      packType - The pack type to check.
      namespace - The namespace to check.
      Returns:
      True if the namespace is completely cached for the given pack type.