Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow replacing the default mod directory via fabric.modsFolder #850

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Set<ModCandidate>> envDisabledMods = new HashMap<>();
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion src/main/legacyJava/net/fabricmc/loader/FabricLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -52,4 +53,6 @@ public Collection<ModContainer> getModContainers() {
public List<ModContainer> getMods() {
return (List) getAllMods();
}

protected abstract Path getModsDirectory0();
}