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

Conversation

Oganesson897
Copy link
Contributor

will not load child folder named optional or disabled
d50cfe1604b02e5e98226782606960fc

- will not load child folder named `optional` or `disabled`
@@ -492,6 +495,18 @@ else if (!list.contains(file))
return list;
}

private static void scanningChildFolder(File directory, List<File> list) {
if (directory.isDirectory() && !(directory.getName().toLowerCase().contains("optional") || directory.getName().toLowerCase().contains("disabled"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains ?, or equals "optional".equalsIgnoreCase(directory.getName())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to be strict about folder names

@@ -492,6 +495,18 @@ else if (!list.contains(file))
return list;
}

private static void scanningChildFolder(File directory, List<File> list) {
Copy link
Contributor

@Ecdcaeb Ecdcaeb Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scan the sub sub dir?
enable path?

sub sub
Supporting paths is useless, mods that need to do so will inject it themselves

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

@@ -469,12 +469,15 @@ else if (!list.contains(file))

for (String dir : new String[]{"mods", "mods" + File.separatorChar + ForgeVersion.mcVersion})
{
List<File> location = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return it instead of using it like this?

@Ecdcaeb
Copy link
Contributor

Ecdcaeb commented Feb 16, 2025

It is understandable that "disabled" is not loaded, but why is "optional" also considered.

@Oganesson897
Copy link
Contributor Author

It is understandable that "disabled" is not loaded, but why is "optional" also considered.

i will rewrite them all when i am home

@kappa-maintainer
Copy link
Collaborator

Maybe make the names configurable

@kappa-maintainer
Copy link
Collaborator

On a second thought, maybe make it configurable regex

@Oganesson897
Copy link
Contributor Author

On a second thought, maybe make it configurable regex

black/white list for scannable folder maybe

- removed sub-sub folder compatible
- add white/black list for special folder
FMLLog.log.info("Searching {} for mods", base.getAbsolutePath());
for (File f : base.listFiles(MOD_FILENAME_FILTER))
for (File f : location)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just inline the var

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth considering whether an API for file locator will be added in future, like IModFileCandidateLocator in FancyML

return stream
.filter(path -> {
Path parent = path.getParent();
return parent == null || (Arrays.stream(ForgeEarlyConfig.SPECIAL_MOD_FOLDER).toList().contains(parent.getFileName().toString()) && ForgeEarlyConfig.IS_WHITELIST);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the case be considered?

@@ -18,4 +18,9 @@ public class ForgeEarlyConfig {
public static String X11_CLASS_NAME = "minecraft";
public static String COCOA_FRAME_NAME = "minecraft";
public static String CONFIG_ANY_TIME_VERSION = "3.0";

public static String[] SPECIAL_MOD_FOLDER = new String[]{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would sub category be considered?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#294 (comment)
hope I am not mistaken.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#294 (comment) hope I am not mistaken.

I means config category.
ForgeEarlyConfig.modloading.disabledList

@Ecdcaeb
Copy link
Contributor

Ecdcaeb commented Feb 16, 2025

oh, my.error

return parent!= null && !("disabled".equalsIgnoreCase(parent.getFileName().toString()) || "optional".equalsIgnoreCase(parent.getFileName().toString()));

@kappa-maintainer
Copy link
Collaborator

Should write a proposal for this, I guess
Btw what's the point of white list? IMO blacklist is enough

- removed whitelist
- inline var
@Ecdcaeb
Copy link
Contributor

Ecdcaeb commented Feb 17, 2025

may crash?
parent != null

Copy link
Contributor

@Ecdcaeb Ecdcaeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, let’s resolve the conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants