Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Version specific mods folder. #512

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/main/java/net/fabricmc/loader/impl/FabricLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,33 @@
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) {
throw new RuntimeException("Could not create directory " + path, e);
}
}

// 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!");
}
Expand Down