Skip to content

Commit

Permalink
Allow replacing the default mod directory via fabric.modsFolder (#850)
Browse files Browse the repository at this point in the history
* Allow replacing the default mod directory via fabric.modDir

* Apply requested changes

* Fix checkstyle failures
  • Loading branch information
IMS212 authored Nov 13, 2023
1 parent 41e71f0 commit a460fb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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();
}

0 comments on commit a460fb2

Please sign in to comment.