Skip to main content

Texture Generation

All texture generators available through the JSON system are also available in code; they are located in dev.lukebemish.dynamicassetgenerator.api.client.generators.texsources, and are subclasses of TexSource. A TexSource can be turned into a PathAwareInputStreamSource by wrapping them in a TextureGenerator. For example:

public class ClientExample {
public static final AssetResourceCache ASSET_CACHE =
ResourceCache.register(new AssetResourceCache(new ResourceLocation("my_mod", "assets")));

public static void initializeClient() {
// This method would be run during client initialization from the appropriate location.
ASSET_CACHE.planSource(
new TextureGenerator(
new ResourceLocation("my_mod","block/my_block"),
new TextureReaderSource.Builder().setPath(new ResourceLocation("item/apple")).build()
)
);
}
}

This will register a new texture source that copies the item/apple texture to my_mod:block/my_block.

Custom Texture Sources

Custom texture sources can be created by implementing TexSource, which requires implementing two methods:

getSupplier takes a TexSourceDataHolder and a ResourceGenerationContext, and returns a IoSupplier<NativeImage>, or null if no texture can be constructed. The TexSourceDataHolder is used to hold data that should be passed to "child" elements of the texture source, such as the logger, which can be retrieved with TexSourceDataHolder#getLogger. Note that making your source's output depend on other data in this element requires implementing the caching API, and that if your source reads existing resources, it should implement the cache key API.

codec returns a map codec that can be used to serialize or deserialize the texture source. This codec must be registered with TexSource.register, and is used when caching texture sources; a texture source's generated texture must be fully describable by the information encoded by its codec, unless the experimental caching API is implemented for that texture source.