Workaround for runtime resource packs that aren't thread safe

Related: https://github.com/Fuzss/diagonalfences/issues/38
This commit is contained in:
embeddedt 2023-05-05 11:27:07 -04:00
parent cc36e0c3f1
commit 367cc372c2
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -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<PackResources> allPackResources = new ArrayList<>(manager.listPacks().collect(Collectors.toList()));
Collections.reverse(allPackResources);
ObjectOpenHashSet<ResourceLocation> 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<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
for(ResourceLocation blockstate : blockStateFiles) {
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
List<Resource> 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<Resource> resources = manager.getResources(fileLocation);
for(Resource resource : resources) {
JsonParser parser = new JsonParser();
try {