#!/usr/bin/env python3 """Prüft die Vorlagenwelt: Wie viele Chunks im geplanten Bereich liegen vollständig generiert vor?""" import glob, json, os, re, struct, sys, zlib, gzip from collections import Counter WELT = sys.argv[1] if len(sys.argv) > 1 else '/root/studien/haertetest/vorlagen/welt' RAND = 88 status = Counter() fehlend_voll = 0 for f in glob.glob(f'{WELT}/dimensions/minecraft/overworld/region/r.*.mca'): m = re.search(r'r\.(-?\d+)\.(-?\d+)\.mca$', f) rx, rz = int(m.group(1)), int(m.group(2)) d = open(f, 'rb').read() if len(d) < 8192: continue for i in range(1024): cx, cz = rx * 32 + (i & 31), rz * 32 + (i >> 5) if not (-RAND <= cx <= RAND and -RAND <= cz <= RAND): continue loc = struct.unpack('>I', d[i * 4:i * 4 + 4])[0] if loc == 0: status['fehlt'] += 1 continue o = (loc >> 8) * 4096 n = struct.unpack('>I', d[o:o + 4])[0] art = d[o + 4] roh = d[o + 5:o + 4 + n] try: t = zlib.decompress(roh) if art == 2 else gzip.decompress(roh) if art == 1 else roh except Exception: status['unlesbar'] += 1 continue k = t.find(b'Status') if k < 0: status['ohne_status'] += 1 continue l = struct.unpack('>H', t[k + 6:k + 8])[0] status[t[k + 8:k + 8 + l].decode('ascii', 'replace')] += 1 soll = (2 * RAND + 1) ** 2 print(json.dumps({'soll_chunks': soll, 'status': status}, ensure_ascii=False))