diff options
author | isXander <xander@isxander.dev> | 2024-04-14 21:11:32 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2024-04-14 21:11:32 +0100 |
commit | 26aec79e10025ff3427ceb47602156ebd670b2ac (patch) | |
tree | 280515927ea98bc510385d81de2d508f94910126 /src/main/java/dev/isxander/yacl3/gui | |
parent | bb0690af2536edf9ff920c0c229de8b919215850 (diff) | |
download | YetAnotherConfigLib-26aec79e10025ff3427ceb47602156ebd670b2ac.tar.gz YetAnotherConfigLib-26aec79e10025ff3427ceb47602156ebd670b2ac.tar.bz2 YetAnotherConfigLib-26aec79e10025ff3427ceb47602156ebd670b2ac.zip |
Fix gifs not being preloaded + add testmod samples
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/gui')
-rw-r--r-- | src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java b/src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java index 0c9b8a3..5674c85 100644 --- a/src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java +++ b/src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java @@ -44,8 +44,10 @@ public class ImageRendererManager { } @SuppressWarnings("unchecked") - public static <T extends ImageRenderer> CompletableFuture<T> registerImage(ResourceLocation id, ImageRendererFactory factory) { - System.out.println(PRELOADED_IMAGE_CACHE.get(id)); + public static <T extends ImageRenderer> CompletableFuture<T> registerOrGetImage(ResourceLocation id, Supplier<ImageRendererFactory> factorySupplier) { + if (PRELOADED_IMAGE_CACHE.containsKey(id)) { + return CompletableFuture.completedFuture((T) PRELOADED_IMAGE_CACHE.get(id)); + } if (IMAGE_CACHE.containsKey(id)) { return (CompletableFuture<T>) IMAGE_CACHE.get(id); @@ -54,6 +56,7 @@ public class ImageRendererManager { var future = new CompletableFuture<ImageRenderer>(); IMAGE_CACHE.put(id, future); + ImageRendererFactory factory = factorySupplier.get(); SINGLE_THREAD_EXECUTOR.submit(() -> { Supplier<Optional<ImageRendererFactory.ImageSupplier>> supplier = factory.requiresOffThreadPreparation() @@ -66,6 +69,11 @@ public class ImageRendererManager { return (CompletableFuture<T>) future; } + @Deprecated + public static <T extends ImageRenderer> CompletableFuture<T> registerImage(ResourceLocation id, ImageRendererFactory factory) { + return registerOrGetImage(id, () -> factory); + } + private static <T extends ImageRenderer> void completeImageFactory(ResourceLocation id, Supplier<Optional<ImageRendererFactory.ImageSupplier>> supplier, CompletableFuture<ImageRenderer> future) { RenderSystem.assertOnRenderThread(); |