Skip to content

Commit d407367

Browse files
committed
feat: config toggle to prevent loading .webp and .gif on resource reload for performance reasons
1 parent 256b8a1 commit d407367

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/main/java/dev/isxander/yacl3/gui/image/ImageRendererManager.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,36 @@
33
import com.mojang.blaze3d.systems.RenderSystem;
44
import dev.isxander.yacl3.gui.image.impl.AnimatedDynamicTextureImage;
55
import dev.isxander.yacl3.impl.utils.YACLConstants;
6+
import dev.isxander.yacl3.platform.YACLConfig;
67
import net.minecraft.client.Minecraft;
78
import net.minecraft.resources.ResourceLocation;
89

910
import java.util.List;
1011
import java.util.Map;
12+
import java.util.Objects;
1113
import java.util.Optional;
1214
import java.util.concurrent.*;
1315
import java.util.function.Function;
1416
import java.util.function.Predicate;
1517
import java.util.function.Supplier;
18+
import java.util.stream.Stream;
1619

1720
public class ImageRendererManager {
1821
private static final ExecutorService SINGLE_THREAD_EXECUTOR = Executors.newSingleThreadExecutor(task -> new Thread(task, "YACL Image Prep"));
1922

2023
private static final Map<ResourceLocation, CompletableFuture<ImageRenderer>> IMAGE_CACHE = new ConcurrentHashMap<>();
2124
static final Map<ResourceLocation, ImageRenderer> PRELOADED_IMAGE_CACHE = new ConcurrentHashMap<>();
2225

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(
2528
location -> location.getPath().endsWith(".webp"),
2629
AnimatedDynamicTextureImage::createWEBPFromTexture
27-
),
28-
new PreloadedImageFactory(
30+
) : null,
31+
YACLConfig.HANDLER.instance().preloadComplexImageFormats ? new PreloadedImageFactory(
2932
location -> location.getPath().endsWith(".gif"),
3033
AnimatedDynamicTextureImage::createGIFFromTexture
31-
)
32-
);
34+
) : null
35+
).filter(Objects::nonNull).toList();
3336

3437
public static <T extends ImageRenderer> Optional<T> getImage(ResourceLocation id) {
3538
if (PRELOADED_IMAGE_CACHE.containsKey(id)) {

src/main/java/dev/isxander/yacl3/platform/YACLConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class YACLConfig {
1313
.build())
1414
.build();
1515

16-
@SerialEntry
16+
@SerialEntry(comment = "Show the flashing colour picker hint (auto disables after first use)")
1717
public boolean showColorPickerIndicator = true;
18+
19+
@SerialEntry(comment = "Load .webp and .gif during Minecraft resource reload instead of on-demand (can decrease startup time)")
20+
public boolean preloadComplexImageFormats = false;
1821
}

0 commit comments

Comments
 (0)