Package net.minecraftforge.resource
Class ResourceCacheManager
java.lang.Object
net.minecraftforge.resource.ResourceCacheManager
Cache manager for resources.
This class handles caching the resource listing calls on a pack, pack type and namespace level.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
A namespaced and pack type specific cache which theResourceCacheManager
can delegate the handling to.private static final record
Record for the delegated namespaced manager map.private static interface
Functional callback interface to get a walkable stream of paths.private static final record
Record for the individual cache entries.private static final class
Class to handle the reading, initial creation, and watching of the boot configuration file, for the resource cache manager. -
Field Summary
Modifier and TypeFieldDescriptionprivate final String
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.private final Map<ResourceCacheManager.PackTypeAndNamespace,
ResourceCacheManager.NamespacedResourceCacheManager> The individual sub managers by pack type and namespaceprivate final BiFunction<PackType,
String, Path> The path builder (different users have different requirements for how they want to handle this)private static final org.slf4j.Marker
Logging marker to handle the hiding of the entries from the debug file.private final boolean
Indicates if the underlying namespaced managers need to support reloading. -
Constructor Summary
ConstructorDescriptionResourceCacheManager
(boolean supportsReloading, String indexOnThreadConfigurationKey, BiFunction<PackType, String, Path> pathBuilder) 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. -
Method Summary
Modifier and TypeMethodDescriptioncreateWalkingStream
(Path path) Handling method to create a new stream of paths in the target directory, which can then be walked.getNamespaces
(PackType type) Looks up all already indexed namespaces.getResources
(PackType type, String resourceNamespace, Path inputPath, Predicate<ResourceLocation> filter) Returns the cached resources for the given pack type, namespace, path prefix and filter.boolean
Indicates if the given namespace is completely cached for the given pack type.void
Invoked to trigger indexing of a given namespaces resources.boolean
Deprecated, for removal: This API element is subject to removal in a future version.boolean
Indicates if this cache manager requires the indexing of the file-tree to happen on the main thread.static boolean
Indicates if the caching system is enabled or not.
-
Field Details
-
RESOURCE_CACHE
private static final org.slf4j.Marker RESOURCE_CACHELogging marker to handle the hiding of the entries from the debug file. -
supportsReloading
private final boolean supportsReloadingIndicates if the underlying namespaced managers need to support reloading. Disabled for the (in-jar / downloaded) default vanilla pack. -
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
The path builder (different users have different requirements for how they want to handle this) -
managersByNamespace
private final Map<ResourceCacheManager.PackTypeAndNamespace,ResourceCacheManager.NamespacedResourceCacheManager> managersByNamespaceThe 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, 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
Invoked to trigger indexing of a given namespaces resources.- Parameters:
namespace
- The namespace to index.
-
createWalkingStream
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
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
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.
-