feat(pack): ship offline usernamecache to clients for Jade

Jade resolves tamed-animal owner names client-side; its Mojang profile
lookup can't resolve offline-mode UUIDs and it falls back to NeoForge's
UsernameCache, which the client loads from <game>/usernamecache.json.
Ship that file (side = "client", installed at the game root) so migrated
owners stop showing as "???".

Maintain the mapping with tools/sync-usernamecache.py after new logins.
This commit is contained in:
logan committed 2026-10-06 23:28:00 -04:00
1 parent 0adfb6c656
commit e7d6691466
7 files changed
+92 -1

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""Refresh the pack's client-side usernamecache.json from the live server cache.
The pack ships <game>/usernamecache.json to clients (via usernamecache.pw.toml)
so Jade can resolve offline-mode owner names client-side (it falls back to
NeoForge's UsernameCache after the Mojang lookup fails). This merges the
server's live cache into packfiles/usernamecache-offline.json and updates the
download hash in usernamecache.pw.toml.
Run after new players have logged in, then refresh/commit/push:
python3 tools/sync-usernamecache.py
packwiz refresh
git add packfiles/usernamecache-offline.json usernamecache.pw.toml index.toml pack.toml
git commit -m "chore(pack): refresh client usernamecache"
git push
"""
import hashlib
import json
import pathlib
import re
import sys
ROOT = pathlib.Path(__file__).resolve().parent.parent
LIVE = ROOT / "usernamecache.json"
SHIPPED = ROOT / "packfiles" / "usernamecache-offline.json"
META = ROOT / "usernamecache.pw.toml"
def load(path):
try:
return json.loads(path.read_text(encoding="utf-8"))
except FileNotFoundError:
return {}
def main():
live = load(LIVE)
shipped = load(SHIPPED)
merged = {**shipped, **live} # the live server cache wins
if not merged:
print("no entries found; is the server's usernamecache.json missing?", file=sys.stderr)
return 1
text = json.dumps(merged, indent=2, sort_keys=True) + "\n"
changed = not SHIPPED.exists() or SHIPPED.read_text(encoding="utf-8") != text
SHIPPED.parent.mkdir(parents=True, exist_ok=True)
SHIPPED.write_text(text, encoding="utf-8")
digest = hashlib.sha256(text.encode("utf-8")).hexdigest()
meta = META.read_text(encoding="utf-8")
new_meta = re.sub(r'(?m)^(hash = ")[0-9a-f]+(")$', lambda m: m.group(1) + digest + m.group(2), meta)
if new_meta != meta:
META.write_text(new_meta, encoding="utf-8")
print(f"{len(merged)} entries ({len(live)} live, {len(shipped)} shipped), "
f"{'updated' if changed else 'unchanged'} -> packfiles/usernamecache-offline.json")
print(f"sha256 {digest}")
print("next: packwiz refresh && git add packfiles/usernamecache-offline.json "
"usernamecache.pw.toml index.toml pack.toml && commit && push")
return 0
if __name__ == "__main__":
sys.exit(main())