|
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) { |
@@ -166,9 +174,8 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR |
166 | 174 | blockStateData.add(CompletableFuture.runAsync(() -> { |
167 | 175 | try { |
168 | 176 | for(Resource resource : resources) { |
169 | | - JsonParser parser = new JsonParser(); |
170 | 177 | try { |
171 | | - blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)))); |
| 178 | + blockStateLoadedFiles.add(Pair.of(blockstate, parseStream(resource.getInputStream()))); |
172 | 179 | } catch(JsonParseException e) { |
173 | 180 | logOrSuppressError(blockstateErrors, "blockstate", blockstate, e); |
174 | 181 | } finally { |
@@ -257,8 +264,7 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR |
257 | 264 | ResourceLocation fileLocation = new ResourceLocation(model.getNamespace(), "models/" + model.getPath() + ".json"); |
258 | 265 | modelBytes.add(CompletableFuture.supplyAsync(() -> { |
259 | 266 | try(Resource resource = manager.getResource(fileLocation)) { |
260 | | - JsonParser parser = new JsonParser(); |
261 | | - return Pair.of(model, parser.parse(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))); |
| 267 | + return Pair.of(model, parseStream(resource.getInputStream())); |
262 | 268 | } catch(IOException | JsonParseException e) { |
263 | 269 | logOrSuppressError(blockstateErrors, "model", fileLocation, e); |
264 | 270 | return Pair.of(fileLocation, null); |
|
0 commit comments