From 8829b00d238ff42fba6e1ad3eee3f570c84e08b6 Mon Sep 17 00:00:00 2001 From: isXander Date: Sat, 27 May 2023 20:45:02 +0100 Subject: add custom image provider to OptionDescription --- .../main/java/dev/isxander/yacl/api/OptionDescription.java | 13 +++++++++++++ .../java/dev/isxander/yacl/impl/OptionDescriptionImpl.java | 10 ++++++++++ 2 files changed, 23 insertions(+) (limited to 'common/src/main/java/dev/isxander') diff --git a/common/src/main/java/dev/isxander/yacl/api/OptionDescription.java b/common/src/main/java/dev/isxander/yacl/api/OptionDescription.java index c233309..fbae4c2 100644 --- a/common/src/main/java/dev/isxander/yacl/api/OptionDescription.java +++ b/common/src/main/java/dev/isxander/yacl/api/OptionDescription.java @@ -122,6 +122,19 @@ public interface OptionDescription { */ Builder webpImage(Path path, ResourceLocation uniqueLocation); + /** + * Sets a custom image renderer to display with the description. + * This is useful for rendering other abstract things relevant to your mod. + *

+ * However, THIS IS NOT API SAFE! As part of the gui package, things + * may change that could break compatibility with future versions of YACL. + * A helpful utility (that is also not API safe) is {@link ImageRenderer#getOrMakeAsync(ResourceLocation, Supplier)} + * which will cache the image renderer for the whole game lifecycle and construct it asynchronously to the render thread. + * @param image the image renderer to display + * @return this builder + */ + Builder customImage(CompletableFuture> image); + /** * Sets an animated GIF image to display with the description. This is backed by a regular minecraft resource * in your mod's /assets folder. diff --git a/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java index 0b2853f..ba994e4 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java @@ -122,6 +122,16 @@ public record OptionDescriptionImpl(Component description, CompletableFuture> image) { + Validate.notNull(image, "Image cannot be null!"); + Validate.isTrue(imageUnset, "Image already set!"); + + this.image = image; + this.imageUnset = false; + return this; + } + @Override public OptionDescription build() { MutableComponent concatenatedDescription = Component.empty(); -- cgit