Skip to content

Commit 9fcc1f5

Browse files
committed
Merge 1.16 into 1.18
2 parents a2eacc0 + dff181a commit 9fcc1f5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

common/src/main/java/org/embeddedt/modernfix/dynamicresources/ModelBakeryHelpers.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.common.collect.ImmutableList;
66
import com.google.common.collect.Sets;
77
import com.google.gson.*;
8+
import com.google.gson.stream.JsonReader;
89
import com.mojang.datafixers.util.Pair;
910
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
1011
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
@@ -55,6 +56,13 @@ public class ModelBakeryHelpers {
5556
*/
5657
public static final int MAX_MODEL_LIFETIME_SECS = 300;
5758

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+
5866
private static void gatherAdditionalViaManualScan(List<PackResources> untrustedPacks, Set<ResourceLocation> knownLocations,
5967
Collection<ResourceLocation> uncertainLocations, String filePrefix) {
6068
if(untrustedPacks.size() > 0) {
@@ -166,9 +174,8 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR
166174
blockStateData.add(CompletableFuture.runAsync(() -> {
167175
try {
168176
for(Resource resource : resources) {
169-
JsonParser parser = new JsonParser();
170177
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())));
172179
} catch(JsonParseException e) {
173180
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
174181
} finally {
@@ -257,8 +264,7 @@ public static void gatherModelMaterials(ResourceManager manager, Predicate<PackR
257264
ResourceLocation fileLocation = new ResourceLocation(model.getNamespace(), "models/" + model.getPath() + ".json");
258265
modelBytes.add(CompletableFuture.supplyAsync(() -> {
259266
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()));
262268
} catch(IOException | JsonParseException e) {
263269
logOrSuppressError(blockstateErrors, "model", fileLocation, e);
264270
return Pair.of(fileLocation, null);

0 commit comments

Comments
 (0)