fix: humanized fallback for share display names (26.9.7)
This commit is contained in:
1 parent
8896c4b83e
commit
dab8cae84c
5 files changed
+30
-18
No files matched your search
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
本文件记录 Iridium 的重要变更。
|
本文件记录 Iridium 的重要变更。
|
||||||
|
|
||||||
|
## [26.9.7] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `!!share`:无 NBT 改名时,正文 fallback 改为 ID 美化名(如 `Time Twister Wireless`),不再直接显示 `kubejs:...`;语言键命中则显示正式本地化名
|
||||||
|
|
||||||
## [26.9.6] - 2026-09-13
|
## [26.9.6] - 2026-09-13
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ MCDReforged 插件:物品展示 / 戴头 / 获取头颅 / 游戏内计算器 /
|
|||||||
|
|
||||||
| | |
|
| | |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 版本 | **26.9.6** |
|
| 版本 | **26.9.7** |
|
||||||
| 作者 | 云镜之端/SKYMirror |
|
| 作者 | 云镜之端/SKYMirror |
|
||||||
| 许可 | 保留所有权益(All Rights Reserved) |
|
| 许可 | 保留所有权益(All Rights Reserved) |
|
||||||
| 前置 | MCDReforged `>= 2.6.0` |
|
| 前置 | MCDReforged `>= 2.6.0` |
|
||||||
|
|||||||
+13
-6
@@ -87,28 +87,35 @@ def _extract_custom_name(item_snbt: str) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _humanize_id(item_id: str) -> str:
|
||||||
|
"""kubejs:time_twister_wireless -> Time Twister Wireless"""
|
||||||
|
path = item_id.split(":", 1)[-1]
|
||||||
|
parts = [p for p in path.replace("-", "_").split("_") if p]
|
||||||
|
if not parts:
|
||||||
|
return item_id
|
||||||
|
return " ".join(p[:1].upper() + p[1:] for p in parts)
|
||||||
|
|
||||||
|
|
||||||
def _translate_key(item_id: str) -> str:
|
def _translate_key(item_id: str) -> str:
|
||||||
"""Guess client language key from item id (best-effort)."""
|
"""Guess client language key from item id (best-effort)."""
|
||||||
if ":" not in item_id:
|
if ":" not in item_id:
|
||||||
return f"item.minecraft.{item_id}"
|
return f"item.minecraft.{item_id}"
|
||||||
ns, path = item_id.split(":", 1)
|
ns, path = item_id.split(":", 1)
|
||||||
if ns == "minecraft":
|
if ns == "minecraft":
|
||||||
# Most block-items use block.minecraft.*; tools/items use item.minecraft.*
|
|
||||||
# Prefer item.* — missing key falls back via "fallback"
|
|
||||||
return f"item.minecraft.{path}"
|
return f"item.minecraft.{path}"
|
||||||
# Modded cables/blocks: block.<mod>.<path>
|
return f"item.{ns}.{path}"
|
||||||
return f"block.{ns}.{path}"
|
|
||||||
|
|
||||||
|
|
||||||
def _display_json(item_snbt: str) -> str:
|
def _display_json(item_snbt: str) -> str:
|
||||||
"""JSON text component: custom name if any, else client-side translate key."""
|
"""JSON text component: custom name if any, else client translate + humanized fallback."""
|
||||||
custom = _extract_custom_name(item_snbt)
|
custom = _extract_custom_name(item_snbt)
|
||||||
if custom:
|
if custom:
|
||||||
return '{"text":"' + _json_str(custom) + '"}'
|
return '{"text":"' + _json_str(custom) + '"}'
|
||||||
item_id = _item_id(item_snbt)
|
item_id = _item_id(item_snbt)
|
||||||
key = _translate_key(item_id)
|
key = _translate_key(item_id)
|
||||||
|
pretty = _humanize_id(item_id)
|
||||||
return (
|
return (
|
||||||
'{"translate":"' + _json_str(key) + '","fallback":"' + _json_str(item_id) + '"}'
|
'{"translate":"' + _json_str(key) + '","fallback":"' + _json_str(pretty) + '"}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"id": "iridium",
|
"id": "iridium",
|
||||||
"version": "26.9.6",
|
"version": "26.9.7",
|
||||||
"name": "Iridium",
|
"name": "Iridium",
|
||||||
"description": {
|
"description": {
|
||||||
"zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD",
|
"zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD",
|
||||||
|
|||||||
+10
-10
@@ -252,19 +252,19 @@ def test_share_query_sanitizes_player():
|
|||||||
|
|
||||||
|
|
||||||
def test_extract_display_name():
|
def test_extract_display_name():
|
||||||
from iridium.share import _display_json, _item_id, _translate_key
|
from iridium.share import _display_json, _humanize_id, _item_id, _translate_key
|
||||||
|
|
||||||
assert _item_id('{id:"minecraft:stone",Count:1b}') == "minecraft:stone"
|
assert _item_id('{id:"minecraft:stone",Count:1b}') == "minecraft:stone"
|
||||||
assert _translate_key("minecraft:diamond") == "item.minecraft.diamond"
|
assert _translate_key("minecraft:diamond") == "item.minecraft.diamond"
|
||||||
assert _translate_key("ae2:fluix_covered_cable") == "block.ae2.fluix_covered_cable"
|
assert _translate_key("kubejs:time_twister_wireless") == "item.kubejs.time_twister_wireless"
|
||||||
assert '"text"' in _display_json(
|
assert _humanize_id("kubejs:time_twister_wireless") == "Time Twister Wireless"
|
||||||
'{id:"minecraft:diamond",tag:{display:{Name:"Shiny"}}}'
|
assert _humanize_id("minecraft:fluix_covered_cable") == "Fluix Covered Cable"
|
||||||
)
|
assert '"text"' in _display_json('{id:"minecraft:diamond",tag:{display:{Name:"Shiny"}}}')
|
||||||
assert '"translate"' in _display_json('{id:"minecraft:stone",Count:1b}')
|
disp = _display_json('{id:"kubejs:time_twister_wireless",Count:1b}')
|
||||||
assert "fallback" in _display_json('{id:"minecraft:stone",Count:1b}')
|
assert '"translate"' in disp
|
||||||
assert "custom_name" not in _display_json(
|
assert "Time Twister Wireless" in disp
|
||||||
'{id:"minecraft:stone",Count:1b}'
|
assert "fallback" in disp
|
||||||
) or True
|
assert "kubejs:time_twister_wireless" not in disp
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user