Allow corrupt JSONs when scanning models for textures
Fixes Hexerei textures being missing on 1.18
This commit is contained in:
parent
565cc23c6c
commit
dff181accb
|
|
@ -5,6 +5,7 @@ import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
|
@ -55,6 +56,13 @@ public class ModelBakeryHelpers {
|
||||||
*/
|
*/
|
||||||
public static final int MAX_MODEL_LIFETIME_SECS = 300;
|
public static final int MAX_MODEL_LIFETIME_SECS = 300;
|
||||||
|
|
||||||
|
private static JsonElement parseStream(InputStream stream) {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonReader jsonReader = new JsonReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
|
||||||
|
jsonReader.setLenient(true);
|
||||||
|
return parser.parse(jsonReader);
|
||||||
|
}
|
||||||
|
|
||||||
private static void gatherAdditionalViaManualScan(List<PackResources> untrustedPacks, Set<ResourceLocation> knownLocations,
|
private static void gatherAdditionalViaManualScan(List<PackResources> untrustedPacks, Set<ResourceLocation> knownLocations,
|
||||||
Collection<ResourceLocation> uncertainLocations, String filePrefix) {
|
Collection<ResourceLocation> uncertainLocations, String filePrefix) {
|
||||||
if(untrustedPacks.size() > 0) {
|
if(untrustedPacks.size() > 0) {
|
||||||
|
|
@ -166,9 +174,8 @@ public class ModelBakeryHelpers {
|
||||||
blockStateData.add(CompletableFuture.runAsync(() -> {
|
blockStateData.add(CompletableFuture.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
for(Resource resource : resources) {
|
for(Resource resource : resources) {
|
||||||
JsonParser parser = new JsonParser();
|
|
||||||
try {
|
try {
|
||||||
blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))));
|
blockStateLoadedFiles.add(Pair.of(blockstate, parseStream(resource.getInputStream())));
|
||||||
} catch(JsonParseException e) {
|
} catch(JsonParseException e) {
|
||||||
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
|
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -257,8 +264,7 @@ public class ModelBakeryHelpers {
|
||||||
ResourceLocation fileLocation = new ResourceLocation(model.getNamespace(), "models/" + model.getPath() + ".json");
|
ResourceLocation fileLocation = new ResourceLocation(model.getNamespace(), "models/" + model.getPath() + ".json");
|
||||||
modelBytes.add(CompletableFuture.supplyAsync(() -> {
|
modelBytes.add(CompletableFuture.supplyAsync(() -> {
|
||||||
try(Resource resource = manager.getResource(fileLocation)) {
|
try(Resource resource = manager.getResource(fileLocation)) {
|
||||||
JsonParser parser = new JsonParser();
|
return Pair.of(model, parseStream(resource.getInputStream()));
|
||||||
return Pair.of(model, parser.parse(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)));
|
|
||||||
} catch(IOException | JsonParseException e) {
|
} catch(IOException | JsonParseException e) {
|
||||||
logOrSuppressError(blockstateErrors, "model", fileLocation, e);
|
logOrSuppressError(blockstateErrors, "model", fileLocation, e);
|
||||||
return Pair.of(fileLocation, null);
|
return Pair.of(fileLocation, null);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user