Skip to content

Commit

Permalink
fix(tools): forge libraries erasing themselves
Browse files Browse the repository at this point in the history
This was due to a side effect of our de-doubling algorithm
Port of:
PojavLauncherTeam/PojavLauncher@5656176c950b9
50271221436700777196233b31f
  • Loading branch information
khanhduytran0 committed May 25, 2024
1 parent 3f0ec78 commit b2aa432
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,30 +341,33 @@ public static JMinecraftVersionList.Version getVersionInfo(String versionName) {
"releaseTime", "time", "type"
);

List<DependentLibrary> libList = new ArrayList<DependentLibrary>(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<DependentLibrary> 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();
Expand Down

0 comments on commit b2aa432

Please sign in to comment.