package net.minecraft.server.packs; import com.google.common.collect.Lists; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.metadata.MetadataSectionType; import net.minecraft.server.packs.resources.IoSupplier; import org.jetbrains.annotations.Nullable; public class CompositePackResources implements PackResources { private final PackResources primaryPackResources; private final List packResourcesStack; public CompositePackResources(PackResources primaryPackResources, List packResourcesStack) { this.primaryPackResources = primaryPackResources; List list = new ArrayList(packResourcesStack.size() + 1); list.addAll(Lists.reverse(packResourcesStack)); list.add(primaryPackResources); this.packResourcesStack = List.copyOf(list); } @Nullable @Override public IoSupplier getRootResource(String... elements) { return this.primaryPackResources.getRootResource(elements); } @Nullable @Override public IoSupplier getResource(PackType packType, ResourceLocation location) { for (PackResources packResources : this.packResourcesStack) { IoSupplier ioSupplier = packResources.getResource(packType, location); if (ioSupplier != null) { return ioSupplier; } } return null; } @Override public void listResources(PackType packType, String namespace, String path, PackResources.ResourceOutput resourceOutput) { Map> map = new HashMap(); for (PackResources packResources : this.packResourcesStack) { packResources.listResources(packType, namespace, path, map::putIfAbsent); } map.forEach(resourceOutput); } @Override public Set getNamespaces(PackType type) { Set set = new HashSet(); for (PackResources packResources : this.packResourcesStack) { set.addAll(packResources.getNamespaces(type)); } return set; } @Nullable @Override public T getMetadataSection(MetadataSectionType type) throws IOException { return this.primaryPackResources.getMetadataSection(type); } @Override public PackLocationInfo location() { return this.primaryPackResources.location(); } @Override public void close() { this.packResourcesStack.forEach(PackResources::close); } }