From 26aec79e10025ff3427ceb47602156ebd670b2ac Mon Sep 17 00:00:00 2001 From: isXander Date: Sun, 14 Apr 2024 21:11:32 +0100 Subject: Fix gifs not being preloaded + add testmod samples --- .../dev/isxander/yacl3/gui/image/ImageRendererManager.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/main/java/dev/isxander/yacl3/gui') 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 CompletableFuture registerImage(ResourceLocation id, ImageRendererFactory factory) { - System.out.println(PRELOADED_IMAGE_CACHE.get(id)); + public static CompletableFuture registerOrGetImage(ResourceLocation id, Supplier factorySupplier) { + if (PRELOADED_IMAGE_CACHE.containsKey(id)) { + return CompletableFuture.completedFuture((T) PRELOADED_IMAGE_CACHE.get(id)); + } if (IMAGE_CACHE.containsKey(id)) { return (CompletableFuture) IMAGE_CACHE.get(id); @@ -54,6 +56,7 @@ public class ImageRendererManager { var future = new CompletableFuture(); IMAGE_CACHE.put(id, future); + ImageRendererFactory factory = factorySupplier.get(); SINGLE_THREAD_EXECUTOR.submit(() -> { Supplier> supplier = factory.requiresOffThreadPreparation() @@ -66,6 +69,11 @@ public class ImageRendererManager { return (CompletableFuture) future; } + @Deprecated + public static CompletableFuture registerImage(ResourceLocation id, ImageRendererFactory factory) { + return registerOrGetImage(id, () -> factory); + } + private static void completeImageFactory(ResourceLocation id, Supplier> supplier, CompletableFuture future) { RenderSystem.assertOnRenderThread(); -- cgit