From c1225f3876e21f0201ce8107a00b1db3ab9f78c7 Mon Sep 17 00:00:00 2001 From: David Quintana Date: Tue, 18 Dec 2018 21:48:39 +0100 Subject: [PATCH] Fix the path handling for mod jar resource packs. (#5228) --- .../fml/packs/ModFileResourcePack.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java index e3bab994b..f8ec48c41 100644 --- a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java +++ b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java @@ -76,10 +76,10 @@ public class ModFileResourcePack extends AbstractResourcePack { try { - Path inputPath = Paths.get(pathIn); - Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName()); + Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName()).toAbsolutePath(); + Path inputPath = root.resolve(pathIn); return Files.walk(root). - map(path -> root.relativize(path)). + map(path -> root.relativize(path.toAbsolutePath())). filter(path -> path.getNameCount() > 1 && path.getNameCount() - 1 <= maxDepth). // Make sure the depth is within bounds, ignoring domain filter(path -> !path.toString().endsWith(".mcmeta")). // Ignore .mcmeta files filter(path -> path.subpath(1, path.getNameCount()).startsWith(inputPath)). // Make sure the target path is inside this one (again ignoring domain) @@ -100,7 +100,12 @@ public class ModFileResourcePack extends AbstractResourcePack public Set getResourceNamespaces(ResourcePackType type) { try { - return Files.walk(modFile.getLocator().findPath(modFile, type.getDirectoryName()),1).map(p->p.getFileName().toString()).collect(Collectors.toSet()); + Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName()).toAbsolutePath(); + return Files.walk(root,1) + .map(path -> root.relativize(path.toAbsolutePath())) + .filter(path -> path.getNameCount() > 0) // skip the root entry + .map(p->p.toString().replaceAll("/$","")) // remove the trailing slash, if present + .collect(Collectors.toSet()); } catch (IOException e) {