{"id":50793933,"url":"https://github.com/yuhangle/world-inspector","last_synced_at":"2026-06-12T13:01:00.344Z","repository":{"id":360457683,"uuid":"1250236639","full_name":"yuhangle/world-inspector","owner":"yuhangle","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-26T13:41:10.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-26T14:35:39.061Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuhangle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-26T12:41:04.000Z","updated_at":"2026-05-26T14:01:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yuhangle/world-inspector","commit_stats":null,"previous_names":["yuhangle/world-inspector"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/yuhangle/world-inspector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuhangle%2Fworld-inspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuhangle%2Fworld-inspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuhangle%2Fworld-inspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuhangle%2Fworld-inspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuhangle","download_url":"https://codeload.github.com/yuhangle/world-inspector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuhangle%2Fworld-inspector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34245218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-12T13:00:56.141Z","updated_at":"2026-06-12T13:01:00.314Z","avatar_url":"https://github.com/yuhangle.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# World Inspector\n\n读取和检视 Minecraft 基岩版存档数据 — 方块、玩家、实体、区块 — 直接从 LevelDB 中读取。支持跨存档导入/导出。\n\n## 编译\n\n```bash\n# CLI 工具 + 静态库\ncargo build --release\n\n# 仅静态库\ncargo build --release --lib\n```\n\n产物：\n- `target/release/world-inspector` — CLI 工具\n- `target/release/libworld_inspector.a` — C FFI 静态库\n\n## CLI 用法\n\n```\nworld-inspector \u003c世界路径\u003e                                   存档概要\nworld-inspector \u003c世界路径\u003e \u003cx\u003e \u003cy\u003e \u003cz\u003e [dimension]          查询方块\nworld-inspector \u003c世界路径\u003e --players                         列出玩家 \nworld-inspector \u003c世界路径\u003e --actors                          列出实体\nworld-inspector \u003c世界路径\u003e --player \u003ckey\u003e                    查看玩家数据\nworld-inspector \u003c世界路径\u003e --player \u003ckey\u003e --dump             完整 NBT 转储\nworld-inspector \u003c世界路径\u003e --player \u003ckey\u003e --json             JSON 输出背包\n\n实体管理：\nworld-inspector \u003c世界路径\u003e --wipe-actors                            擦除非玩家实体\nworld-inspector \u003c世界路径\u003e --wipe-actors --include-players          擦除全部实体（含玩家数据）\nworld-inspector \u003c世界路径\u003e --export-actors \u003cfile\u003e                   导出实体到 JSON（含玩家）\nworld-inspector \u003c世界路径\u003e --export-actors \u003cfile\u003e --no-players      导出仅非玩家实体\nworld-inspector \u003c世界路径\u003e --import-actors \u003cfile\u003e                   从 JSON 导入实体（覆盖）\nworld-inspector \u003c世界路径\u003e --import-actors \u003cfile\u003e --skip-existing   导入实体（跳过已存在）\n\n区块管理：\nworld-inspector \u003c世界路径\u003e --export-chunks \u003cfile\u003e \u003cbx\u003e \u003cbz\u003e                导出单区块\nworld-inspector \u003c世界路径\u003e --export-chunks \u003cfile\u003e \u003cbx1\u003e \u003cbz1\u003e \u003cbx2\u003e \u003cbz2\u003e  导出区块范围\nworld-inspector \u003c世界路径\u003e --import-chunks \u003cfile\u003e               从 JSON 导入区块（覆盖）\nworld-inspector \u003c世界路径\u003e --import-chunks \u003cfile\u003e --skip-existing  导入区块（跳过已存在）\n```\n\n### 示例\n\n```bash\n# 存档概要\nworld-inspector /bedrock_server/worlds/Bedrock\\ level\n\n# 查询方块 (-3, -60, -3) 主世界\nworld-inspector /bedrock_server/worlds/Bedrock\\ level -3 -60 -3\n\n# 查看下界方块\nworld-inspector /bedrock_server/worlds/Bedrock\\ level 0 100 0 nether\n\n# 列出所有玩家\nworld-inspector /bedrock_server/worlds/Bedrock\\ level --players\n\n# 查看玩家背包 (JSON)\nworld-inspector /bedrock_server/worlds/Bedrock\\ level --player player_\u003cUUID\u003e --json\n\n# 完整数据转储\nworld-inspector /bedrock_server/worlds/Bedrock\\ level --player player_\u003cUUID\u003e --dump\n\n# 导出所有实体 + 玩家数据\nworld-inspector /world --export-actors entities.json\n\n# 仅导出非玩家实体（不含玩家数据）\nworld-inspector /world --export-actors entities.json --no-players\n\n# 导入实体到目标存档（覆盖模式）\nworld-inspector /target-world --import-actors entities.json\n\n# 擦除非玩家实体\nworld-inspector /world --wipe-actors\n\n# 擦除全部实体（含玩家数据）\nworld-inspector /world --wipe-actors --include-players\n\n# 导出区块（方块坐标 0, 64 所在的单区块）\nworld-inspector /world --export-chunks chunks.json 0 64\n\n# 导出区块范围（矩形区域内的所有区块）\nworld-inspector /world --export-chunks chunks.json -100 64 200 128\n\n# 导入区块到目标存档\nworld-inspector /target-world --import-chunks chunks.json\n```\n\n## 跨存档数据迁移\n\n通过组合使用导出/导入命令，可以在存档之间迁移数据：\n\n```bash\n# 1. 从源存档导出实体 + 玩家数据\n./wi /source --export-actors entities.json\n\n# 2. 从源存档导出区块（覆盖目标存档需要替换的区域）\n./wi /source --export-chunks chunks.json -100 64 200 128\n\n# 3. 清空目标存档（按需选做）\n./wi /target --wipe-actors --include-players\n\n# 4. 导入实体到目标存档\n./wi /target --import-actors entities.json\n\n# 5. 导入区块到目标存档\n./wi /target --import-chunks chunks.json\n```\n\n实体和区块分开管理，可按需选择性迁移。\n\n### 导出文件格式\n\n所有导出的 JSON 文件通用结构：\n\n```json\n{\n  \"total\": 100,\n  \"entries\": [\n    {\n      \"key_hex\": \"6163746f72707265666978...\",\n      \"value_base64\": \"eJzEyz...\",\n      \"identifier\": \"minecraft:zombie\"\n    }\n  ],\n  \"chunks\": [\"0,4\", \"1,4\"]\n}\n```\n\n- `total` — 条目总数\n- `entries` — 键值对列表（key 为 hex 编码，value 为 base64 编码）\n- `identifier` — 实体类型（仅实体导出时存在）\n- `chunks` — 已导出区块列表（仅区块导出时存在）\n\n## 玩家 key\n\nLevelDB 中的玩家 key 有三种格式：\n\n| 格式 | 说明 |\n|---|---|\n| `~local_player` | 单人模式本地玩家 |\n| `player_\u003cUUID\u003e` | 玩家身份数据（含 ServerId 指向 player_server_） |\n| `player_server_\u003cUUID\u003e` | 玩家完整游戏数据（背包、位置、生命等） |\n\nCLI 自动跟随 `ServerId` 链接显示关联数据。\n\n## 注\n\n- 只读命令以 `read_only` 模式打开 LevelDB，不修改数据\n- 写命令（wipe/import）以读写模式独立打开 DB，不影响只读功能\n- delete 操作写入 LevelDB 删除标记（tombstone），BDS 启动时自动识别\n- 导出的 JSON 文件支持 `--skip-existing` 可重入安全地增量导入\n\n## C FFI 接口\n\n将 `world_inspector` 链接为静态库后，C/C++ 可调用以下函数。\n\n### 基础接口\n\n```c\n#include \"world_inspector.h\"\n\n// 打开/关闭世界\nWiWorld* wi_open(const char* world_path);\nvoid wi_close(WiWorld* world);\n\n// 查询背包（结构化 C struct 返回）\ntypedef struct { int32_t slot; char* name; int32_t count; int32_t damage; char* tag_json; } WiItem;\ntypedef struct { WiItem* items; int32_t count; } WiItemArray;\ntypedef struct { WiItemArray inventory; WiItemArray armor; WiItem* offhand; } WiInventoryResult;\n\nWiInventoryResult* wi_get_inventory(WiWorld* world, const char* player_key);\nvoid wi_free_inventory(WiInventoryResult* result);\n\n// 一键 JSON 查询（每次调用独立打开/关闭数据库）\nchar* wi_get_inventory_json(const char* world_path, const char* player_key);\nvoid wi_free_string(char* s);\n\n// 列出玩家\nchar** wi_list_player_keys(WiWorld* world, int32_t* out_count);\nvoid wi_free_string_array(char** arr, int32_t count);\n```\n\n### 预编码背包接口\n\n返回预序列化为二进制 NBT 的物品数据（LE 格式，无头），可直接用于需要预编码物品的 UI 系统，保留物品的全部 NBT 属性。\n\n```c\ntypedef struct {\n    int32_t slot;\n    char* type_id;       // \"minecraft:diamond_sword\"\n    int32_t count;\n    int32_t damage;\n    uint8_t* nbt_bytes;  // tag 子化合物的二进制 NBT（LE 无头格式）\n    int32_t nbt_len;\n} WiEncodedItem;\n\ntypedef struct {\n    WiEncodedItem* items;\n    int32_t count;\n} WiEncodedInventory;\n\nWiEncodedInventory* wi_get_encoded_inventory(const char* world_path, const char* player_key);\nvoid wi_free_encoded_inventory(WiEncodedInventory* inv);\n```\n\n### C++ 示例\n\n```cpp\n#include \"world_inspector.h\"\n#include \u003cvector\u003e\n#include \u003cstring\u003e\n#include \u003ccstdio\u003e\n\nstruct InventorySlot {\n    int slot;\n    std::string type_id;\n    int count;\n    int damage;\n    std::vector\u003cuint8_t\u003e nbt;\n};\n\nstd::vector\u003cInventorySlot\u003e load_offline_inventory(const char* world_path, const char* player_uuid) {\n    std::vector\u003cInventorySlot\u003e slots;\n    WiEncodedInventory* inv = wi_get_encoded_inventory(world_path, player_uuid);\n    if (!inv) return slots;\n\n    for (int i = 0; i \u003c inv-\u003ecount; i++) {\n        auto\u0026 item = inv-\u003eitems[i];\n        slots.push_back(InventorySlot{\n            item.slot,\n            item.type_id,\n            item.count,\n            item.damage,\n            {item.nbt_bytes, item.nbt_bytes + item.nbt_len}\n        });\n    }\n    wi_free_encoded_inventory(inv);\n    return slots;\n}\n```\n\n## Rust 库接口\n\n```rust\nuse world_inspector::WorldHandle;\n\nlet mut handle = WorldHandle::open(\"worlds/Bedrock level\")?;\n\n// 查询玩家背包（结构化数据）\nlet inv = handle.get_player_inventory(\"player_\u003cUUID\u003e\")?;\nfor item in \u0026inv.inventory {\n    println!(\"Slot {}: {} x{}\", item.slot, item.name, item.count);\n}\n\n// 查询预编码物品（二进制 NBT）\nlet encoded = handle.get_player_encoded_items(\"player_\u003cUUID\u003e\")?;\nfor item in \u0026encoded {\n    println!(\"Slot {}: {} nbt_len={}\", item.slot, item.name, item.nbt_bytes.len());\n}\n\n// 列出所有玩家 key\nlet keys = handle.list_player_keys();\n```\n\n## 架构\n\n```\nLevelDB (NBT binary)\n    │\n    ├─ CLI: 方块查询、实体管理、区块操作\n    │\n    ├─ wi_get_inventory_json()   → JSON string（调试/外部接口）\n    │\n    ├─ wi_get_inventory()        → WiInventoryResult（结构化 C struct）\n    │\n    └─ wi_get_encoded_inventory() → WiEncodedItem[]（预编码 binary NBT）\n                                          │\n                                          ▼\n                               预编码物品可直接供 UI 系统使用\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuhangle%2Fworld-inspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuhangle%2Fworld-inspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuhangle%2Fworld-inspector/lists"}