From 89e8d2689e0e85f3f5862fb949b387fd1d4bcc98 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sat, 28 Oct 2023 19:27:37 -0700 Subject: [PATCH 1/3] Allow replacing the default mod directory via fabric.modDir --- src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java | 3 ++- .../java/net/fabricmc/loader/impl/util/SystemProperties.java | 2 ++ src/main/legacyJava/net/fabricmc/loader/FabricLoader.java | 4 +++- 3 files changed, 7 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 7abe5e02a..2b13bbf50 100644 --- a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -207,7 +208,7 @@ private void setup() throws ModResolutionException { ModDiscoverer discoverer = new ModDiscoverer(versionOverrides, depOverrides); discoverer.addCandidateFinder(new ClasspathModCandidateFinder()); - discoverer.addCandidateFinder(new DirectoryModCandidateFinder(gameDir.resolve("mods"), remapRegularMods)); + discoverer.addCandidateFinder(new DirectoryModCandidateFinder(System.getProperty(SystemProperties.MODS_DIRECTORY) != null ? Paths.get(System.getProperty(SystemProperties.MODS_DIRECTORY)) : gameDir.resolve("mods"), remapRegularMods)); discoverer.addCandidateFinder(new ArgumentModCandidateFinder(remapRegularMods)); Map> envDisabledMods = new HashMap<>(); diff --git a/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java index 5851e5dd7..1eb3b07d8 100644 --- a/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java +++ b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java @@ -36,6 +36,8 @@ public final class SystemProperties { public static final String ADD_MODS = "fabric.addMods"; // a comma-separated list of mod ids to disable, even if they're discovered. mostly useful for unit testing. public static final String DISABLE_MOD_IDS = "fabric.debug.disableModIds"; + // a path to a directory to replace the default mod search directory + public static final String MODS_DIRECTORY = "fabric.modDir"; // file containing the class path for in-dev runtime mod remapping public static final String REMAP_CLASSPATH_FILE = "fabric.remapClasspathFile"; // class path groups to map multiple class path entries to a mod (paths separated by path separator, groups by double path separator) diff --git a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java index 639dff4b6..16aee99a9 100644 --- a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java +++ b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java @@ -17,10 +17,12 @@ package net.fabricmc.loader; import java.io.File; +import java.nio.file.Paths; import java.util.Collection; import java.util.List; import net.fabricmc.loader.impl.FabricLoaderImpl; +import net.fabricmc.loader.impl.util.SystemProperties; /** * The main class for mod loading operations. @@ -37,7 +39,7 @@ public abstract class FabricLoader implements net.fabricmc.loader.api.FabricLoad public static final FabricLoader INSTANCE = FabricLoaderImpl.InitHelper.get(); public File getModsDirectory() { - return getGameDir().resolve("mods").toFile(); + return System.getProperty(SystemProperties.MODS_DIRECTORY) != null ? Paths.get(System.getProperty(SystemProperties.MODS_DIRECTORY)).toFile() : getGameDir().resolve("mods").toFile(); } @Override From eebe7f130388f1c02fcfb53b5440c999738a1338 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 29 Oct 2023 10:36:14 -0700 Subject: [PATCH 2/3] Apply requested changes --- .../java/net/fabricmc/loader/impl/FabricLoaderImpl.java | 9 ++++++++- .../net/fabricmc/loader/impl/util/SystemProperties.java | 4 ++-- .../legacyJava/net/fabricmc/loader/FabricLoader.java | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java index 2b13bbf50..8855dbbec 100644 --- a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java +++ b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java @@ -208,7 +208,7 @@ private void setup() throws ModResolutionException { ModDiscoverer discoverer = new ModDiscoverer(versionOverrides, depOverrides); discoverer.addCandidateFinder(new ClasspathModCandidateFinder()); - discoverer.addCandidateFinder(new DirectoryModCandidateFinder(System.getProperty(SystemProperties.MODS_DIRECTORY) != null ? Paths.get(System.getProperty(SystemProperties.MODS_DIRECTORY)) : gameDir.resolve("mods"), remapRegularMods)); + discoverer.addCandidateFinder(new DirectoryModCandidateFinder(getModsDirectory0(), remapRegularMods)); discoverer.addCandidateFinder(new ArgumentModCandidateFinder(remapRegularMods)); Map> envDisabledMods = new HashMap<>(); @@ -593,6 +593,13 @@ public String[] getLaunchArguments(boolean sanitize) { return getGameProvider().getLaunchArguments(sanitize); } + @Override + protected Path getModsDirectory0() { + String directory = System.getProperty(SystemProperties.MODS_FOLDER); + + return directory != null ? Paths.get(directory) : gameDir.resolve("mods"); + } + /** * Provides singleton for static init assignment regardless of load order. */ diff --git a/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java index 1eb3b07d8..d1179d952 100644 --- a/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java +++ b/src/main/java/net/fabricmc/loader/impl/util/SystemProperties.java @@ -32,12 +32,12 @@ public final class SystemProperties { public static final String LOG_FILE = "fabric.log.file"; // minimum log level for builtin log handler public static final String LOG_LEVEL = "fabric.log.level"; + // a path to a directory to replace the default mod search directory + public static final String MODS_FOLDER = "fabric.modsFolder"; // additional mods to load (path separator separated paths, @ prefix for meta-file with each line referencing an actual file) public static final String ADD_MODS = "fabric.addMods"; // a comma-separated list of mod ids to disable, even if they're discovered. mostly useful for unit testing. public static final String DISABLE_MOD_IDS = "fabric.debug.disableModIds"; - // a path to a directory to replace the default mod search directory - public static final String MODS_DIRECTORY = "fabric.modDir"; // file containing the class path for in-dev runtime mod remapping public static final String REMAP_CLASSPATH_FILE = "fabric.remapClasspathFile"; // class path groups to map multiple class path entries to a mod (paths separated by path separator, groups by double path separator) diff --git a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java index 16aee99a9..c57640ea4 100644 --- a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java +++ b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java @@ -17,6 +17,7 @@ package net.fabricmc.loader; import java.io.File; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; import java.util.List; @@ -39,7 +40,7 @@ public abstract class FabricLoader implements net.fabricmc.loader.api.FabricLoad public static final FabricLoader INSTANCE = FabricLoaderImpl.InitHelper.get(); public File getModsDirectory() { - return System.getProperty(SystemProperties.MODS_DIRECTORY) != null ? Paths.get(System.getProperty(SystemProperties.MODS_DIRECTORY)).toFile() : getGameDir().resolve("mods").toFile(); + return getModsDirectory0().toFile(); } @Override @@ -54,4 +55,6 @@ public Collection getModContainers() { public List getMods() { return (List) getAllMods(); } + + protected abstract Path getModsDirectory0(); } From 54498669604385df0088344c99cd740dd8faa7f2 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Sun, 29 Oct 2023 10:43:11 -0700 Subject: [PATCH 3/3] Fix checkstyle failures --- src/main/legacyJava/net/fabricmc/loader/FabricLoader.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java index c57640ea4..c2dc88610 100644 --- a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java +++ b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java @@ -18,12 +18,10 @@ import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collection; import java.util.List; import net.fabricmc.loader.impl.FabricLoaderImpl; -import net.fabricmc.loader.impl.util.SystemProperties; /** * The main class for mod loading operations.