From 74703e2a601e7e7e51f0ddb4cebd8ceb3c02b213 Mon Sep 17 00:00:00 2001 From: tterrag Date: Thu, 11 Oct 2018 17:50:42 -0400 Subject: [PATCH] Fix mod asset loading --- .../fml/loading/FMLCommonLaunchHandler.java | 2 +- .../fml/packs/ModFileResourcePack.java | 22 ++++++++++++++----- .../fml/packs/ResourcePackLoader.java | 7 ++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java b/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java index 76ad5bef2..632558b2c 100644 --- a/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java +++ b/src/main/java/net/minecraftforge/fml/loading/FMLCommonLaunchHandler.java @@ -75,7 +75,7 @@ public abstract class FMLCommonLaunchHandler if (uri.getSchemeSpecificPart().contains("!")) { path = Paths.get(new URI(uri.getSchemeSpecificPart().split("!")[0])); } else { - path = Paths.get(new URI("file:///"+uri.getSchemeSpecificPart().substring(0, uri.getSchemeSpecificPart().length()-className.length()))); + path = Paths.get(new URI("file://"+uri.getSchemeSpecificPart().substring(0, uri.getSchemeSpecificPart().length()-className.length()))); } LOGGER.debug(CORE, "Found JAR {} at path {}", jarName, path.toString()); return path; diff --git a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java index 41b172195..e3bab994b 100644 --- a/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java +++ b/src/main/java/net/minecraftforge/fml/packs/ModFileResourcePack.java @@ -28,11 +28,16 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; import java.util.Collections; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import com.google.common.base.Joiner; public class ModFileResourcePack extends AbstractResourcePack { @@ -71,11 +76,18 @@ public class ModFileResourcePack extends AbstractResourcePack { try { - return Files.walk(modFile.getLocator().findPath(modFile, type.getDirectoryName())). - filter(path -> !path.toString().endsWith(".mcmeta")). - filter(path -> path.getNameCount() > 2 && pathIn.equals(path.getName(2).toString())). - filter(path -> filter.test(path.subpath(3, Math.min(maxDepth+3, path.getNameCount())).toString())). - map(path -> new ResourceLocation(path.getName(1).toString(),path.subpath(3,Math.min(maxDepth+3, path.getNameCount())).toString())). + Path inputPath = Paths.get(pathIn); + Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName()); + return Files.walk(root). + map(path -> root.relativize(path)). + 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) + filter(path -> filter.test(path.getFileName().toString())). // Test the file name against the predicate + // Finally we need to form the RL, so use the first name as the domain, and the rest as the path + // It is VERY IMPORTANT that we do not rely on Path.toString as this is inconsistent between operating systems + // Join the path names ourselves to force forward slashes + map(path -> new ResourceLocation(path.getName(0).toString(), Joiner.on('/').join(path.subpath(1,Math.min(maxDepth, path.getNameCount()))))). collect(Collectors.toList()); } catch (IOException e) diff --git a/src/main/java/net/minecraftforge/fml/packs/ResourcePackLoader.java b/src/main/java/net/minecraftforge/fml/packs/ResourcePackLoader.java index a3d53f632..6ffe37ef0 100644 --- a/src/main/java/net/minecraftforge/fml/packs/ResourcePackLoader.java +++ b/src/main/java/net/minecraftforge/fml/packs/ResourcePackLoader.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.Map; +import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; @@ -111,6 +112,12 @@ public class ResourcePackLoader public void addPackInfosToMap(Map packList, ResourcePackInfo.IFactory factory) { packList.put("forge", ResourcePackInfo.func_195793_a("forge", true, ()->forgePack, factory, ResourcePackInfo.Priority.BOTTOM)); + for (Entry e : modResourcePacks.entrySet()) + { + String name = "modfile/" + e.getKey().getFileName(); + packList.put(name, ResourcePackInfo.func_195793_a(name, true, ()->e.getValue(), factory, ResourcePackInfo.Priority.BOTTOM)); + } } + } }