diff --git a/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/PathResourcePackMixin.java b/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/PathResourcePackMixin.java index c9a84dd6..53236ea6 100644 --- a/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/PathResourcePackMixin.java +++ b/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/PathResourcePackMixin.java @@ -6,6 +6,7 @@ import net.minecraft.server.packs.PackType; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.loading.moddiscovery.ModFile; import net.minecraftforge.resource.PathResourcePack; +import org.apache.commons.lang3.tuple.Triple; import org.embeddedt.modernfix.ModernFix; import org.embeddedt.modernfix.util.FileUtil; import org.spongepowered.asm.mixin.Final; @@ -35,7 +36,7 @@ public abstract class PathResourcePackMixin { @Shadow @Final private String packName; @Shadow @Final private Path source; private EnumMap> namespacesByType; - private EnumMap>>> rootListingByNamespaceAndType; + private EnumMap>>> rootListingByNamespaceAndType; private boolean hasGeneratedListings; private Set containedPaths; @@ -54,22 +55,22 @@ public abstract class PathResourcePackMixin { synchronized (this) { if(hasGeneratedListings) return; - EnumMap>>> rootListingByNamespaceAndType = new EnumMap<>(PackType.class); + EnumMap>>> rootListingByNamespaceAndType = new EnumMap<>(PackType.class); HashSet containedPaths = new HashSet<>(); for(PackType type : PackType.values()) { Set namespaces = this.getNamespaces(type); - HashMap>> rootListingForNamespaces = new HashMap<>(); + HashMap>> rootListingForNamespaces = new HashMap<>(); for(String namespace : namespaces) { try { Path root = this.resolve(type.getDirectory(), namespace).toAbsolutePath(); try (Stream stream = Files.walk(root)) { - ArrayList> rootListingPaths = new ArrayList<>(); + ArrayList> rootListingPaths = new ArrayList<>(); stream .map(path -> root.relativize(path.toAbsolutePath())) .filter(this::isValidCachedResourcePath) .forEach(path -> { if(!path.toString().endsWith(".mcmeta")) - rootListingPaths.add(Pair.of(path, slashJoiner.join(path))); + rootListingPaths.add(Triple.of(path.getNameCount(), path.getFileName().toString(), slashJoiner.join(path))); String mergedPath = slashJoiner.join(type.getDirectory(), namespace, path); containedPaths.add(mergedPath); }); @@ -89,6 +90,8 @@ public abstract class PathResourcePackMixin { } private boolean isValidCachedResourcePath(Path path) { + if(path.getFileName() == null) + return false; String str = path.toString(); for(int i = 0; i < str.length(); i++) { if(!ResourceLocation.validPathChar(str.charAt(i))) { @@ -134,13 +137,13 @@ public abstract class PathResourcePackMixin { pathIn = pathIn + "/"; final String testPath = pathIn; Collection cachedListing = this.rootListingByNamespaceAndType.get(type).getOrDefault(resourceNamespace, Collections.emptyList()).stream(). - filter(path -> path.getFirst().getNameCount() <= maxDepth). // Make sure the depth is within bounds - filter(path -> path.getSecond().startsWith(testPath)). // Make sure the target path is inside this one - filter(path -> filter.test(path.getFirst().getFileName().toString())). // Test the file name against the predicate + filter(path -> path.getLeft() <= maxDepth). // Make sure the depth is within bounds + filter(path -> path.getRight().startsWith(testPath)). // Make sure the target path is inside this one + filter(path -> filter.test(path.getMiddle())). // 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(resourceNamespace, path.getSecond())). + map(path -> new ResourceLocation(resourceNamespace, path.getRight())). collect(Collectors.toList()); cir.setReturnValue(cachedListing); }