dsh-mc-toolkit 0.0.0-stage → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -3
  3. package/README.zh.md +72 -0
  4. package/cordis.patch.yml +140 -0
  5. package/docs/DETAIL.md +27 -0
  6. package/docs/UPDATE.md +42 -0
  7. package/locale/en.json +7 -0
  8. package/locale/zh.json +7 -0
  9. package/package.json +32 -3
  10. package/references/backup-rollback.md +52 -0
  11. package/references/crash-forensics.md +52 -0
  12. package/references/launcher-import.md +40 -0
  13. package/references/merge-playbook.md +50 -0
  14. package/references/pack-branding.md +36 -0
  15. package/references/pcl-instance.md +53 -0
  16. package/references/quests-format.md +63 -0
  17. package/skills/common/mc-crash-forensics/SKILL.md +33 -0
  18. package/skills/common/mc-item-lookup/SKILL.md +31 -0
  19. package/skills/common/mc-jar-inspect/SKILL.md +33 -0
  20. package/skills/common/mc-mod-localize/SKILL.md +28 -0
  21. package/skills/common/mc-mod-research/SKILL.md +36 -0
  22. package/skills/common/mc-pack-qa/SKILL.md +36 -0
  23. package/skills/common/mc-pack-target/SKILL.md +44 -0
  24. package/skills/mod/mc-mod-api/SKILL.md +34 -0
  25. package/skills/mod/mc-mod-dev/SKILL.md +36 -0
  26. package/skills/mod/mc-mod-release/SKILL.md +29 -0
  27. package/skills/mod/mc-mod-upgrade/SKILL.md +24 -0
  28. package/skills/pack/mc-pack-audit/SKILL.md +40 -0
  29. package/skills/pack/mc-pack-distribute/SKILL.md +41 -0
  30. package/skills/pack/mc-pack-merge/SKILL.md +25 -0
  31. package/skills/pack/mc-pack-release/SKILL.md +31 -0
  32. package/skills/pack/mc-pack-scaffold/SKILL.md +33 -0
  33. package/skills/pack/mc-pack-sources/SKILL.md +36 -0
  34. package/skills/pack/mc-pack-version/SKILL.md +27 -0
  35. package/skills/pack/mc-quests/SKILL.md +22 -0
  36. package/tools/index_items.py +344 -0
  37. package/tools/modpack.py +1107 -0
  38. package/tools/quests.py +432 -0
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: mc-pack-release
3
+ description: 当要把整合包打成 .mrpack 并写导入说明与 changelog 时使用。出包后按启动器逐条给导入步骤。
4
+ ---
5
+
6
+ # 整合包发布
7
+
8
+ ## 出包前
9
+
10
+ - `target.json` 存在,MC/加载器/构建号与 manifest 一致。
11
+ - 所有 mod 文件都有来源与哈希,`verify` 全过;`allowModDistribution=false` 的已列入手动安装。
12
+ - changelog 已写;没有未确认的版本改动。
13
+ - 磁盘 ≥ 2GB。
14
+
15
+ ## 步骤
16
+
17
+ 1. 读 `target.json` 与 manifest,生成 `modrinth.index.json`:`formatVersion: 1`、`game: minecraft`、`versionId`、`name`、`files`、`dependencies`。
18
+ 2. 打包 `.mrpack`(本质是 zip):`modrinth.index.json` 放在根目录,`overrides/` 放配置与资源;不要把工程目录或启动器实例整个打进去。
19
+ 3. 校验包内路径用 `/`,没有多余顶层目录;文件哈希与 index 一致;排除未授权 jar。
20
+ 4. 命名为 `<整合包名>-<版本>.mrpack`,计算 sha256,记录文件大小。
21
+ 5. 生成 `.mrpack` 后,读 `references/launcher-import.md` 并按其给用户写导入说明;新启动器要联网核实当前步骤,不凭记忆写。
22
+ 6. 写 `docs/changelog.md`:版本、MC/加载器、增删 mod、配置变更、手动安装、已知问题。
23
+ 7. 交付:`.mrpack`、sha256、导入说明、手动安装清单、回滚方式。
24
+
25
+ ## 踩坑
26
+
27
+ - index 不在 zip 根目录会导致启动器无法识别。
28
+ - `overrides/` 路径相对实例根,多套一层会放错位置。
29
+ - 客户端专属 mod 不要进服务端覆盖;必要时用 `client-overrides/`。
30
+ - 不要为了“完整”把 jar 塞进 overrides,许可证与体积都不允许。
31
+ - 出包后不要再改 `target.json`;改了必须重出并更新哈希。
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: mc-pack-scaffold
3
+ description: 当要从零搭建整合包工程、生成 target.json 与目录骨架时使用。先确认版本,不替用户猜。
4
+ ---
5
+
6
+ # 整合包工程骨架
7
+
8
+ ## 开工自检
9
+
10
+ | 检查 | 缺失时 |
11
+ |---|---|
12
+ | 工程内 `target.json` | 没有就先走 `mc-pack-target` 推导;推不出来再问用户 |
13
+ | Modrinth API 可达 | 说明无法在线校验 |
14
+ | 已设 `CURSEFORGE_API_KEY` | 只能手动安装 |
15
+ | 启动器实例路径存在 | 让用户确认 |
16
+ | 磁盘剩余 ≥ 2GB | 让用户清理,不代删 |
17
+
18
+ 缺项就停并给指引,不自行安装软件。
19
+
20
+ ## 步骤
21
+
22
+ 1. 确认 MC 版本、加载器与构建号,写 `target.json`(`minecraft`/`loader`/`loaderVersion`/`packFormat`)。用户没给版本时先走 `mc-pack-target` 从实例/清单推导,推导不出再问;仍不确定就不写。
23
+ 2. 建目录:`mods/`、`config/`、`defaultconfigs/`、`kubejs/`、`resourcepacks/`、`datapacks/`、`overrides/`、`docs/`。
24
+ 3. `modrinth.index.json` 写 `formatVersion: 1`、`game: minecraft`、`versionId`、`name`、`files: []`,`dependencies` 填 `minecraft` 与加载器键(`forge`/`neoforge`/`fabric-loader`)。
25
+ 4. `overrides/` 放要覆盖到实例根的文件:`config/`、`kubejs/`、`resourcepacks/`、`datapacks/`;不要拷整个实例。
26
+ 5. 建 `docs/changelog.md`,校验 JSON 可解析、目录存在。
27
+
28
+ ## 踩坑
29
+
30
+ - `overrides/` 内路径相对实例根,别多套一层。
31
+ - 客户端专属 mod 不能进服务端覆盖,mrpack 用 `client-overrides/` 区分。
32
+ - `defaultconfigs` 与 `config` 的优先级随加载器变化,查目标加载器文档。
33
+ - 归档内路径用 `/`;中文名可用,但避免空格和特殊符号。
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: mc-pack-sources
3
+ description: 当要挑选 mod 来源、核对许可证、下载并校验文件时使用。确保整合包可合法分发且文件完整。
4
+ ---
5
+
6
+ # mod 来源与许可
7
+
8
+ ## 什么时候用
9
+
10
+ 选 mod、补下载、核对能否随包分发时。先查来源与许可证,再决定进包还是手动安装。
11
+
12
+ ## 来源优先级
13
+
14
+ 1. Modrinth:公开 API,无需 key;记录 project id、version id、下载 URL、sha1/sha512、依赖与 license。
15
+ 2. CurseForge:需要 `CURSEFORGE_API_KEY`;先看 `allowModDistribution`,为 false 只能标“需手动安装”,不得绕过。
16
+ 3. GitHub Releases:作者官方发布页,适合 Modrinth/CF 没有的包;核对 release 与 tag。
17
+ 4. 其它站点只在作者官方链接指向时使用;不碰网盘、转载站、破解站。
18
+
19
+ ## 下载与校验
20
+
21
+ - 下载到临时目录,文件名用 `<modid>-<version>.jar`,不覆盖已有文件。
22
+ - 校验 sha1/sha512 与文件大小;哈希不符就重下,仍不符就停。
23
+ - 校验加载器、MC 版本、依赖版本范围;不把 Forge 包塞进 Fabric 实例。
24
+ - 记录来源 URL、版本 id、哈希到 manifest/lock 文件,方便复现。
25
+ - 有 `tools/modpack.py` 时优先用其 `search` / `resolve` / `verify`,失败再手工查。
26
+
27
+ ## 许可红线
28
+
29
+ - 不把他人 mod jar 打包进整合包再分发;许可证不允许时只给链接。
30
+ - 汉化补丁、资源包、数据包同样看原许可。
31
+ - 作者标注 All Rights Reserved 或禁止再分发时,一律手动安装。
32
+ - API key 只从环境变量读,绝不写进工程、技能或仓库。
33
+
34
+ ## 输出
35
+
36
+ 来源表:mod、版本、来源、下载页、哈希、许可证、可否随包分发、失败原因。最后单列“需手动安装”清单。
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: mc-pack-version
3
+ description: 当用户明确要求切换或升级整合包版本时使用。没有“改版本/升级到/切回”这类触发词时绝不改动。
4
+ ---
5
+
6
+ # 整合包版本切换
7
+
8
+ ## 触发条件
9
+
10
+ 只有用户明确说“改版本 / 升级到 / 切回 / 换到某版本”时才动 `target.json`。没有触发词,即使发现新版本也不改;不确定就先问。
11
+
12
+ ## 步骤
13
+
14
+ 1. 解析新目标:MC 版本、加载器、加载器构建号、所需 Java。核对加载器构建确实支持该 MC 版本;Java 常见对应为 1.20.1→17、1.21+→21,最终以官方要求为准。
15
+ 2. 读当前 `target.json`,列出受影响范围:mod 清单、配置、资源包、数据包、存档兼容性。没有 `target.json` 时先走 `mc-pack-target` 推导当前基线,不靠记忆和文件名。
16
+ 3. 逐个核对现有 mod 在新版本是否有对应版本,以 Modrinth 为主,CurseForge/GitHub 补充;输出三张清单:✅ 有新版、⚠️ 有替代、❌ 没有,等用户拍板。
17
+ 4. 备份:`target.json` → `target.json.bak`,manifest → 带时间戳的备份;同时在 `docs/changelog.md` 记下旧值与待定项。
18
+ 5. 写新 `target.json`,按确认结果调整 mod 清单;不自动删文件,不自动替换没确认的 mod。
19
+ 6. 重新生成 `.mrpack`,按 `mc-pack-release` 出包;changelog 写清旧→新、增删 mod、需手动补装、已放弃项。
20
+ 7. 给用户“需手动补装/已放弃”清单,提醒存档与客户端配置可能不兼容。跨大版本时在 README 注明“这是新包,不是升级”。
21
+
22
+ ## 护栏
23
+
24
+ - 先备份后修改;改完必须重新出包,不能只改 `target.json`。
25
+ - 不自动删旧 jar、旧配置、旧存档。
26
+ - 加载器切换(Forge↔NeoForge↔Fabric)按跨大版本处理,先确认所有 mod 都有对应版本。
27
+ - 没有 `target.json.bak` 与 changelog 记录,视为流程未完成。
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: mc-quests
3
+ description: 当要制作或校验 FTB 任务书(章节、任务、奖励、前置)时使用。ID 对照模组元数据,奖励预算与任务链都要检查。
4
+ ---
5
+
6
+ # FTB 任务书
7
+
8
+ ## 结构
9
+
10
+ 任务书按「章节 → 任务 → 奖励」组织,任务之间用依赖连线;前置缺失或成环都会断链。格式细节见 `references/quests-format.md`。
11
+
12
+ ## 步骤
13
+
14
+ 1. 先定章节与主线,每个任务只做一件事;写清前置,避免成环。
15
+ 2. ID 对照:物品/方块/标签 ID 必须能在 `items.json`、整合包内 jar 元数据或 Modrinth 找到;查不到就标“待确认”,不硬猜。
16
+ 3. 奖励预算:单任务奖励价值与章节总量都要有上限,别用高价值物品堆进度。
17
+ 4. 校验:`python tools/quests.py check <任务书目录>` 做尽力校验——能解析 SNBT 就查结构与引用,解析不了退回结构/正则检查,并明确标注「未完全解析」。
18
+ 5. 按报告逐条修;改前备份原任务书。
19
+
20
+ ## 护栏
21
+
22
+ 不硬猜 ID;不覆盖用户的奖励设定而不说明;校验未通过不宣布完成。
@@ -0,0 +1,344 @@
1
+ #!/usr/bin/env python3
2
+ """Build a local item index from a mods directory.
3
+
4
+ Scans each jar for mod metadata, language files, item/block models, and
5
+ recipes, then writes one JSON file keyed by item id. This is a best-effort
6
+ index for cross-checking; MC 百科 / Minecraft Wiki remain authoritative.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import json
13
+ import re
14
+ import sys
15
+ import zipfile
16
+ from datetime import datetime, timezone
17
+ from pathlib import Path
18
+ from typing import Any
19
+
20
+ try:
21
+ import tomllib
22
+ except ImportError: # pragma: no cover - Python < 3.11
23
+ tomllib = None
24
+
25
+ LANG_RE = re.compile(r"^assets/([^/]+)/lang/([^/]+)\.json$")
26
+ ITEM_KEY_RE = re.compile(r"^(item|block|tile)\.([a-z0-9_.-]+)\.(.+?)(?:\.name)?$")
27
+ RECIPE_DIRS = ("recipes", "recipe")
28
+
29
+
30
+ class IndexError_(Exception):
31
+ pass
32
+
33
+
34
+ def configure_stdout() -> None:
35
+ if hasattr(sys.stdout, "reconfigure"):
36
+ sys.stdout.reconfigure(encoding="utf-8")
37
+
38
+
39
+ def read_json_bytes(raw: bytes) -> Any:
40
+ return json.loads(raw.decode("utf-8-sig"))
41
+
42
+
43
+ def read_json_entry(archive: zipfile.ZipFile, name: str) -> Any:
44
+ try:
45
+ return read_json_bytes(archive.read(name))
46
+ except (KeyError, UnicodeDecodeError, json.JSONDecodeError):
47
+ return None
48
+
49
+
50
+ def parse_forge_metadata(archive: zipfile.ZipFile, name: str) -> list[dict]:
51
+ raw = archive.read(name)
52
+ try:
53
+ text = raw.decode("utf-8-sig")
54
+ except UnicodeDecodeError:
55
+ return []
56
+ if tomllib is not None:
57
+ try:
58
+ data = tomllib.loads(text)
59
+ mods = data.get("mods") or []
60
+ if isinstance(mods, dict):
61
+ mods = [mods]
62
+ return [
63
+ {
64
+ "id": str(mod.get("modId") or ""),
65
+ "name": str(mod.get("displayName") or mod.get("modId") or ""),
66
+ "version": str(mod.get("version") or ""),
67
+ }
68
+ for mod in mods
69
+ if isinstance(mod, dict) and mod.get("modId")
70
+ ]
71
+ except Exception:
72
+ pass
73
+ match = re.search(r'modId\s*=\s*"([^"]+)"', text)
74
+ if not match:
75
+ return []
76
+ name_match = re.search(r'displayName\s*=\s*"([^"]+)"', text)
77
+ version_match = re.search(r'version\s*=\s*"([^"]+)"', text)
78
+ return [{
79
+ "id": match.group(1),
80
+ "name": name_match.group(1) if name_match else match.group(1),
81
+ "version": version_match.group(1) if version_match else "",
82
+ }]
83
+
84
+
85
+ def read_mod_metadata(archive: zipfile.ZipFile) -> list[dict]:
86
+ names = set(archive.namelist())
87
+ mods: list[dict] = []
88
+ for candidate in ("META-INF/neoforge.mods.toml", "META-INF/mods.toml"):
89
+ if candidate in names:
90
+ mods.extend(parse_forge_metadata(archive, candidate))
91
+ if "fabric.mod.json" in names:
92
+ data = read_json_entry(archive, "fabric.mod.json")
93
+ if isinstance(data, dict) and data.get("id"):
94
+ mods.append({
95
+ "id": str(data.get("id")),
96
+ "name": str(data.get("name") or data.get("id")),
97
+ "version": str(data.get("version") or ""),
98
+ })
99
+ return mods
100
+
101
+
102
+ def read_lang_files(archive: zipfile.ZipFile) -> dict[str, dict[str, str]]:
103
+ result: dict[str, dict[str, str]] = {}
104
+ for name in archive.namelist():
105
+ match = LANG_RE.match(name)
106
+ if not match:
107
+ continue
108
+ locale = match.group(2)
109
+ data = read_json_entry(archive, name)
110
+ if not isinstance(data, dict):
111
+ continue
112
+ bucket = result.setdefault(locale, {})
113
+ for key, value in data.items():
114
+ if isinstance(value, str):
115
+ bucket[key] = value
116
+ return result
117
+
118
+
119
+ def key_to_id(key: str) -> str | None:
120
+ match = ITEM_KEY_RE.match(key)
121
+ if not match:
122
+ return None
123
+ namespace = match.group(2).split(".")[0]
124
+ path = match.group(3)
125
+ if not namespace or not path:
126
+ return None
127
+ return f"{namespace}:{path}"
128
+
129
+
130
+ def discover_model_ids(archive: zipfile.ZipFile) -> set[str]:
131
+ ids: set[str] = set()
132
+ for name in archive.namelist():
133
+ match = re.match(r"^assets/([^/]+)/models/item/(.+)\.json$", name)
134
+ if match:
135
+ ids.add(f"{match.group(1)}:{match.group(2)}")
136
+ continue
137
+ match = re.match(r"^assets/([^/]+)/blockstates/(.+)\.json$", name)
138
+ if match:
139
+ ids.add(f"{match.group(1)}:{match.group(2)}")
140
+ return ids
141
+
142
+
143
+ def extract_item_ids(value: Any) -> list[str]:
144
+ found: list[str] = []
145
+ if isinstance(value, dict):
146
+ for key in ("item", "id"):
147
+ item = value.get(key)
148
+ if isinstance(item, str):
149
+ found.append(item)
150
+ tag = value.get("tag")
151
+ if isinstance(tag, str):
152
+ found.append("#" + tag)
153
+ for child in value.values():
154
+ found.extend(extract_item_ids(child))
155
+ elif isinstance(value, list):
156
+ for child in value:
157
+ found.extend(extract_item_ids(child))
158
+ return found
159
+
160
+
161
+ def parse_recipe(data: dict) -> dict | None:
162
+ result = data.get("result")
163
+ result_id = None
164
+ count = 1
165
+ if isinstance(result, str):
166
+ result_id = result
167
+ elif isinstance(result, dict):
168
+ for key in ("item", "id"):
169
+ if isinstance(result.get(key), str):
170
+ result_id = result[key]
171
+ break
172
+ try:
173
+ count = int(result.get("count", 1))
174
+ except (TypeError, ValueError):
175
+ count = 1
176
+ if not result_id:
177
+ return None
178
+ try:
179
+ count = int(data.get("count", count))
180
+ except (TypeError, ValueError):
181
+ pass
182
+ ingredients: list[str] = []
183
+ for key in ("ingredients", "key", "ingredient", "base", "addition", "template"):
184
+ if key in data:
185
+ ingredients.extend(extract_item_ids(data[key]))
186
+ deduped = []
187
+ for item in ingredients:
188
+ if item != result_id and item not in deduped:
189
+ deduped.append(item)
190
+ return {
191
+ "type": str(data.get("type") or ""),
192
+ "result": result_id,
193
+ "count": count,
194
+ "ingredients": deduped,
195
+ }
196
+
197
+
198
+ def scan_recipes(archive: zipfile.ZipFile) -> dict[str, list[dict]]:
199
+ recipes: dict[str, list[dict]] = {}
200
+ for name in archive.namelist():
201
+ parts = name.split("/")
202
+ if len(parts) < 4 or parts[0] != "data" or parts[2] not in RECIPE_DIRS:
203
+ continue
204
+ if not name.endswith(".json"):
205
+ continue
206
+ data = read_json_entry(archive, name)
207
+ if not isinstance(data, dict):
208
+ continue
209
+ parsed = parse_recipe(data)
210
+ if not parsed:
211
+ continue
212
+ parsed["file"] = name
213
+ recipes.setdefault(parsed["result"], []).append(parsed)
214
+ return recipes
215
+
216
+
217
+ def scan_jar(path: Path) -> tuple[dict, list[dict], dict[str, list[dict]], set[str], dict[str, str], dict[str, str]]:
218
+ try:
219
+ archive = zipfile.ZipFile(path)
220
+ except (OSError, zipfile.BadZipFile) as error:
221
+ raise IndexError_(f"不是可读的 jar:{path}:{error}") from error
222
+ with archive:
223
+ mods = read_mod_metadata(archive)
224
+ lang = read_lang_files(archive)
225
+ en = lang.get("en_us", {})
226
+ zh = lang.get("zh_cn", {})
227
+ model_ids = discover_model_ids(archive)
228
+ recipes = scan_recipes(archive)
229
+ key_ids = {key_to_id(key) for key in set(en) | set(zh)}
230
+ key_ids.discard(None)
231
+ return mods, lang, recipes, model_ids, en, zh
232
+
233
+
234
+ def build_index(mods_dir: Path) -> dict:
235
+ jars = sorted(mods_dir.glob("*.jar"))
236
+ items: dict[str, dict] = {}
237
+ warnings: list[str] = []
238
+ for jar in jars:
239
+ try:
240
+ mods, _, recipes, model_ids, en, zh = scan_jar(jar)
241
+ except IndexError_ as error:
242
+ warnings.append(str(error))
243
+ continue
244
+ mod_by_namespace = {mod["id"]: mod for mod in mods}
245
+ namespace_ids: set[str] = set(model_ids)
246
+ for key in set(en) | set(zh):
247
+ item_id = key_to_id(key)
248
+ if item_id:
249
+ namespace_ids.add(item_id)
250
+ for item_id in namespace_ids:
251
+ namespace, _, path = item_id.partition(":")
252
+ if not path:
253
+ continue
254
+ entry = items.setdefault(item_id, {
255
+ "id": item_id,
256
+ "mod": namespace,
257
+ "mod_name": mod_by_namespace.get(namespace, {}).get("name", namespace),
258
+ "name_en": None,
259
+ "name_zh": None,
260
+ "recipes": [],
261
+ "sources": [],
262
+ })
263
+ key_candidates = [f"item.{namespace}.{path}", f"block.{namespace}.{path}", f"tile.{namespace}.{path}.name"]
264
+ if entry["name_en"] is None:
265
+ entry["name_en"] = next((en[key] for key in key_candidates if key in en), None)
266
+ if entry["name_zh"] is None:
267
+ entry["name_zh"] = next((zh[key] for key in key_candidates if key in zh), None)
268
+ if jar.name not in entry["sources"]:
269
+ entry["sources"].append(jar.name)
270
+ for recipe in recipes.get(item_id, []):
271
+ if recipe not in entry["recipes"]:
272
+ entry["recipes"].append(recipe)
273
+ for item_id, recipe_list in recipes.items():
274
+ if item_id in items:
275
+ continue
276
+ namespace, _, path = item_id.partition(":")
277
+ items[item_id] = {
278
+ "id": item_id,
279
+ "mod": namespace,
280
+ "mod_name": mod_by_namespace.get(namespace, {}).get("name", namespace),
281
+ "name_en": None,
282
+ "name_zh": None,
283
+ "recipes": recipe_list,
284
+ "sources": [jar.name],
285
+ }
286
+ for recipe_list in recipes.values():
287
+ for recipe in recipe_list:
288
+ for ingredient in recipe.get("ingredients", []):
289
+ if ingredient.startswith("#"):
290
+ continue
291
+ namespace, _, path = ingredient.partition(":")
292
+ if namespace in mod_by_namespace and ingredient not in items:
293
+ items[ingredient] = {
294
+ "id": ingredient,
295
+ "mod": namespace,
296
+ "mod_name": mod_by_namespace.get(namespace, {}).get("name", namespace),
297
+ "name_en": None,
298
+ "name_zh": None,
299
+ "recipes": [],
300
+ "sources": [jar.name],
301
+ }
302
+ for entry in items.values():
303
+ entry["sources"].sort()
304
+ entry["recipes"].sort(key=lambda item: item.get("file", ""))
305
+ return {
306
+ "generatedAt": datetime.now(timezone.utc).isoformat(timespec="seconds"),
307
+ "modsDir": str(mods_dir),
308
+ "jarCount": len(jars),
309
+ "itemCount": len(items),
310
+ "warnings": warnings,
311
+ "items": dict(sorted(items.items())),
312
+ }
313
+
314
+
315
+ def main() -> int:
316
+ configure_stdout()
317
+ parser = argparse.ArgumentParser(description="扫描 mods/*.jar 生成 items.json。")
318
+ parser.add_argument("mods_dir", help="包含 jar 的 mods 目录。")
319
+ parser.add_argument("--output", default="items.json", help="输出 JSON 路径,默认 items.json。")
320
+ parser.add_argument("--indent", type=int, default=2, help="JSON 缩进,默认 2。")
321
+ args = parser.parse_args()
322
+ mods_dir = Path(args.mods_dir)
323
+ if not mods_dir.is_dir():
324
+ print(f"错误:目录不存在:{mods_dir}", file=sys.stderr)
325
+ return 1
326
+ index = build_index(mods_dir)
327
+ output = Path(args.output)
328
+ output.parent.mkdir(parents=True, exist_ok=True)
329
+ output.write_text(
330
+ json.dumps(index, ensure_ascii=False, indent=args.indent) + "\n",
331
+ encoding="utf-8",
332
+ )
333
+ print(f"已生成:{output}")
334
+ print(f"jar:{index['jarCount']} 物品:{index['itemCount']} 警告:{len(index['warnings'])}")
335
+ missing_zh = sum(1 for item in index["items"].values() if item["name_zh"] is None)
336
+ missing_en = sum(1 for item in index["items"].values() if item["name_en"] is None)
337
+ print(f"缺英文名:{missing_en} 缺中文名:{missing_zh}")
338
+ for warning in index["warnings"][:10]:
339
+ print(f"警告:{warning}", file=sys.stderr)
340
+ return 0
341
+
342
+
343
+ if __name__ == "__main__":
344
+ raise SystemExit(main())