From 1f16fc020406ff3234e38ff80ffa4a0f51cd33dd Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Wed, 10 May 2023 11:42:16 -0400 Subject: [PATCH] Move iteration later in texture atlas patch --- .../faster_texture_loading/TextureAtlasMixin.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_loading/TextureAtlasMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_loading/TextureAtlasMixin.java index b605365b..e32640ad 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_loading/TextureAtlasMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_loading/TextureAtlasMixin.java @@ -42,10 +42,13 @@ public abstract class TextureAtlasMixin { @Inject(method = "getBasicSpriteInfos", at = @At("HEAD")) private void loadImages(ResourceManager manager, Set imageLocations, CallbackInfoReturnable> cir) { usingFasterLoad = ModernFixPlatformHooks.isLoadingNormally(); + } + + @Redirect(method = "getBasicSpriteInfos", at = @At(value = "INVOKE", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;", ordinal = 0)) + private Iterator skipIteration(Set instance, ResourceManager manager, Set imageLocations) { // bail if Forge is erroring to avoid AT crashes - if(!usingFasterLoad) { - return; - } + if(!usingFasterLoad) + return instance.iterator(); List> futures = new ArrayList<>(); ConcurrentLinkedQueue results = new ConcurrentLinkedQueue<>(); for(ResourceLocation location : imageLocations) { @@ -72,11 +75,7 @@ public abstract class TextureAtlasMixin { } CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); storedResults = results; - } - - @Redirect(method = "getBasicSpriteInfos", at = @At(value = "INVOKE", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;", ordinal = 0)) - private Iterator skipIteration(Set instance) { - return usingFasterLoad ? Collections.emptyIterator() : instance.iterator(); + return Collections.emptyIterator(); } @Inject(method = "getBasicSpriteInfos", at = @At("RETURN"))