Interface TexSource
- All Known Implementing Classes:
AbstractManyOperationSource,AddMask,AnimationFrameCapture,AnimationSplittingSource,ChannelMask,ChannelRouteSource,ColorSource,CropSource,CutoffMask,EdgeMask,ErrorSource,FallbackSource,ForegroundTransferSource,GrowMask,InvertMask,MaskSource,MultiplyMask,OverlaySource,PaletteCombinedSource,PaletteSpreadSource,ShadowedSource,SpreadSource,TextureReaderSource,TransformSource
public interface TexSource
Contains instructions for generating a single texture. Many implementations allow for nesting of further sources
within this; thus, to avoid the generation of duplicate sources, texture sources are cached, if possible, with their
key being their serialized form in JSON. If this information is not enough to uniquely identify the texture a source
will produce (for instance, if it uses information passed in a context), then a source should implement the caching
API as needed.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> @NonNull com.mojang.serialization.DataResult<T> cacheMetadata(com.mojang.serialization.DynamicOps<T> ops, TexSourceDataHolder data) If your texture source depends on runtime data context (anything stored in theTexSourceDataHolder), you will need to override this method to return a unique key for the given context.@NonNull com.mojang.serialization.MapCodec<? extends TexSource> codec()default @Nullable net.minecraft.server.packs.resources.IoSupplier<com.mojang.blaze3d.platform.NativeImage> getCachedSupplier(TexSourceDataHolder data, ResourceGenerationContext context) Delegates togetSupplier(dev.lukebemish.dynamicassetgenerator.api.client.generators.TexSourceDataHolder, dev.lukebemish.dynamicassetgenerator.api.ResourceGenerationContext), but caches the result if possible.@Nullable net.minecraft.server.packs.resources.IoSupplier<com.mojang.blaze3d.platform.NativeImage> getSupplier(TexSourceDataHolder data, ResourceGenerationContext context) Provides a supplier for the texture this source will generate, or null if a texture cannot be provided.default <T> @NonNull com.mojang.serialization.DataResult<T> persistentCacheData(com.mojang.serialization.DynamicOps<T> ops, ResourceGenerationContext context) If your texture source depends on loaded resources (anything stored in theResourceGenerationContext), you will need to override this method to return a unique key based on the actual, loaded resources.static <T extends TexSource>
voidregister(net.minecraft.resources.ResourceLocation rl, com.mojang.serialization.MapCodec<T> codec) Register a new type of texture source, alongside a codec to decode from JSON and encode to a cache key.default String
-
Field Details
-
METADATA_CACHE_KEY
- See Also:
-
CODEC
-
-
Method Details
-
register
static <T extends TexSource> void register(net.minecraft.resources.ResourceLocation rl, com.mojang.serialization.MapCodec<T> codec) Register a new type of texture source, alongside a codec to decode from JSON and encode to a cache key.- Type Parameters:
T- the texture source type- Parameters:
rl- the identifier of this texture source typecodec- can serialize and deserialize this texture source type
-
cacheMetadata
@Experimental default <T> @NonNull com.mojang.serialization.DataResult<T> cacheMetadata(com.mojang.serialization.DynamicOps<T> ops, TexSourceDataHolder data) If your texture source depends on runtime data context (anything stored in theTexSourceDataHolder), you will need to override this method to return a unique key for the given context. This key will be used when caching textures generated by this source. If your source should not be cached, return a DataResult.error.- Parameters:
ops- DynamicOps to encode the unique key with.data- Data holder that the key is dependent on.- Returns:
- A success with a unique key for the given context, or an error if no key can be generated.
-
persistentCacheData
@Experimental default <T> @NonNull com.mojang.serialization.DataResult<T> persistentCacheData(com.mojang.serialization.DynamicOps<T> ops, ResourceGenerationContext context) If your texture source depends on loaded resources (anything stored in theResourceGenerationContext), you will need to override this method to return a unique key based on the actual, loaded resources. This key will be used for caching across reloads, unlike that provided bycacheMetadata(com.mojang.serialization.DynamicOps<T>, dev.lukebemish.dynamicassetgenerator.api.client.generators.TexSourceDataHolder). If your source should not be cached, return a DataResult.error.- Parameters:
ops- DynamicOps to encode the unique key with.context- the context that the resource will be generated in. Resources can safely be accessed in this context- Returns:
- A success with a unique key for the given context, or an error if no key can be generated.
-
codec
@NonNull com.mojang.serialization.MapCodec<? extends TexSource> codec()- Returns:
- a codec which can be used to serialize this source
-
getSupplier
@OverrideOnly @Nullable net.minecraft.server.packs.resources.IoSupplier<com.mojang.blaze3d.platform.NativeImage> getSupplier(TexSourceDataHolder data, ResourceGenerationContext context) Provides a supplier for the texture this source will generate, or null if a texture cannot be provided. Should be overridden, but not called; callgetCachedSupplier(dev.lukebemish.dynamicassetgenerator.api.client.generators.TexSourceDataHolder, dev.lukebemish.dynamicassetgenerator.api.ResourceGenerationContext)instead to support caching.- Parameters:
data- context information passed by outer nesting texture sources; if you depend on this, you will want to implement the caching API (seecacheMetadata(com.mojang.serialization.DynamicOps<T>, dev.lukebemish.dynamicassetgenerator.api.client.generators.TexSourceDataHolder))context- context about the environment the texture is generating in- Returns:
- a supplier able to produce the texture, or null if the texture could not be produced.
-
getCachedSupplier
@NonExtendable default @Nullable net.minecraft.server.packs.resources.IoSupplier<com.mojang.blaze3d.platform.NativeImage> getCachedSupplier(TexSourceDataHolder data, ResourceGenerationContext context) Delegates togetSupplier(dev.lukebemish.dynamicassetgenerator.api.client.generators.TexSourceDataHolder, dev.lukebemish.dynamicassetgenerator.api.ResourceGenerationContext), but caches the result if possible. Should be used instead of the non-cached version, but not extended. -
stringify
- Returns:
- a string representation of this texture source, meant for logging and debugging purposes. Should not be used for serialization or caching. Can be safely overridden to provide whatever information is deemed useful.
-