From 75a7b6ee2ee0a15293fcccdb54bedd35f7f782c4 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 11 Sep 2021 18:57:44 +0200 Subject: [PATCH 1/2] Add second level version specific mods folder --- .../java/net/fabricmc/loader/impl/FabricLoaderImpl.java | 5 ++++- .../impl/discovery/DirectoryModCandidateFinder.java | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java index d8efdf9a4..4aaaf42cc 100644 --- a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java @@ -190,9 +190,12 @@ private void setup() throws ModResolutionException { boolean remapRegularMods = isDevelopmentEnvironment(); ModDiscoverer discoverer = new ModDiscoverer(); discoverer.addCandidateFinder(new ClasspathModCandidateFinder()); - discoverer.addCandidateFinder(new DirectoryModCandidateFinder(gameDir.resolve("mods"), remapRegularMods)); discoverer.addCandidateFinder(new ArgumentModCandidateFinder(remapRegularMods)); + Path modsFolder = gameDir.resolve("mods"); + discoverer.addCandidateFinder(new DirectoryModCandidateFinder(modsFolder, remapRegularMods, true)); + discoverer.addCandidateFinder(new DirectoryModCandidateFinder(modsFolder.resolve(getGameProvider().getNormalizedGameVersion()), remapRegularMods, false)); + modCandidates = discoverer.discoverMods(this); modCandidates = ModResolver.resolve(modCandidates); diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java index eefcd4989..bb7dbac6e 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java @@ -31,15 +31,21 @@ public class DirectoryModCandidateFinder implements ModCandidateFinder { private final Path path; private final boolean requiresRemap; + private final boolean shouldCreateFolder; public DirectoryModCandidateFinder(Path path, boolean requiresRemap) { + this(path, requiresRemap, true); + } + + public DirectoryModCandidateFinder(Path path, boolean requiresRemap, boolean shouldCreateFolder) { this.path = path; this.requiresRemap = requiresRemap; + this.shouldCreateFolder = shouldCreateFolder; } @Override public void findCandidates(ModCandidateConsumer out) { - if (!Files.exists(path)) { + if (shouldCreateFolder && !Files.exists(path)) { try { Files.createDirectory(path); } catch (IOException e) { From 101a496eeb88f63d89b26022013bca9513f0a4b0 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 11 Sep 2021 19:08:27 +0200 Subject: [PATCH 2/2] Add a statement to skip the search for mods if the folder does not exist. --- .../loader/impl/discovery/DirectoryModCandidateFinder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java index bb7dbac6e..d7c5e4e0b 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/DirectoryModCandidateFinder.java @@ -53,6 +53,11 @@ public void findCandidates(ModCandidateConsumer out) { } } + // If the folder does not exist at this point it shouldn't be searched for mods + if (!Files.exists(path)) { + return; + } + if (!Files.isDirectory(path)) { throw new RuntimeException(path + " is not a directory!"); }