Merge 1.18 into 1.19.2

This commit is contained in:
embeddedt 2023-07-15 15:07:17 -04:00
commit 09d24c542e
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -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) {
@ -161,7 +169,7 @@ public class ModelBakeryHelpers {
for(Resource resource : resources) { for(Resource resource : resources) {
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
try(InputStream stream = resource.open()) { try(InputStream stream = resource.open()) {
blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)))); blockStateLoadedFiles.add(Pair.of(blockstate, parseStream(stream)));
} catch(JsonParseException e) { } catch(JsonParseException e) {
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e); logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
} }
@ -249,8 +257,7 @@ public class ModelBakeryHelpers {
modelBytes.add(CompletableFuture.supplyAsync(() -> { modelBytes.add(CompletableFuture.supplyAsync(() -> {
Optional<Resource> resource = manager.getResource(fileLocation); Optional<Resource> resource = manager.getResource(fileLocation);
try(InputStream stream = resource.orElseThrow().open()) { try(InputStream stream = resource.orElseThrow().open()) {
JsonParser parser = new JsonParser(); return Pair.of(model, parseStream(stream));
return Pair.of(model, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)));
} catch(IOException | NoSuchElementException | JsonParseException e) { } catch(IOException | NoSuchElementException | JsonParseException e) {
logOrSuppressError(blockstateErrors, "model", fileLocation, e); logOrSuppressError(blockstateErrors, "model", fileLocation, e);
return Pair.of(fileLocation, null); return Pair.of(fileLocation, null);