From e14d7ba141a0334fa0e91a09fc77f9ea82bf23cb Mon Sep 17 00:00:00 2001 From: allaryin Date: Sun, 24 Apr 2022 17:09:35 -0500 Subject: [PATCH 1/2] Added default run config and loader jar copying to gradle, a null check, and jvm args are starting to read from forge's version json --- build.gradle | 29 +++++++++++++++++++ .../java/org/mcupdater/gui/javafx/Main.java | 9 +++++- .../mcupdater/gui/javafx/MainController.java | 11 +++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 7a59b1b..efe0bf1 100644 --- a/build.gradle +++ b/build.gradle @@ -11,18 +11,47 @@ javafx { } version = sharedVersion +sourceCompatibility = 17 dependencies { implementation project(':MCU-API') implementation project(':MCU-DownloadLib') implementation project(':PackBuilder') + implementation 'com.mojang:authlib:1.6.25' + + runtimeOnly project(':MCU-ForgeLoader') + runtimeOnly project(':MCU-ForgeLoaderV2') } application { mainClass = 'org.mcupdater.gui.javafx.Main' } +def testMCURoot = "c:\\Users\\"+System.properties['user.name']+"\\MCU-Test" +run.doFirst { + // provide default args if we're running via gradle + if( args.size() == 0 ) { + mkdir(testMCURoot) + args = [ + "-ServerPack", "http://files.mcupdater.com/official_packs/mcu-1.16.5-together.xml", + "-MCURoot", testMCURoot, + "--runtimes=8#c:\\temp\\jdk8u302-b08-jre\\bin\\java.exe;11#c:\\temp\\jdk-11.0.12+7-jre\\bin\\java.exe;17#c:\\temp\\jdk-17+35\\bin\\java.exe", + ] + + // make sure we have current forgeloader jars + copyForgeLoaders + } +} +tasks.register("copyForgeLoaders", Copy) { + def dest = mkdir(testMCURoot + "\\lib" ) + + from file("..\\MCU-ForgeLoader\\build\\libs\\MCU-ForgeLoader.jar"), + file("..\\MCU-ForgeLoaderV2\\build\\libs\\MCU-ForgeLoaderV2.jar"), + file("..\\MCU-LegacyForgeLoader\\build\\libs\\MCU-LegacyForgeLoader.jar") + into dest +} + processResources { duplicatesStrategy = DuplicatesStrategy.INCLUDE from(sourceSets*.resources.srcDirs) { diff --git a/src/main/java/org/mcupdater/gui/javafx/Main.java b/src/main/java/org/mcupdater/gui/javafx/Main.java index d80267b..3f41b6b 100644 --- a/src/main/java/org/mcupdater/gui/javafx/Main.java +++ b/src/main/java/org/mcupdater/gui/javafx/Main.java @@ -52,10 +52,17 @@ public void start(Stage stage) throws Exception { } } else { newProfile = settings.findProfile(settings.getLastProfile()); + // if no 'last profile' was saved, just default to the first one in the list + if (newProfile == null) { + newProfile = settings.getProfiles().get(0); + } } controller.refreshInstanceList(); controller.refreshProfiles(); - controller.profiles.setSelectedProfile(newProfile.getName()); + // if no profile is set, avoid npe on the name lookup + if (newProfile != null) { + controller.profiles.setSelectedProfile(newProfile.getName()); + } } public Image getImage(String filename) { diff --git a/src/main/java/org/mcupdater/gui/javafx/MainController.java b/src/main/java/org/mcupdater/gui/javafx/MainController.java index b4da0ce..8a648f9 100644 --- a/src/main/java/org/mcupdater/gui/javafx/MainController.java +++ b/src/main/java/org/mcupdater/gui/javafx/MainController.java @@ -394,7 +394,13 @@ private void tryNewLaunch(ServerList selected, List modules, Profil } String playerName = launchProfile.getName(); String sessionKey = launchProfile.getSessionKey(this); + + MCUpdater mcu = MCUpdater.getInstance(); + Path instancePath = mcu.getInstanceRoot().resolve(selected.getServerId()); + // NB: we want to use the loader's version json for arguments if one exists + MinecraftVersion loaderVersion = MinecraftVersion.loadLocalVersion(instancePath.toFile(), selected.getLoaderVersion()); MinecraftVersion mcVersion = MinecraftVersion.loadVersion(selected.getVersion()); + selected.getLoaders().sort(new OrderComparator()); String indexName = mcVersion.getAssets(); if (indexName == null) { @@ -409,8 +415,6 @@ private void tryNewLaunch(ServerList selected, List modules, Profil clArgs = new StringBuilder(); } List libs = new ArrayList<>(); - MCUpdater mcu = MCUpdater.getInstance(); - Path instancePath = mcu.getInstanceRoot().resolve(selected.getServerId()); File indexesPath = mcu.getArchiveFolder().resolve("assets").resolve("indexes").toFile(); File indexFile = new File(indexesPath, indexName + ".json"); String json; @@ -445,6 +449,9 @@ private void tryNewLaunch(ServerList selected, List modules, Profil if (!mcVersion.getJVMArguments().isEmpty()) { args.add(mcVersion.getJVMArguments()); } + if (loaderVersion != null && !loaderVersion.getJVMArguments().isEmpty()) { + args.add(loaderVersion.getJVMArguments()); + } if (!settings.getJvmOpts().isEmpty()) { args.addAll(Arrays.asList(settings.getJvmOpts().split(" "))); } From 2df145f495aeaac5f683141f03b9a15331069180 Mon Sep 17 00:00:00 2001 From: allaryin Date: Sun, 24 Apr 2022 17:52:12 -0500 Subject: [PATCH 2/2] Parse fields in jvm args loaded from forge --- .../java/org/mcupdater/gui/javafx/MainController.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mcupdater/gui/javafx/MainController.java b/src/main/java/org/mcupdater/gui/javafx/MainController.java index 8a648f9..3aaa985 100644 --- a/src/main/java/org/mcupdater/gui/javafx/MainController.java +++ b/src/main/java/org/mcupdater/gui/javafx/MainController.java @@ -446,12 +446,14 @@ private void tryNewLaunch(ServerList selected, List modules, Profil args.add("-Xms" + settings.getMinMemory()); args.add("-Xmx" + settings.getMaxMemory()); //args.add("-XX:PermSize=" + settings.getPermGen()); + if (loaderVersion != null && !loaderVersion.getJVMArguments().isEmpty()) { + clArgs.append(" "); + clArgs.append(loaderVersion.getJVMArguments()); + } if (!mcVersion.getJVMArguments().isEmpty()) { + // we may only want to try the mc version's args if we don't have one for forge? args.add(mcVersion.getJVMArguments()); } - if (loaderVersion != null && !loaderVersion.getJVMArguments().isEmpty()) { - args.add(loaderVersion.getJVMArguments()); - } if (!settings.getJvmOpts().isEmpty()) { args.addAll(Arrays.asList(settings.getJvmOpts().split(" "))); } @@ -533,6 +535,9 @@ private void tryNewLaunch(ServerList selected, List modules, Profil fields.put("user_properties", "{}"); //TODO: This will likely actually get used at some point. fields.put("user_type", (launchProfile.getStyle())); fields.put("version_type", mcVersion.getType()); + fields.put("library_directory", mcu.getInstanceRoot().resolve("libraries").toString()); + fields.put("classpath_separator", File.pathSeparator); + //fields.put("version_name", "minecraft"); // the filename of the jar to be executed String[] fieldArr = tmpclArgs.split(" "); for (int i = 0; i < fieldArr.length; i++) { fieldArr[i] = fieldReplacer.replace(fieldArr[i]);