From b2aa43284856d77553964a961dbefce4effbbb84 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Sun, 26 May 2024 05:54:18 +0700 Subject: [PATCH] fix(tools): forge libraries erasing themselves This was due to a side effect of our de-doubling algorithm Port of: https://github.com/PojavLauncherTeam/PojavLauncher/commit/5656176c950b9 50271221436700777196233b31f --- .../main/java/net/kdt/pojavlaunch/Tools.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java index 1232978470..40c1b97bde 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -341,30 +341,33 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName) { "releaseTime", "time", "type" ); - List libList = new ArrayList(Arrays.asList(inheritsVer.libraries)); - try { - loop_1: - for (DependentLibrary lib : customVer.libraries) { - String libName = lib.name.substring(0, lib.name.lastIndexOf(":")); - for (int i = 0; i < libList.size(); i++) { - DependentLibrary libAdded = libList.get(i); - String libAddedName = libAdded.name.substring(0, libAdded.name.lastIndexOf(":")); - - if (!libAdded.name.equals(lib.name) && libAddedName.equals(libName)) { - System.out.println("Library " + libName + ": Replaced version " + - libAdded.name.substring(libAddedName.length() + 1) + " with " + - lib.name.substring(libName.length() + 1)); - libList.set(i, lib); - libName = null; - } + // Go through the libraries, remove the ones overridden by the custom version + List inheritLibraryList = new ArrayList<>(Arrays.asList(inheritsVer.libraries)); + outer_loop: + for(DependentLibrary library : customVer.libraries){ + // Clean libraries overridden by the custom version + String libName = library.name.substring(0, library.name.lastIndexOf(":")); + + for(DependentLibrary inheritLibrary : inheritLibraryList) { + String inheritLibName = inheritLibrary.name.substring(0, inheritLibrary.name.lastIndexOf(":")); + + if(libName.equals(inheritLibName)){ + System.out.println("Library " + libName + ": Replaced version " + + libName.substring(libName.lastIndexOf(":") + 1) + " with " + + inheritLibName.substring(inheritLibName.lastIndexOf(":") + 1)); + + // Remove the library , superseded by the overriding libs + inheritLibraryList.remove(inheritLibrary); + continue outer_loop; } - - if (libName != null) libList.add(0, lib); } - } finally { - inheritsVer.libraries = libList.toArray(new DependentLibrary[0]); } + // Fuse libraries + inheritLibraryList.addAll(Arrays.asList(customVer.libraries)); + inheritsVer.libraries = inheritLibraryList.toArray(new DependentLibrary[0]); + preProcessLibraries(inheritsVer.libraries); + // Inheriting Minecraft 1.13+ with append custom args if (inheritsVer.arguments != null && customVer.arguments != null) { List totalArgList = new ArrayList();