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

feat: child folder mod locator #294

Open
wants to merge 6 commits into
base: experimental/foundation
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
7 changes: 5 additions & 2 deletions src/main/java/net/minecraftforge/common/ForgeEarlyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class ForgeEarlyConfig {
public static String COCOA_FRAME_NAME = "minecraft";

public static String CONFIG_ANY_TIME_VERSION = "3.0";

public static String MIXIN_BOOTER_VERSION = "10.5";

@Config.Comment("""
Expand All @@ -82,6 +83,8 @@ public static class CategoryOpenAlContext{
@Config.Comment("Enable HRTF sound support")
public boolean ENABLE_HRTF = false;
}



public static String[] DISABLED_MOD_FOLDER = new String[]{
"disabled", "optional"
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -42,9 +43,12 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import net.minecraftforge.common.ForgeEarlyConfig;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.artifact.versioning.ArtifactVersion;

Expand Down Expand Up @@ -474,7 +478,7 @@ else if (!list.contains(file))
continue;

FMLLog.log.info("Searching {} for mods", base.getAbsolutePath());
for (File f : base.listFiles(MOD_FILENAME_FILTER))
for (File f : scanningModFiles(base.toPath()))
{
if (!list.contains(f))
{
Expand All @@ -492,6 +496,22 @@ else if (!list.contains(file))
return list;
}

public static List<File> scanningModFiles(Path rootDir) {
try (Stream<Path> stream = java.nio.file.Files.walk(rootDir)) {
return stream
.filter(path -> {
Path parent = path.getParent();
return parent != null && !Arrays.stream(ForgeEarlyConfig.DISABLED_MOD_FOLDER).toList().contains(parent.getFileName().toString());
})
.filter(java.nio.file.Files::isRegularFile)
.map(Path::toFile)
.filter(File::isFile)
.collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException("Unable to scan mod folder", e);
}
}

public static Repository getDefaultRepo()
{
return libraries_dir;
Expand Down