Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jackhuang.hmcl.download.VersionList;
import org.jackhuang.hmcl.task.GetTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.gson.JsonSerializable;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -75,16 +76,38 @@ public Task<?> refreshAsync() {
String mcVersion;

try {
int si1 = version.indexOf('.'), si2 = version.indexOf('.', version.indexOf('.') + 1);
int si1 = version.indexOf('.');
int si2 = version.indexOf('.', si1 + 1);
if (si1 < 0 || si2 < 0) {
LOG.warning("Unsupported NeoForge version: " + version);
continue;
}

int majorVersion = Integer.parseInt(version.substring(0, si1));
if (majorVersion == 0) { // Snapshot version.
mcVersion = version.substring(si1 + 1, si2);
} else {
String ver = version.substring(0, Integer.parseInt(version.substring(si1 + 1, si2)) == 0 ? si1 : si2);
if (majorVersion >= 26) {
int si3 = version.indexOf('.', si2 + 1);
Comment on lines 86 to +91
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parsing logic switches behavior on majorVersion >= 26, but the threshold is a magic number here and the rationale isn’t obvious from the code. Consider extracting it into a named constant (e.g., indicating the NeoForge/Minecraft versioning scheme change) or adding a short comment explaining why 26 is the cutoff, so future updates don’t accidentally break version parsing again.

Copilot uses AI. Check for mistakes.

if (si3 < 0) {
LOG.warning("Unsupported NeoForge version: " + version);
continue;
}

String ver = Integer.parseInt(version.substring(si2 + 1, si3)) == 0
? version.substring(0, si2)
: version.substring(0, si3);

int separator = version.indexOf('+');
mcVersion = separator < 0 ? ver : ver + "-" + version.substring(separator + 1);
if (separator < 0)
mcVersion = ver;
else
mcVersion = ver + "-" + version.substring(separator + 1);
} else {
String ver = Integer.parseInt(version.substring(si1 + 1, si2)) == 0
? version.substring(0, si1)
: version.substring(0, si2);
mcVersion = "1." + ver;
}
}
Expand All @@ -106,14 +129,7 @@ public Task<?> refreshAsync() {
});
}

private static final class OfficialAPIResult {
private final boolean isSnapshot;

private final List<String> versions;

public OfficialAPIResult(boolean isSnapshot, List<String> versions) {
this.isSnapshot = isSnapshot;
this.versions = versions;
}
@JsonSerializable
private record OfficialAPIResult(boolean isSnapshot, List<String> versions) {
}
}