package net.minecraft.client.resources;

import java.util.stream.Stream;
import java.nio.file.Path;
import java.util.Collections;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.nio.file.LinkOption;
import java.util.List;
import java.nio.file.Files;
import java.nio.file.FileVisitOption;
import java.util.Collection;
import java.util.function.Predicate;
import net.minecraft.resources.ResourceLocation;
import java.io.File;

public class DirectAssetIndex extends AssetIndex {
    private final File assetsDirectory;
    
    public DirectAssetIndex(final File file) {
        this.assetsDirectory = file;
    }
    
    @Override
    public File getFile(final ResourceLocation uh) {
        return new File(this.assetsDirectory, uh.toString().replace(':', '/'));
    }
    
    @Override
    public File getRootFile(final String string) {
        return new File(this.assetsDirectory, string);
    }
    
    @Override
    public Collection<ResourceLocation> getFiles(final String string1, final String string2, final int integer, final Predicate<String> predicate) {
        final Path path4 = this.assetsDirectory.toPath().resolve(string2);
        try (final Stream<Path> stream7 = Files.walk(path4.resolve(string1), integer)) {
            return stream7.filter(path -> Files.isRegularFile(path)).filter(path -> !path.endsWith(".mcmeta")).filter(path -> predicate.test(path.getFileName().toString())).map(path3 -> new ResourceLocation(string2, path4.relativize(path3).toString().replaceAll("\\\\", "/"))).collect(Collectors.toList());
        }
        catch (NoSuchFileException ex) {}
        catch (IOException iOException7) {
            DirectAssetIndex.LOGGER.warn("Unable to getFiles on {}", string1, iOException7);
        }
        return Collections.emptyList();
    }
}
