Skip to main content

General Concepts

Resources and data are provided through a ResourceCache; DynAssetGen has built in implementations of ResourceCache for generating assets and data. Resource caches have an identifier associated with them, and can be registered with ResourceCache.register. For instance, to register a data cache:

public static final DataResourceCache DATA_CACHE =
ResourceCache.register(new DataResourceCache(ResourceLocation.fromNamespaceAndPath("my_mod", "data")));

AssetResourceCache is a similar built-in implementation for client resources.

Resource generation is structured around several core concepts:

  • ResourceGenerationContext, an object which holds information about the current resource generation environment, including a ResourceSource which can be used to access existing resources.
  • InputStreamSource, an object which can take a target file resource location and a generation context, and supplies an IoSupplier<InputStream> which can be used to read the resource data, or null if no resource should be supplied.
  • PathAwareInputStreamSource, a InputStreamSource which is aware of which locations it can provide data for.
  • Reset listeners, callbacks which are invoked when a resource cache is reset. These should be used to invalidate any sort of caching.

InputStreamSource also has a default method, createCacheKey, which can be overridden to provide a "key" for the generated resource. Between resource pack reloads or game restarts, if this key has not changed for a resource at a given location, then the existing, cached location will be used. Thus, this key should include all information needed to specify the resource; for texture sources, for instance, the implementation of this key contains both the serialized texture source generator, as well as hashed versions of any images that the texture source reads.

ResourceCache contains a number of methods for adding input stream sources; these methods all internally delegate to the "lazy" method which accepts a Supplier<? extends PathAwareInputStreamSource> and does not evaluate it until resources are requested from the cache. This means that a PathAwareInputStreamSource can safely access existing resources or data both when generating resources and when determining which resources it can provide.

Resources and data from other sources (the base game, resource packs, other mods, etc.) can be accessed through the provided ResourceGenerationContext; by default, this will not contain resources from other packs added by DynAssetGen. To access these, provide their names in ResourceCache#getDependencies.