diff --git a/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java b/src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java index 7abe5e02a..8855dbbec 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(getModsDirectory0(), remapRegularMods)); discoverer.addCandidateFinder(new ArgumentModCandidateFinder(remapRegularMods)); Map> envDisabledMods = new HashMap<>(); @@ -592,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 5851e5dd7..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,6 +32,8 @@ 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. diff --git a/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java b/src/main/legacyJava/net/fabricmc/loader/FabricLoader.java index 639dff4b6..c2dc88610 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.util.Collection; import java.util.List; @@ -37,7 +38,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 getModsDirectory0().toFile(); } @Override @@ -52,4 +53,6 @@ public Collection getModContainers() { public List getMods() { return (List) getAllMods(); } + + protected abstract Path getModsDirectory0(); }