From 06ce743c00b161ffada3a8737bec1a0b53fb48ac Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Thu, 12 Oct 2023 10:58:51 +0200 Subject: [PATCH] Create the option to search for a none MC Specific forge jar on the class path. --- .../fml/loading/targets/CommonDevLaunchHandler.java | 13 +++++++++---- .../loading/targets/ForgeUserdevLaunchHandler.java | 10 ++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/loader/src/main/java/net/minecraftforge/fml/loading/targets/CommonDevLaunchHandler.java b/loader/src/main/java/net/minecraftforge/fml/loading/targets/CommonDevLaunchHandler.java index fca6b44ca..6d69e0c8f 100644 --- a/loader/src/main/java/net/minecraftforge/fml/loading/targets/CommonDevLaunchHandler.java +++ b/loader/src/main/java/net/minecraftforge/fml/loading/targets/CommonDevLaunchHandler.java @@ -12,6 +12,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.function.BiPredicate; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,12 +76,16 @@ protected String[] preLaunch(String[] arguments, ModuleLayer layer) { return args.getArguments(); } + + protected static Optional searchJarOnClasspath(String[] classpath, String match) { + return Arrays.stream(classpath) + .filter(e -> FileUtils.matchFileName(e, false, match)) + .findFirst().map(Paths::get); + } protected static Path findJarOnClasspath(String[] classpath, String match) { - return Paths.get(Arrays.stream(classpath) - .filter(e -> FileUtils.matchFileName(e, false, match)) - .findFirst() - .orElseThrow(() -> new IllegalStateException("Could not find " + match + " in classpath"))); + return searchJarOnClasspath(classpath, match) + .orElseThrow(() -> new IllegalStateException("Could not find " + match + " in classpath")); } protected BiPredicate getMcFilter(Path extra, List minecraft, Stream.Builder> mods) { diff --git a/loader/src/main/java/net/minecraftforge/fml/loading/targets/ForgeUserdevLaunchHandler.java b/loader/src/main/java/net/minecraftforge/fml/loading/targets/ForgeUserdevLaunchHandler.java index 27925e9fa..ab55baf3c 100644 --- a/loader/src/main/java/net/minecraftforge/fml/loading/targets/ForgeUserdevLaunchHandler.java +++ b/loader/src/main/java/net/minecraftforge/fml/loading/targets/ForgeUserdevLaunchHandler.java @@ -14,7 +14,13 @@ public abstract class ForgeUserdevLaunchHandler extends CommonUserdevLaunchHandler { @Override protected void processStreams(String[] classpath, VersionInfo versionInfo, Stream.Builder mc, Stream.Builder> mods) { - var forge = findJarOnClasspath(classpath, "forge-" + versionInfo.mcAndForgeVersion()); - mc.add(forge); + var forge = searchJarOnClasspath(classpath, "forge-" + versionInfo.mcAndForgeVersion()); + if (forge.isEmpty()) { + forge = searchJarOnClasspath(classpath, "forge-" + versionInfo.forgeVersion()); + } + if (forge.isEmpty()) { + throw new RuntimeException("Could not find %s, nor %s jar on classpath".formatted("forge-" + versionInfo.mcAndForgeVersion(), "forge-" + versionInfo.forgeVersion())); + } + mc.add(forge.get()); } }