|
3 | 3 | import com.mojang.blaze3d.systems.RenderSystem; |
4 | 4 | import dev.isxander.yacl3.gui.image.impl.AnimatedDynamicTextureImage; |
5 | 5 | import dev.isxander.yacl3.impl.utils.YACLConstants; |
| 6 | +import dev.isxander.yacl3.platform.YACLConfig; |
6 | 7 | import net.minecraft.client.Minecraft; |
7 | 8 | import net.minecraft.resources.ResourceLocation; |
8 | 9 |
|
9 | 10 | import java.util.List; |
10 | 11 | import java.util.Map; |
| 12 | +import java.util.Objects; |
11 | 13 | import java.util.Optional; |
12 | 14 | import java.util.concurrent.*; |
13 | 15 | import java.util.function.Function; |
14 | 16 | import java.util.function.Predicate; |
15 | 17 | import java.util.function.Supplier; |
| 18 | +import java.util.stream.Stream; |
16 | 19 |
|
17 | 20 | public class ImageRendererManager { |
18 | 21 | private static final ExecutorService SINGLE_THREAD_EXECUTOR = Executors.newSingleThreadExecutor(task -> new Thread(task, "YACL Image Prep")); |
19 | 22 |
|
20 | 23 | private static final Map<ResourceLocation, CompletableFuture<ImageRenderer>> IMAGE_CACHE = new ConcurrentHashMap<>(); |
21 | 24 | static final Map<ResourceLocation, ImageRenderer> PRELOADED_IMAGE_CACHE = new ConcurrentHashMap<>(); |
22 | 25 |
|
23 | | - static final List<PreloadedImageFactory> PRELOADED_IMAGE_FACTORIES = List.of( |
24 | | - new PreloadedImageFactory( |
| 26 | + static final List<PreloadedImageFactory> PRELOADED_IMAGE_FACTORIES = Stream.of( |
| 27 | + YACLConfig.HANDLER.instance().preloadComplexImageFormats ? new PreloadedImageFactory( |
25 | 28 | location -> location.getPath().endsWith(".webp"), |
26 | 29 | AnimatedDynamicTextureImage::createWEBPFromTexture |
27 | | - ), |
28 | | - new PreloadedImageFactory( |
| 30 | + ) : null, |
| 31 | + YACLConfig.HANDLER.instance().preloadComplexImageFormats ? new PreloadedImageFactory( |
29 | 32 | location -> location.getPath().endsWith(".gif"), |
30 | 33 | AnimatedDynamicTextureImage::createGIFFromTexture |
31 | | - ) |
32 | | - ); |
| 34 | + ) : null |
| 35 | + ).filter(Objects::nonNull).toList(); |
33 | 36 |
|
34 | 37 | public static <T extends ImageRenderer> Optional<T> getImage(ResourceLocation id) { |
35 | 38 | if (PRELOADED_IMAGE_CACHE.containsKey(id)) { |
|
0 commit comments