Search in sources :

Example 1 with PackType

use of net.minecraft.server.packs.PackType in project MinecraftForge by MinecraftForge.

the class PathResourcePack method getResources.

@Override
public Collection<ResourceLocation> getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<String> filter) {
    try {
        Path root = resolve(type.getDirectory(), resourceNamespace).toAbsolutePath();
        Path inputPath = root.getFileSystem().getPath(pathIn);
        return Files.walk(root).map(root::relativize).filter(path -> path.getNameCount() <= maxDepth && !path.toString().endsWith(".mcmeta") && path.startsWith(inputPath)).filter(path -> filter.test(path.getFileName().toString())).map(path -> new ResourceLocation(resourceNamespace, Joiner.on('/').join(path))).collect(Collectors.toList());
    } catch (IOException e) {
        return Collections.emptyList();
    }
}
Also used : Path(java.nio.file.Path) ResourceLocation(net.minecraft.resources.ResourceLocation) AbstractPackResources(net.minecraft.server.packs.AbstractPackResources) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) IOException(java.io.IOException) PackType(net.minecraft.server.packs.PackType) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Locale(java.util.Locale) Path(java.nio.file.Path) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) ResourceLocation(net.minecraft.resources.ResourceLocation) IOException(java.io.IOException)

Example 2 with PackType

use of net.minecraft.server.packs.PackType in project MinecraftForge by MinecraftForge.

the class DelegatingResourcePack method buildNamespaceMap.

private Map<String, List<PackResources>> buildNamespaceMap(PackType type, List<PackResources> packList) {
    Map<String, List<PackResources>> map = new HashMap<>();
    for (PackResources pack : packList) {
        for (String namespace : pack.getNamespaces(type)) {
            map.computeIfAbsent(namespace, k -> new ArrayList<>()).add(pack);
        }
    }
    map.replaceAll((k, list) -> ImmutableList.copyOf(list));
    return ImmutableMap.copyOf(map);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) AbstractPackResources(net.minecraft.server.packs.AbstractPackResources) ResourcePackFileNotFoundException(net.minecraft.server.packs.ResourcePackFileNotFoundException) java.util(java.util) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) IOException(java.io.IOException) MetadataSectionSerializer(net.minecraft.server.packs.metadata.MetadataSectionSerializer) PackType(net.minecraft.server.packs.PackType) Collectors(java.util.stream.Collectors) File(java.io.File) PackMetadataSection(net.minecraft.server.packs.metadata.pack.PackMetadataSection) ImmutableList(com.google.common.collect.ImmutableList) PackResources(net.minecraft.server.packs.PackResources) InputStream(java.io.InputStream) ImmutableList(com.google.common.collect.ImmutableList) AbstractPackResources(net.minecraft.server.packs.AbstractPackResources) PackResources(net.minecraft.server.packs.PackResources)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 AbstractPackResources (net.minecraft.server.packs.AbstractPackResources)2 PackType (net.minecraft.server.packs.PackType)2 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileNotFoundException (java.io.FileNotFoundException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 java.util (java.util)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Locale (java.util.Locale)1 Set (java.util.Set)1