Skip to content

Conversation

@Mine-diamond
Copy link
Contributor

No description provided.

@Mine-diamond Mine-diamond changed the title feat:修复部分版本无法识别自己版本的世界的问题 fix:修复部分版本无法识别自己版本的世界的问题 Nov 30, 2025
@Glavo Glavo requested a review from Copilot December 3, 2025 08:18
Copilot finished reviewing on behalf of Glavo December 3, 2025 08:21
Copy link
Contributor

Copilot AI left a 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.

Comment on lines +62 to +67
.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))
Copy link

Copilot AI Dec 3, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +67
.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))
Copy link

Copilot AI Dec 3, 2025

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:

  1. Leverages existing version parsing logic in GameVersionNumber.Release.parse() (see line 273 in GameVersionNumber.java)
  2. Handles all version format variations consistently
  3. Is more maintainable as new version formats can be added to GameVersionNumber without modifying this code
  4. Avoids code duplication between the two filter locations
Suggested change
.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)

Copilot uses AI. Check for mistakes.
@Glavo
Copy link
Member

Glavo commented Dec 4, 2025

#4917 会实现对游戏版本的归一化处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants