Fix #5907: 修复无法为 MC 26.1.1 从官方源安装 NeoForge 的问题#5910
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the NeoForge version parsing logic to accommodate changes in versioning for major version 26 and above, while also converting the OfficialAPIResult class into a Java record. Review feedback identifies a critical indexing error in the substring logic for extracting Minecraft versions, which may result in truncated or incorrect version strings. Additionally, the current check for a third dot in the version string is flagged as potentially over-restrictive, as it could cause valid version formats to be ignored.
HMCLCore/src/main/java/org/jackhuang/hmcl/download/neoforge/NeoForgeOfficialVersionList.java
Outdated
Show resolved
Hide resolved
HMCLCore/src/main/java/org/jackhuang/hmcl/download/neoforge/NeoForgeOfficialVersionList.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
修复从 NeoForge 官方 Maven 版本列表解析 Minecraft 26.1.1 对应版本失败,导致无法从官方源安装 NeoForge 的问题。
Changes:
- 调整 NeoForge 版本字符串解析逻辑:对
majorVersion >= 26的版本按新的段位规则提取对应的 MC 版本号(支持区分26.1与26.1.1)。 - 为无法解析/不支持的版本号增加显式告警日志并跳过处理,避免异常中断刷新流程。
- 将
OfficialAPIResult从内部类改为record,并补充@JsonSerializable标注以匹配项目 Gson 序列化约定。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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); |
There was a problem hiding this comment.
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.
No description provided.