Skip to content

Commit

Permalink
Take in the fabric argument so we can handle mod loaders in a similar…
Browse files Browse the repository at this point in the history
… way
  • Loading branch information
Novampr committed Oct 13, 2024
1 parent 441cc5f commit 502660a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
public class Main {
public static String mcVersion; // DL: Make Minecraft version public
public static String gameDir; // DL: Grant access to the game directory
public static boolean coreModsOnly;
public static String modDirectory;

public static void main(String[] args) throws Throwable {
// --fml.neoForgeVersion 20.2.20-beta --fml.fmlVersion 1.0.2 --fml.mcVersion 1.20.2 --fml.neoFormVersion 20231019.002635 --launchTarget forgeclient

List<String> argsList = Stream.of(args).collect(Collectors.toList());
List<String> argsList = Stream.of(args).toList();

gameDir = argsList.get(argsList.indexOf("--gameDir") + 1); // DL: Grant access to the game directory

// NOTE: this is only true for NeoForge versions past 20.2.x
// early versions of NeoForge (for 1.20.1) are not supposed to be covered here
boolean isNeoForge = argsList.contains("--fml.neoForgeVersion");
coreModsOnly = argsList.contains("--coreModsOnly");
if (coreModsOnly) System.out.println("Running with only core DL mods! This is not suggested.");
modDirectory = System.getProperty("fabric.addMods");

mcVersion = argsList.get(argsList.indexOf("--fml.mcVersion") + 1); // DL: Make Minecraft version public
String forgeGroup = argsList.contains("--fml.forgeGroup") ? argsList.get(argsList.indexOf("--fml.forgeGroup") + 1) : "net.neoforged";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -26,16 +27,7 @@ public LexForgeModLoader() {
}

private static Path getDirectoryRequired() {
File file = new File(Main.gameDir);
Path path;
if (Main.coreModsOnly) {
path = file.getParentFile().getParentFile().toPath()
.resolve("shared/lexforge/"+Main.mcVersion+"/mods/vivecraft/");
} else {
path = file.getParentFile().getParentFile().toPath()
.resolve("shared/lexforge/"+Main.mcVersion+"/mods/");
}
return path;
return new File(Main.modDirectory).toPath();
}

LexForgeModLoader(Path modFolder, String name) {
Expand All @@ -48,8 +40,10 @@ public List<ModFileOrException> scanMods() {
LOGGER.debug(LogMarkers.SCAN, "Scanning mods dir {} for mods", this.modFolder);
var excluded = ModDirTransformerDiscoverer.allExcluded();
try {
var ret = new ArrayList<ModFileOrException>();
var files = Files.list(this.modFolder).toList();
List<ModFileOrException> ret = new ArrayList<ModFileOrException>();
List<Path> files = new ArrayList<>();
listAllFiles(this.modFolder, files);

for (var file : files) {
var name = file.getFileName().toString().toLowerCase(Locale.ROOT);
if (excluded.contains(file) || !name.endsWith(SUFFIX))
Expand Down Expand Up @@ -81,4 +75,16 @@ public String name() {
public String toString() {
return "{"+customName+" locator at "+this.modFolder+"}";
}

private static void listAllFiles(Path currentPath, List<Path> allFiles) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentPath)) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
listAllFiles(entry, allFiles);
} else {
allFiles.add(entry);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand All @@ -34,16 +36,7 @@ public NeoForgeModLoader() {
}

private static Path getDirectoryRequired() {
File file = new File(Main.gameDir);
Path path;
if (Main.coreModsOnly) {
path = file.getParentFile().getParentFile().toPath()
.resolve("shared/neoforge/"+Main.mcVersion+"/mods/core/");
} else {
path = file.getParentFile().getParentFile().toPath()
.resolve("shared/neoforge/"+Main.mcVersion+"/mods/");
}
return path;
return new File(Main.modDirectory).toPath();
}

NeoForgeModLoader(Path modFolder) {
Expand All @@ -59,28 +52,14 @@ public NeoForgeModLoader(Path modFolder, String name) {
public void findCandidates(ILaunchContext context, IDiscoveryPipeline pipeline) {
LOGGER.debug(LogMarkers.SCAN, "Scanning mods dir {} for mods", this.modFolder);

List<Path> directoryContent;
if (!Main.coreModsOnly) {
try (var files = Stream.concat(Files.list(this.modFolder), Files.list(this.modFolder.getParent()))) {
directoryContent = files
.filter(p -> StringUtils.toLowerCase(p.getFileName().toString()).endsWith(SUFFIX))
.sorted(Comparator.comparing(path -> StringUtils.toLowerCase(path.getFileName().toString())))
.toList();
} catch (UncheckedIOException | IOException e) {
throw new ModLoadingException(ModLoadingIssue.error("fml.modloadingissue.failed_to_list_folder_content", this.modFolder).withAffectedPath(this.modFolder).withCause(e));
}
} else {
try (var files = Files.list(this.modFolder)) {
directoryContent = files
.filter(p -> StringUtils.toLowerCase(p.getFileName().toString()).endsWith(SUFFIX))
.sorted(Comparator.comparing(path -> StringUtils.toLowerCase(path.getFileName().toString())))
.toList();
} catch (UncheckedIOException | IOException e) {
throw new ModLoadingException(ModLoadingIssue.error("fml.modloadingissue.failed_to_list_folder_content", this.modFolder).withAffectedPath(this.modFolder).withCause(e));
}
List<Path> files = new ArrayList<>();
try {
listAllFiles(this.modFolder, files);
} catch (IOException e) {
throw new ModLoadingException(ModLoadingIssue.error("fml.modloadingissue.failed_to_list_folder_content", this.modFolder).withAffectedPath(this.modFolder).withCause(e));
}

for (var file : directoryContent) {
for (var file : files.stream().filter(path -> path.endsWith(SUFFIX)).toList()) {
if (!Files.isRegularFile(file)) {
pipeline.addIssue(ModLoadingIssue.warning("fml.modloadingissue.brokenfile.unknown").withAffectedPath(file));
continue;
Expand All @@ -94,4 +73,16 @@ public void findCandidates(ILaunchContext context, IDiscoveryPipeline pipeline)
public String toString() {
return "{" + customName + " locator at " + this.modFolder + "}";
}

private static void listAllFiles(Path currentPath, List<Path> allFiles) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentPath)) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
listAllFiles(entry, allFiles);
} else {
allFiles.add(entry);
}
}
}
}
}

0 comments on commit 502660a

Please sign in to comment.