From 367cc372c27fb21cd07dfc80536d394ce8091604 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Fri, 5 May 2023 11:27:07 -0400 Subject: [PATCH] Workaround for runtime resource packs that aren't thread safe Related: https://github.com/Fuzss/diagonalfences/issues/38 --- .../dynamicresources/ModelBakeryHelpers.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelBakeryHelpers.java b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelBakeryHelpers.java index 12ef8d8b..e0df2a26 100644 --- a/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelBakeryHelpers.java +++ b/common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelBakeryHelpers.java @@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.Property; import org.embeddedt.modernfix.ModernFix; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.*; @@ -97,6 +98,12 @@ public class ModelBakeryHelpers { List allPackResources = new ArrayList<>(manager.listPacks().collect(Collectors.toList())); Collections.reverse(allPackResources); ObjectOpenHashSet allAvailableModels = new ObjectOpenHashSet<>(), allAvailableStates = new ObjectOpenHashSet<>(); + /* try to fix CME in some runtime packs by forcing generation */ + for(PackResources pack : allPackResources) { + try(InputStream stream = pack.getResource(PackType.CLIENT_RESOURCES, new ResourceLocation("modernfix", "dummy.json"))) { + } catch(Exception ignored) { + } + } allPackResources.removeIf(pack -> { if(isTrustedPack.test(pack)) { for(String namespace : pack.getNamespaces(PackType.CLIENT_RESOURCES)) { @@ -124,10 +131,18 @@ public class ModelBakeryHelpers { ConcurrentLinkedQueue> blockStateLoadedFiles = new ConcurrentLinkedQueue<>(); List> blockStateData = new ArrayList<>(); for(ResourceLocation blockstate : blockStateFiles) { + ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json"); + List resources; + try { + resources = manager.getResources(fileLocation); + if(resources.isEmpty()) + continue; + } catch(IOException e) { + logOrSuppressError(blockstateErrors, "blockstate", blockstate, e); + continue; + } blockStateData.add(CompletableFuture.runAsync(() -> { - ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json"); try { - List resources = manager.getResources(fileLocation); for(Resource resource : resources) { JsonParser parser = new JsonParser(); try {