|
5 | 5 | import com.google.common.collect.ImmutableList; |
6 | 6 | import com.google.common.collect.Sets; |
7 | 7 | import com.google.gson.*; |
| 8 | +import com.google.gson.stream.JsonReader; |
8 | 9 | import com.mojang.datafixers.util.Pair; |
9 | 10 | import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; |
10 | 11 | import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; |
@@ -55,6 +56,13 @@ public class ModelBakeryHelpers { |
55 | 56 | */ |
56 | 57 | public static final int MAX_MODEL_LIFETIME_SECS = 300; |
57 | 58 |
|
| 59 | + private static JsonElement parseStream(InputStream stream) { |
| 60 | + JsonParser parser = new JsonParser(); |
| 61 | + JsonReader jsonReader = new JsonReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); |
| 62 | + jsonReader.setLenient(true); |
| 63 | + return parser.parse(jsonReader); |
| 64 | + } |
| 65 | + |
58 | 66 | private static void gatherAdditionalViaManualScan(List<PackResources> untrustedPacks, Set<ResourceLocation> knownLocations, |
59 | 67 | Collection<ResourceLocation> uncertainLocations, String filePrefix) { |
60 | 68 | if(untrustedPacks.size() > 0) { |
@@ -161,7 +169,7 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR |
161 | 169 | for(Resource resource : resources) { |
162 | 170 | JsonParser parser = new JsonParser(); |
163 | 171 | try(InputStream stream = resource.open()) { |
164 | | - blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)))); |
| 172 | + blockStateLoadedFiles.add(Pair.of(blockstate, parseStream(stream))); |
165 | 173 | } catch(JsonParseException e) { |
166 | 174 | logOrSuppressError(blockstateErrors, "blockstate", blockstate, e); |
167 | 175 | } |
@@ -249,8 +257,7 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR |
249 | 257 | modelBytes.add(CompletableFuture.supplyAsync(() -> { |
250 | 258 | Optional<Resource> resource = manager.getResource(fileLocation); |
251 | 259 | try(InputStream stream = resource.orElseThrow().open()) { |
252 | | - JsonParser parser = new JsonParser(); |
253 | | - return Pair.of(model, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8))); |
| 260 | + return Pair.of(model, parseStream(stream)); |
254 | 261 | } catch(IOException | NoSuchElementException | JsonParseException e) { |
255 | 262 | logOrSuppressError(blockstateErrors, "model", fileLocation, e); |
256 | 263 | return Pair.of(fileLocation, null); |
|
0 commit comments