use of net.minecraft.resource.ResourceType in project fabric by FabricMC.
the class ModNioResourcePack method findResources.
@Override
public Collection<Identifier> findResources(ResourceType type, String path, int depth, Predicate<String> predicate) {
List<Identifier> ids = new ArrayList<>();
String nioPath = path.replace("/", separator);
for (String namespace : getNamespaces(type)) {
Path namespacePath = getPath(type.getName() + "/" + namespace);
if (namespacePath != null) {
Path searchPath = namespacePath.resolve(nioPath).toAbsolutePath().normalize();
if (Files.exists(searchPath)) {
try {
Files.walk(searchPath, depth).filter(Files::isRegularFile).filter((p) -> {
String filename = p.getFileName().toString();
return !filename.endsWith(".mcmeta") && predicate.test(filename);
}).map(namespacePath::relativize).map((p) -> p.toString().replace(separator, "/")).forEach((s) -> {
try {
ids.add(new Identifier(namespace, s));
} catch (InvalidIdentifierException e) {
LOGGER.error(e.getMessage());
}
});
} catch (IOException e) {
LOGGER.warn("findResources at " + path + " in namespace " + namespace + ", mod " + modInfo.getId() + " failed!", e);
}
}
}
}
return ids;
}
use of net.minecraft.resource.ResourceType in project quilt-standard-libraries by QuiltMC.
the class ModNioResourcePack method findResources.
@Override
public Collection<Identifier> findResources(ResourceType type, String namespace, String path, int depth, Predicate<String> pathFilter) {
var ids = new ArrayList<Identifier>();
String nioPath = path.replace("/", separator);
Path namespacePath = this.getPath(type.getDirectory() + "/" + namespace);
if (namespacePath != null) {
Path searchPath = namespacePath.resolve(nioPath).toAbsolutePath().normalize();
if (Files.exists(searchPath)) {
try {
Files.walk(searchPath, depth).filter(Files::isRegularFile).filter((p) -> {
String filename = p.getFileName().toString();
return !filename.endsWith(".mcmeta") && pathFilter.test(filename);
}).map(namespacePath::relativize).map((p) -> p.toString().replace(separator, "/")).forEach((s) -> {
try {
ids.add(new Identifier(namespace, s));
} catch (InvalidIdentifierException e) {
LOGGER.error(e.getMessage());
}
});
} catch (IOException e) {
LOGGER.warn("findResources at " + path + " in namespace " + namespace + ", mod " + this.modInfo.getId() + " failed!", e);
}
}
}
return ids;
}
Aggregations