-
Notifications
You must be signed in to change notification settings - Fork 799
fix:修复部分版本无法识别自己版本的世界的问题 #4888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:修复部分版本无法识别自己版本的世界的问题 #4888
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes an issue where certain Minecraft versions were not recognizing their own world saves. The problem stems from version format inconsistencies—worlds created in versions like "1.14 Pre-Release 1" store that format in their level.dat, but HMCL uses the normalized format "1.14-pre1" internally.
Key Changes
- Adds version string normalization to world filtering logic to handle format variations (e.g., " Pre-Release " → "-pre", " Release Candidate " → "-rc")
- Applies the fix in two locations: the showAll listener and the refresh() method
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .filter(world -> isShowAll() || world.getGameVersion() == null || world.getGameVersion().equals(gameVersion) | ||
| || world.getGameVersion() | ||
| .replace(" Pre-Release ", "-pre") | ||
| .replace(" Release Candidate ", "-rc") | ||
| .replace(" experimental snapshot ", "_experimental-snapshot-") | ||
| .replace(" Unobfuscated", "_unobfuscated").equals(gameVersion)) |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version normalization logic (lines 64-67) is duplicated in the refresh() method (lines 108-111). Consider extracting this into a private helper method to avoid code duplication and make maintenance easier. For example:
private boolean matchesGameVersion(World world) {
return isShowAll() || world.getGameVersion() == null
|| world.getGameVersion().equals(gameVersion)
|| normalizeVersion(world.getGameVersion()).equals(gameVersion);
}
private String normalizeVersion(String version) {
return version
.replace(" Pre-Release ", "-pre")
.replace(" Release Candidate ", "-rc")
.replace(" experimental snapshot ", "_experimental-snapshot-")
.replace(" Unobfuscated", "_unobfuscated");
}Then use .filter(this::matchesGameVersion) in both places.
| .filter(world -> isShowAll() || world.getGameVersion() == null || world.getGameVersion().equals(gameVersion) | ||
| || world.getGameVersion() | ||
| .replace(" Pre-Release ", "-pre") | ||
| .replace(" Release Candidate ", "-rc") | ||
| .replace(" experimental snapshot ", "_experimental-snapshot-") | ||
| .replace(" Unobfuscated", "_unobfuscated").equals(gameVersion)) |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using GameVersionNumber.asGameVersion() for version comparison instead of string manipulation. The GameVersionNumber class already handles version format variations (like " Pre-Release " vs "-pre") during parsing and comparison. This would be more robust and maintainable:
.filter(world -> isShowAll() || world.getGameVersion() == null
|| GameVersionNumber.asGameVersion(world.getGameVersion())
.compareTo(GameVersionNumber.asGameVersion(gameVersion)) == 0)This approach:
- Leverages existing version parsing logic in
GameVersionNumber.Release.parse()(see line 273 in GameVersionNumber.java) - Handles all version format variations consistently
- Is more maintainable as new version formats can be added to
GameVersionNumberwithout modifying this code - Avoids code duplication between the two filter locations
| .filter(world -> isShowAll() || world.getGameVersion() == null || world.getGameVersion().equals(gameVersion) | |
| || world.getGameVersion() | |
| .replace(" Pre-Release ", "-pre") | |
| .replace(" Release Candidate ", "-rc") | |
| .replace(" experimental snapshot ", "_experimental-snapshot-") | |
| .replace(" Unobfuscated", "_unobfuscated").equals(gameVersion)) | |
| .filter(world -> isShowAll() || world.getGameVersion() == null | |
| || GameVersionNumber.asGameVersion(world.getGameVersion()) | |
| .compareTo(GameVersionNumber.asGameVersion(gameVersion)) == 0) |
|
#4917 会实现对游戏版本的归一化处理。 |
No description provided.