使用 HelloNBT 替代 OpenNBT#5667
Conversation
|
换成自维护的 NBT 库有什么优势吗 |
|
There was a problem hiding this comment.
Pull request overview
该 PR 将项目的 NBT 读写实现从 OpenNBT 迁移到 HelloNBT,并同步调整相关 UI/NBT 浏览器实现与依赖声明,以保持世界/结构文件解析与 NBT 编辑功能可用。
Changes:
- 用
org.glavo.nbt.* (HelloNBT)替换com.github.steveice10.opennbt.* (OpenNBT)的读写与 Tag API 调用 - 更新世界存档(
World)与 Litematic 文件解析逻辑以使用NBTCodec - 重构 NBT 编辑器树视图实现(删除旧
NBTTreeView/NBTTagType,引入NBTTreeItem+NBTTreeCell)
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| gradle/libs.versions.toml | 新增 hello-nbt、lz4 版本与坐标,移除 opennbt |
| HMCLCore/build.gradle.kts | 依赖切换为 hello-nbt,并新增 lz4 |
| HMCLCore/src/main/java/org/jackhuang/hmcl/schematic/LitematicFile.java | 使用 HelloNBT 的 NBTCodec 与新 Tag API 读取 litematic |
| HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java | 世界存档 NBT 读写切换到 NBTCodec,并调整 zip/world 读取逻辑 |
| HMCL/src/main/resources/assets/about/deps.json | 更新第三方依赖展示信息(OpenNBT -> HelloNBT) |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java | UI 侧 Tag API 适配(部分由 getValue 调整为 get 等) |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/package-info.java | 新增 ui.nbt 包的 NotNullByDefault 声明 |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeView.java | 删除旧版 NBTTreeView |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTagType.java | 删除旧版 NBTTagType |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeItem.java | 新增惰性加载的 TreeItem 实现,支持 Chunk/Parent 展开 |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTTreeCell.java | 新增 TreeCell 渲染(图标+条目数/值展示) |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java | NBT 文件读取改为 HelloNBT(含 region/anvil)并返回 NBTElement |
| HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTEditorPage.java | NBT 编辑页面读取与 TreeView 构建改为新实现 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| root = fs.getPath("/"); | ||
| fileName = FileUtils.getName(this.file); | ||
| } else { | ||
| List<Path> files = Files.list(fs.getPath("/")).toList(); |
There was a problem hiding this comment.
Files.list(fs.getPath("/")) returns a Stream that must be closed; calling .toList() without try-with-resources can leak file descriptors (especially inside the zip FileSystem). Wrap the Files.list(...) call in a try-with-resources (or use Files.newDirectoryStream) before collecting.
| List<Path> files = Files.list(fs.getPath("/")).toList(); | |
| List<Path> files; | |
| try (Stream<Path> stream = Files.list(fs.getPath("/"))) { | |
| files = stream.toList(); | |
| } |
| var view = new TreeView<>(root) { | ||
| @Override | ||
| protected Skin<?> createDefaultSkin() { | ||
| return new TreeViewSkin<Tag>(this) { | ||
| { | ||
| FXUtils.smoothScrolling(getVirtualFlow()); | ||
| } | ||
| }; |
There was a problem hiding this comment.
The TreeView is parameterized as TreeView<NBTElement>, but createDefaultSkin() returns new TreeViewSkin<Tag>(this). This generic mismatch should not compile (and forces an unnecessary Tag import). Use a TreeViewSkin<NBTElement> (or new TreeViewSkin<>(this)) so the skin matches the TreeView's type.
No description provided.