Files
TFMC-resource-pack/tools/update_disc_names.py
Marc 33a2c4c852
All checks were successful
Release Resource Pack / release (push) Successful in 27s
change name of items?
2025-10-08 21:16:17 +02:00

81 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Normalize music disc base names AND description lines plus cookie rename across all locales.
We set BOTH the base display name (item.minecraft.music_disc_<id>) and the tooltip/hover line
(.desc) so the in-inventory name and the subtitle line match custom music.
Target mapping (base + desc get same value):
11 -> Yunge Kutta - Linjären
13 -> Yunge Kutta - Nabla Aura
blocks -> Yunge Kutta - Plugga
cat -> Yunge Kutta - F (Skålar & Pokaler)
chirp -> Big F - Fysik
Additionally rename cookie to Amanuenskaka
Logic:
* For each locale JSON, insert or update the needed keys.
* Preserve other keys untouched.
* Use 2-space indentation, UTF-8, no ASCII escaping.
"""
from __future__ import annotations
import json
from pathlib import Path
LANG_DIR = Path('assets/minecraft/lang')
DISC_MAP = {
"11": "Yunge Kutta - Linjären",
"13": "Yunge Kutta - Nabla Aura",
"blocks": "Yunge Kutta - Plugga",
"cat": "Yunge Kutta - F (Skålar & Pokaler)",
"chirp": "Big F - Fysik",
}
EXTRA_KEYS = {
"item.minecraft.cookie": "Amanuenskaka",
}
def main() -> int:
if not LANG_DIR.is_dir():
print(f"Language directory not found: {LANG_DIR}")
return 1
changed_files = 0
for path in sorted(LANG_DIR.glob('*.json')):
try:
text = path.read_text(encoding='utf-8')
data = json.loads(text)
except Exception as e:
print(f"Skipping {path}: cannot parse JSON ({e})")
continue
updated = False
# Apply disc base + desc keys
for disc_id, value in DISC_MAP.items():
base_key = f"item.minecraft.music_disc_{disc_id}"
desc_key = f"{base_key}.desc"
if data.get(base_key) != value:
data[base_key] = value
updated = True
if data.get(desc_key) != value:
data[desc_key] = value
updated = True
# Apply extra keys
for key, value in EXTRA_KEYS.items():
if data.get(key) != value:
data[key] = value
updated = True
if updated:
# Dump with indent=2 and ensure_ascii False to keep UTF-8 characters
new_text = json.dumps(data, ensure_ascii=False, indent=2, sort_keys=False) + "\n"
# Minimize diff: only overwrite if content changed
if new_text != text:
path.write_text(new_text, encoding='utf-8')
changed_files += 1
print(f"Updated: {path}")
print(f"Done. Files changed: {changed_files}")
return 0
if __name__ == '__main__': # pragma: no cover
raise SystemExit(main())