mcdr-chest-scanner
MCDReforged 库插件:通过玩家准星指向或指定坐标获取箱子内容,支持大箱子。
安装
在插件 mcdreforged.plugin.json 中声明依赖:
{
"dependencies": {
"chest_scanner_lib": ">=0.1.0"
}
}
依赖
| 依赖 | 类型 |
|---|---|
| MCDReforged >=2.14.0 | 插件平台 |
| MinecraftDataAPI | 玩家位置/朝向(仅 find_targeted_chest 需要) |
| hjson >=3.1 | Python 包(pip install hjson) |
API
所有函数成功返回 ({item_id: qty}, None),失败返回 (None, error_code)。
高级 API
find_targeted_chest(server, player, max_distance=6.0)
扫描玩家准星指向的箱子,含双联箱子合并。
items, err = find_targeted_chest(server, "Steve")
if err:
server.logger.warning(f"扫描失败: {err}")
scan_chest_rcon(server, x, y, z)
扫描指定坐标的箱子,含双联箱子合并。
items, err = scan_chest_rcon(server, 10, 64, 20)
低级 API
| 函数 | 返回值 | 说明 |
|---|---|---|
detect_facing_type(server, x, y, z) | (facing, type) 或 None | 通过 execute if block 探测箱子 block state |
read_double_chest(server, x, y, z, primary_items) | dict | 检测 partner 半 + 合并 54 格 |
expand_items(items, acc) | None | 递归展开嵌套物品(潜影盒)到 Counter |
parse_rcon_block_items(raw) | (list, None) 或 (None, err) | 解析 RCON data get block 响应 |
parse_block_coords(raw) | (x, y, z) 或 None | 从 RCON 响应前缀提取坐标 |
错误码
| 错误码 | 含义 |
|---|---|
no_rcon | RCON 未运行或查询失败 |
no_api / no_pos | 无法获取玩家位置(仅准星模式) |
not_container | 非容器方块 |
not_found | 射线范围内无容器 |
empty | 容器为空 |
parse_error / unknown_format | SNBT 解析失败 |
实现方式
- DDA 体素遍历(Amanatides & Woo)— 准星射线逐格探测,不跳格不遗漏
- 双联箱子合并 —
execute if block探测type/facing,自动合并 54 格 - 陷阱箱兼容 —
minecraft:chest+minecraft:trapped_chest - SNBT 解析 — 提取自 MinecraftDataAPI 预处理 + hjson 宽松解析
许可
MIT
介绍文本来源:README_zh.md