/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.gson.JsonObject * com.google.gson.JsonParseException * com.mojang.serialization.DynamicOps * com.mojang.serialization.JsonOps */ package net.minecraft.server.packs.resources; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.JsonOps; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import net.minecraft.server.packs.metadata.MetadataSectionType; import net.minecraft.server.packs.resources.IoSupplier; import net.minecraft.util.GsonHelper; public interface ResourceMetadata { public static final ResourceMetadata EMPTY = new ResourceMetadata(){ @Override public Optional getSection(MetadataSectionType serializer) { return Optional.empty(); } }; public static final IoSupplier EMPTY_SUPPLIER = () -> EMPTY; public static ResourceMetadata fromJsonStream(InputStream inputStream) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));){ final JsonObject metadata = GsonHelper.parse(reader); ResourceMetadata resourceMetadata = new ResourceMetadata(){ @Override public Optional getSection(MetadataSectionType serializer) { String name = serializer.name(); if (metadata.has(name)) { Object section = serializer.codec().parse((DynamicOps)JsonOps.INSTANCE, (Object)metadata.get(name)).getOrThrow(JsonParseException::new); return Optional.of(section); } return Optional.empty(); } }; return resourceMetadata; } } public Optional getSection(MetadataSectionType var1); default public Optional> getTypedSection(MetadataSectionType type) { return this.getSection(type).map(type::withValue); } default public List> getTypedSections(Collection> types) { return types.stream().map(this::getTypedSection).flatMap(Optional::stream).collect(Collectors.toUnmodifiableList()); } }