Workaround for runtime resource packs that aren't thread safe
Related: https://github.com/Fuzss/diagonalfences/issues/38
This commit is contained in:
parent
cc36e0c3f1
commit
367cc372c2
|
|
@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.Property;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -97,6 +98,12 @@ public class ModelBakeryHelpers {
|
||||||
List<PackResources> allPackResources = new ArrayList<>(manager.listPacks().collect(Collectors.toList()));
|
List<PackResources> allPackResources = new ArrayList<>(manager.listPacks().collect(Collectors.toList()));
|
||||||
Collections.reverse(allPackResources);
|
Collections.reverse(allPackResources);
|
||||||
ObjectOpenHashSet<ResourceLocation> allAvailableModels = new ObjectOpenHashSet<>(), allAvailableStates = new ObjectOpenHashSet<>();
|
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 -> {
|
allPackResources.removeIf(pack -> {
|
||||||
if(isTrustedPack.test(pack)) {
|
if(isTrustedPack.test(pack)) {
|
||||||
for(String namespace : pack.getNamespaces(PackType.CLIENT_RESOURCES)) {
|
for(String namespace : pack.getNamespaces(PackType.CLIENT_RESOURCES)) {
|
||||||
|
|
@ -124,10 +131,18 @@ public class ModelBakeryHelpers {
|
||||||
ConcurrentLinkedQueue<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
|
ConcurrentLinkedQueue<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
|
||||||
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
|
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
|
||||||
for(ResourceLocation blockstate : blockStateFiles) {
|
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(() -> {
|
blockStateData.add(CompletableFuture.runAsync(() -> {
|
||||||
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
|
|
||||||
try {
|
try {
|
||||||
List<Resource> resources = manager.getResources(fileLocation);
|
|
||||||
for(Resource resource : resources) {
|
for(Resource resource : resources) {
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user