diff options
author | isXander <xander@isxander.dev> | 2024-06-11 23:13:49 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-06-11 23:13:57 +0100 |
commit | 305718e163f91802a4bc1c1ed6540febb2ce204e (patch) | |
tree | d72fe8b95dab1ef89f67b13a19f8c06fdb582c28 /src/main/java/dev/isxander/yacl3/api | |
parent | 65b4f7ba8374bbaebc6a431f8347ffc3e8afdced (diff) | |
download | YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.gz YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.bz2 YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.zip |
codec config and rewritten kotlin dsl
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/api')
-rw-r--r-- | src/main/java/dev/isxander/yacl3/api/Binding.java | 5 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl3/api/OptionDescription.java | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/dev/isxander/yacl3/api/Binding.java b/src/main/java/dev/isxander/yacl3/api/Binding.java index f41b78b..61c59a2 100644 --- a/src/main/java/dev/isxander/yacl3/api/Binding.java +++ b/src/main/java/dev/isxander/yacl3/api/Binding.java @@ -6,6 +6,7 @@ import net.minecraft.client.OptionInstance; import org.apache.commons.lang3.Validate; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; /** @@ -19,6 +20,10 @@ public interface Binding<T> { T defaultValue(); + default <U> Binding<U> xmap(Function<T, U> to, Function<U, T> from) { + return Binding.generic(to.apply(this.defaultValue()), () -> to.apply(this.getValue()), v -> this.setValue(from.apply(v))); + } + /** * Creates a generic binding. * diff --git a/src/main/java/dev/isxander/yacl3/api/OptionDescription.java b/src/main/java/dev/isxander/yacl3/api/OptionDescription.java index 7336379..fce7e2f 100644 --- a/src/main/java/dev/isxander/yacl3/api/OptionDescription.java +++ b/src/main/java/dev/isxander/yacl3/api/OptionDescription.java @@ -128,7 +128,7 @@ public interface OptionDescription { * <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)} + * A helpful utility (that is also not API safe) is {@link dev.isxander.yacl3.gui.image.ImageRendererManager#registerOrGetImage(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 @@ -136,6 +136,21 @@ public interface OptionDescription { Builder customImage(CompletableFuture<Optional<ImageRenderer>> image); /** + * 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 dev.isxander.yacl3.gui.image.ImageRendererManager#registerOrGetImage(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 + */ + default Builder customImage(ImageRenderer image) { + return this.customImage(CompletableFuture.completedFuture(Optional.of(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. * |