Skip to content

feat: 添加新版本存档数据获取支持#5419

Open
Mine-diamond wants to merge 27 commits intoHMCL-dev:mainfrom
Mine-diamond:new-level-dat-format
Open

feat: 添加新版本存档数据获取支持#5419
Mine-diamond wants to merge 27 commits intoHMCL-dev:mainfrom
Mine-diamond:new-level-dat-format

Conversation

@Mine-diamond
Copy link
Contributor

@Mine-diamond Mine-diamond commented Feb 4, 2026

26.1-snapshot-6中,mojang对整个存档格式存档基础数据存储格式进行了非常深的破坏性变更,这导致HMCL几乎无法正确读取新版本的世界数据,本PR将添加对新版本的新格式支持

close #5436

java-info = { module = "org.glavo:java-info", version.ref = "java-info" }
authlib-injector = { module = "org.glavo.hmcl:authlib-injector", version.ref = "authlib-injector" }
monet-fx = { module = "org.glavo:MonetFX", version.ref = "monet-fx" }
micanbt = {module = "tech.minediamond:micanbt", version.ref = "micanbt"}
Copy link
Member

Choose a reason for hiding this comment

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

我们不是已经有一个 NBT 库了嘛

Copy link
Contributor

Choose a reason for hiding this comment

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

我们不是已经有一个 NBT 库了嘛

见:#5095

Copy link
Contributor Author

Choose a reason for hiding this comment

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

之所以要换NBT库是因为这个 #5095,这个PR我也尝试重构一下。
同时这个库加了一个叫NBTPath的东西,这样获取深入嵌套的数据就不需要写非常长的get和instanceof了,这能减少维护成本,这也是打算在这个PR就换库的原因,比如:
之前:

    public boolean isLargeBiomes() {
        CompoundTag data = levelData.get("Data");
        if (data.get("generatorName") instanceof StringTag generatorNameTag) { //Valid before 1.16
            return "largeBiomes".equals(generatorNameTag.getValue());
        } else {
            if (data.get("WorldGenSettings") instanceof CompoundTag worldGenSettingsTag
                    && worldGenSettingsTag.get("dimensions") instanceof CompoundTag dimensionsTag
                    && dimensionsTag.get("minecraft:overworld") instanceof CompoundTag overworldTag
                    && overworldTag.get("generator") instanceof CompoundTag generatorTag) {
                if (generatorTag.get("biome_source") instanceof CompoundTag biomeSourceTag
                        && biomeSourceTag.get("large_biomes") instanceof ByteTag largeBiomesTag) { //Valid between 1.16 and 1.16.2
                    return largeBiomesTag.getValue() == (byte) 1;
                } else if (generatorTag.get("settings") instanceof StringTag settingsTag) { //Valid after 1.16.2
                    return "minecraft:large_biomes".equals(settingsTag.getValue());
                }
            }
            return false;
        }
    }

现在:(不含最新版本的逻辑)

public boolean isLargeBiomes() {
        if (levelData.at("Data/generatorName") instanceof StringTag generatorNameTag) { //Valid before 1.16
            return "largeBiomes".equals(generatorNameTag.getClonedValue());
        } else {
            if (levelData.at("Data/WorldGenSettings/dimensions/minecraft:overworld/generator") instanceof CompoundTag generatorTag) {
                if (generatorTag.at("biome_source/large_biomes") instanceof ByteTag largeBiomesTag) { //Valid between 1.16 and 1.16.2
                    return largeBiomesTag.getClonedValue() == (byte) 1;
                } else if (generatorTag.get("settings") instanceof StringTag settingsTag) { //Valid after 1.16.2
                    return "minecraft:large_biomes".equals(settingsTag.getClonedValue());
                }
            }
            return false;
        }
    }

最后,opennbt已经归档了,换一个能更积极维护的库也是好的。新库是我写的,我在尝试添加更多更好的功能。

@Mine-diamond Mine-diamond marked this pull request as ready for review February 7, 2026 13:33
@Glavo Glavo requested a review from Copilot February 7, 2026 13:36
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

为 HMCL 增加对 Minecraft 26.1-snapshot-6 引入的全新/破坏性存档基础数据格式的读取与编辑支持,以修复新版本世界信息(如种子、难度、结构生成等)无法正确解析的问题(close #5436)。

Changes:

  • 引入 MicaNBT 依赖,并在核心世界数据读取/写入中切换到新的 NBT 读写实现。
  • World 支持读取 world_gen_settings.dat 以及在新格式下从独立玩家数据文件读取玩家信息。
  • UI 世界信息页/管理页适配新字段路径(种子、结构生成、难度/锁定/硬核等)。

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
gradle/libs.versions.toml 新增 MicaNBT 版本与库坐标
HMCLCore/build.gradle.kts HMCLCore 引入 micanbt 依赖
HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java 使用 MicaNBT 读取/写入世界数据,并支持新格式拆分的数据文件
HMCL/src/main/resources/assets/about/deps.json 关于页依赖列表新增 MicaNBT 信息
HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldManagePage.java 刷新入口从 reloadLevelDat() 调整为 reloadWorldData()
HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java 世界信息 UI 适配新格式字段与保存逻辑

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Glavo
Copy link
Member

Glavo commented Feb 11, 2026

OpenNBT 长时间无人维护,我也在考虑自行维护 NBT 库。

我希望要么把 NBT 支持库合并到 HMCL 源码中维护,要么将仓库托管在 HMCL-dev 组织下进行维护,否则我觉得可能会对后续的审查和维护造成困难。

@Mine-diamond
Copy link
Contributor Author

可以,我个人非常乐意将 MicaNBT 交给 HMCL-dev 组织来维护。

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.

[Bug] 无法正确识别解析26.1_snap6版本存档

4 participants