diff options
author | isXander <xander@isxander.dev> | 2023-05-27 20:45:02 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2023-05-27 21:31:20 +0100 |
commit | 8829b00d238ff42fba6e1ad3eee3f570c84e08b6 (patch) | |
tree | 198cd5467369428257f33855d7b360188605916f | |
parent | baf4828a710b218b2f51fd7418f01818dea38d92 (diff) | |
download | YetAnotherConfigLib-8829b00d238ff42fba6e1ad3eee3f570c84e08b6.tar.gz YetAnotherConfigLib-8829b00d238ff42fba6e1ad3eee3f570c84e08b6.tar.bz2 YetAnotherConfigLib-8829b00d238ff42fba6e1ad3eee3f570c84e08b6.zip |
add custom image provider to OptionDescription
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/api/OptionDescription.java | 13 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/impl/OptionDescriptionImpl.java | 10 |
2 files changed, 23 insertions, 0 deletions
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 @@ -123,6 +123,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. + * <p> + * However, <strong>THIS IS NOT API SAFE!</strong> 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<Optional<ImageRenderer>> 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 @@ -123,6 +123,16 @@ public record OptionDescriptionImpl(Component description, CompletableFuture<Opt } @Override + public Builder customImage(CompletableFuture<Optional<ImageRenderer>> 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(); Iterator<Component> iter = descriptionLines.iterator(); |