Public Access
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Average a JSON-exported SavedData block profile, including zero-count chunks."""
|
|
import argparse
|
|
import collections
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def generate(source, version):
|
|
raw = source.read_bytes()
|
|
data = json.loads(raw)["nbt"]["data"]
|
|
samples = data.get("Samples", data.get("samples"))
|
|
if not samples:
|
|
raise ValueError("The source profile has no sampled chunks")
|
|
totals = collections.Counter()
|
|
for sample in samples:
|
|
counts = sample.get("Blocks", sample.get("blocks"))
|
|
if not isinstance(counts, dict) or any(not isinstance(n, int) or n < 0 for n in counts.values()):
|
|
raise ValueError("Invalid sampled block counts")
|
|
totals.update(counts)
|
|
return {
|
|
"minecraft_version": version,
|
|
"source_sample_count": len(samples),
|
|
"source_sha256": hashlib.sha256(raw).hexdigest(),
|
|
"blocks_per_chunk": {key: total / len(samples) for key, total in sorted(totals.items())},
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("source", type=Path)
|
|
parser.add_argument("version", choices=("1.21.1", "26.3"))
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(json.dumps(generate(args.source, args.version), indent=2) + "\n")
|