Skip to content

Commit

Permalink
[1.10.2] Fixed ordering of Forge versions
Browse files Browse the repository at this point in the history
  • Loading branch information
3arthqu4ke committed Jul 17, 2024
1 parent ff2ddb1 commit a4632d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static me.earth.headlessmc.launcher.util.URLs.url;
Expand All @@ -31,6 +32,7 @@ protected List<ForgeVersion> read(JsonElement element) throws IOException {
result.add(version);
}

result.sort(Comparator.reverseOrder());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@
import java.util.List;

@Data
public class ForgeVersion implements HasName {
public class ForgeVersion implements HasName, Comparable<ForgeVersion> {
@SerializedName("requires")
private List<Requires> requires;

@SerializedName("version")
private String name;

@Data
public static class Requires {
@SerializedName("equals")
private String equals;

// @SerializedName("uid") <- check this
// private String netMinecraft; seems to always be "net.minecraft"
@Override
public int compareTo(ForgeVersion other) {
if (this.name.equals(other.getName())) {
return 0;
}

String[] version1 = this.name.split("[-.]");
String[] version2 = other.getName().split("[-.]");
for (int i = 0; i < version1.length && i < version2.length; i++) {
int compare;
try {
compare = Integer.compare(Integer.parseInt(version1[i]), Integer.parseInt(version2[i]));
} catch (NumberFormatException e) {
compare = String.CASE_INSENSITIVE_ORDER.compare(version1[i], version2[i]);
}

if (compare != 0) {
return compare;
}
}

return Integer.compare(version2.length, version1.length);
}

public String getVersion() {
Expand All @@ -31,4 +46,13 @@ public String getFullName() {
return getVersion() + "-" + getName();
}

@Data
public static class Requires {
@SerializedName("equals")
private String equals;

// @SerializedName("uid") <- check this
// private String netMinecraft; seems to always be "net.minecraft"
}

}

0 comments on commit a4632d5

Please sign in to comment.