/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.gson.JsonObject * com.mojang.logging.LogUtils * com.mojang.serialization.DynamicOps * com.mojang.serialization.JsonOps * org.jspecify.annotations.Nullable * org.slf4j.Logger */ package net.minecraft.server.packs; import com.google.gson.JsonObject; import com.mojang.logging.LogUtils; 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 net.minecraft.server.packs.PackLocationInfo; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.metadata.MetadataSectionType; import net.minecraft.server.packs.resources.IoSupplier; import net.minecraft.util.GsonHelper; import org.jspecify.annotations.Nullable; import org.slf4j.Logger; public abstract class AbstractPackResources implements PackResources { private static final Logger LOGGER = LogUtils.getLogger(); private final PackLocationInfo location; protected AbstractPackResources(PackLocationInfo location) { this.location = location; } @Override public @Nullable T getMetadataSection(MetadataSectionType metadataSerializer) throws IOException { IoSupplier metadata = this.getRootResource("pack.mcmeta"); if (metadata == null) { return null; } try (InputStream resource = metadata.get();){ T t = AbstractPackResources.getMetadataFromStream(metadataSerializer, resource, this.location); return t; } } public static @Nullable T getMetadataFromStream(MetadataSectionType serializer, InputStream stream, PackLocationInfo location) { JsonObject metadata; try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));){ metadata = GsonHelper.parse(reader); } catch (Exception e) { LOGGER.error("Couldn't load {} {} metadata: {}", new Object[]{location.id(), serializer.name(), e.getMessage()}); return null; } if (!metadata.has(serializer.name())) { return null; } return serializer.codec().parse((DynamicOps)JsonOps.INSTANCE, (Object)metadata.get(serializer.name())).ifError(error -> LOGGER.error("Couldn't load {} {} metadata: {}", new Object[]{location.id(), serializer.name(), error.message()})).result().orElse(null); } @Override public PackLocationInfo location() { return this.location; } }