Class ResourceCache

java.lang.Object
dev.lukebemish.dynamicassetgenerator.api.ResourceCache
Direct Known Subclasses:
AssetResourceCache, DataResourceCache

public abstract class ResourceCache extends Object
Caches instructions for producing resources, and generates them as packs are loaded.
  • Field Details

  • Constructor Details

    • ResourceCache

      public ResourceCache(net.minecraft.resources.ResourceLocation name)
      Parameters:
      name - a unique identifier for this cache
  • Method Details

    • register

      public static <T extends ResourceCache> T register(T cache, net.minecraft.server.packs.repository.Pack.Position position)
      Register a new resource cache.
      Type Parameters:
      T - the type of the cache
      Parameters:
      cache - the cache to register
      position - the position to register the cache at
      Returns:
      the registered cache
    • getDependencies

      public Set<net.minecraft.resources.ResourceLocation> getDependencies()
      Returns:
      names of other ResourceCaches that this cache is allowed to use during generation
    • allowAccess

      public final boolean allowAccess(String packId)
      Determines whether this cache can access the provided resources during resource generation
      Parameters:
      packId - the name of the pack to check whether access is allowed
      Returns:
      true if access is allowed; false otherwise
    • register

      public static <T extends ResourceCache> T register(T cache)
      Register a new resource cache as the lowest priority resource pack.
      Type Parameters:
      T - the type of the cache
      Parameters:
      cache - the cache to register
      Returns:
      the registered cache
    • getName

      public net.minecraft.resources.ResourceLocation getName()
      Returns:
      a unique identifier for this cache
    • getResources

      public Map<net.minecraft.resources.ResourceLocation,net.minecraft.server.packs.resources.IoSupplier<InputStream>> getResources()
      Returns:
      a map of all resources this pack can generate; calling this may resolve any given source cached to it
    • makeContext

      public @NonNull ResourceGenerationContext makeContext(boolean blind)
      Creates a context for generating resources within this cache.
      Parameters:
      blind - if true, the context should not be able to read resources. Must be true if the available resources are not guaranteed to be set up yet
      Returns:
      a context for generating resources within this cache
    • planResetListener

      public void planResetListener(Resettable listener)
      Adds a listener to be called when this cache is reset.
      Parameters:
      listener - the listener to add
    • reset

      public void reset(ResourceGenerationContext context)
      Resets all listeners associated with this cache.
    • planSource

      public void planSource(net.minecraft.resources.ResourceLocation rl, InputStreamSource source)
      Plan a source to be generated at a given resource location when this cache is resolved.
      Parameters:
      rl - the resource location the generated source is located at
      source - the source to generate
    • planSource

      public void planSource(Supplier<Set<net.minecraft.resources.ResourceLocation>> locations, InputStreamSource source)
      Plan to generate sources at a currently unresolved set of locations when this cache is resolved.
      Parameters:
      locations - the locations to generate; resolved when this cache is resolved
      source - the source to generate
    • planSource

      public void planSource(Set<net.minecraft.resources.ResourceLocation> locations, InputStreamSource source)
      Plan to generate sources at a set of locations when this cache is resolved.
      Parameters:
      locations - the locations to generate
      source - the source to generate
    • planSource

      public void planSource(PathAwareInputStreamSource source)
      Plan to generate a source when this cache is resolved.
      Parameters:
      source - the source to generate
    • planSource

      public void planSource(Supplier<? extends PathAwareInputStreamSource> source)
      Plan to generate a currently unresulved source when this cache is resolved.
      Parameters:
      source - the source to generate; resulved when this cache is resolved
    • getPackType

      public abstract @NonNull net.minecraft.server.packs.PackType getPackType()
      Returns:
      the type of pack this cache will generate resources for