Class ReloadableResourceManagerImpl
- All Implemented Interfaces:
AutoCloseable,ReloadableResourceManager,ResourceManager
public class ReloadableResourceManagerImpl extends Object implements ReloadableResourceManager
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classReloadableResourceManagerImpl.FailedResourceReloadMonitorstatic classReloadableResourceManagerImpl.PackAdditionFailedExceptionNested classes/interfaces inherited from interface net.minecraft.resource.ResourceManager
ResourceManager.Empty -
Field Summary
Fields Modifier and Type Field Description private List<ResourcePack>field_25145private List<ResourceReloader>initialListenersprivate static LoggerLOGGERprivate Map<String,NamespaceResourceManager>namespaceManagersprivate Set<String>namespacesprivate List<ResourceReloader>reloadersprivate ResourceTypetype -
Constructor Summary
Constructors Constructor Description ReloadableResourceManagerImpl(ResourceType type) -
Method Summary
Modifier and Type Method Description voidaddPack(ResourcePack pack)protected ResourceReloadbeginReloadInner(Executor prepareExecutor, Executor applyExecutor, List<ResourceReloader> listeners, CompletableFuture<Unit> initialStage)private voidclear()voidclose()booleancontainsResource(Identifier id)Checks whether any of the currently-loaded resource packs contain an entry for the given id.Collection<Identifier>findResources(String startingPath, Predicate<String> pathPredicate)Returns a sorted list of identifiers matching a path predicate.Set<String>getAllNamespaces()Gets a set of all namespaces offered by the resource packs loaded by this manager.List<Resource>getAllResources(Identifier id)Gets all of the available resources to the corresponding resource identifier.ResourcegetResource(Identifier id)Finds and returns the corresponding resource for a resource's identifier.voidregisterReloader(ResourceReloader reloader)Registers a resource reloader to this manager.ResourceReloadreload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs)Performs a reload.Stream<ResourcePack>streamResourcePacks()Gets a stream of loaded resource packs in increasing order of priority.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.resource.ReloadableResourceManager
reload
-
Field Details
-
LOGGER
-
namespaceManagers
-
reloaders
-
initialListeners
-
namespaces
-
field_25145
-
type
-
-
Constructor Details
-
ReloadableResourceManagerImpl
-
-
Method Details
-
addPack
-
getAllNamespaces
Gets a set of all namespaces offered by the resource packs loaded by this manager.- Specified by:
getAllNamespacesin interfaceResourceManager
-
getResource
Finds and returns the corresponding resource for a resource's identifier.Starts by scanning each resource pack from highest priority to lowest. If no resource packs were found to contain the requested entry, will throw a
FileNotFoundException.The returned resource must be closed to avoid resource leaks.
- Specified by:
getResourcein interfaceResourceManager- Parameters:
id- the resource identifier to search for- Throws:
FileNotFoundException- if the identified resource could not be found, or could not be loaded.IOException- if the identified resource was found but a stream to it could not be opened.
-
containsResource
Checks whether any of the currently-loaded resource packs contain an entry for the given id.Starts by querying the resource pack with the highest priority to lowest until it finds one that responds to the requested identifier.
- Specified by:
containsResourcein interfaceResourceManager- Parameters:
id- the resource identifier to search for
-
getAllResources
Gets all of the available resources to the corresponding resource identifier.Resources are returned in load order, or ascending order of priority, so the last element in the returned list is what would be returned normally by
getResource(net.minecraft.util.Identifier)Each resource in this returned list must be closed to avoid resource leaks.
- Specified by:
getAllResourcesin interfaceResourceManager- Parameters:
id- the resource identifier to search for- Throws:
FileNotFoundException- if no matching resources could be found (i.e. if the list would be empty)IOException- if resources were found, but any one of them could not be opened to be read.
-
findResources
Returns a sorted list of identifiers matching a path predicate.Scanning begins in
startingPathand each candidate file present under that directory will be offered up to the predicate to decide whether it should be included or not.Elements in the returned list may not, necessarily be unique. Additional effort is advised to ensure that duplicates in the returned list are discarded before loading.
- Specified by:
findResourcesin interfaceResourceManager- Parameters:
startingPath- the starting path to begin scanning frompathPredicate- a predicate to determine whether a path should be included or not- Returns:
- the list matching identifiers
-
clear
private void clear() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceReloadableResourceManager
-
registerReloader
Registers a resource reloader to this manager.- Specified by:
registerReloaderin interfaceReloadableResourceManager- Parameters:
reloader- the reloader
-
beginReloadInner
protected ResourceReload beginReloadInner(Executor prepareExecutor, Executor applyExecutor, List<ResourceReloader> listeners, CompletableFuture<Unit> initialStage) -
reload
public ResourceReload reload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs)Performs a reload. Returns an object that yields some insights to the reload.prepareExecutormay be asynchronous.applyExecutormust synchronize with the game engine so changes are properly made to it. The reload will only begin afterinitialStagehas completed. Earlier elements inpackshave lower priorities.- Specified by:
reloadin interfaceReloadableResourceManager- Parameters:
prepareExecutor- an executor for the prepare stageapplyExecutor- an executor for the apply stageinitialStage- a completable future to be completed before this reloadpacks- a list of resource packs providing resources- Returns:
- the reload
- See Also:
ResourceReloader.reload(net.minecraft.resource.ResourceReloader.Synchronizer, net.minecraft.resource.ResourceManager, net.minecraft.util.profiler.Profiler, net.minecraft.util.profiler.Profiler, java.util.concurrent.Executor, java.util.concurrent.Executor)
-
streamResourcePacks
Gets a stream of loaded resource packs in increasing order of priority.- Specified by:
streamResourcePacksin interfaceResourceManager
-