Created
January 19, 2024 10:41
-
-
Save zydeco/5ff803f49fce174c0944afc123510b07 to your computer and use it in GitHub Desktop.
mca diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mcworldlib as mc | |
import deepdiff | |
import re | |
from sys import argv | |
#argv = [None, 'world/region/r.0.0.original.mca', 'world/region/r.0.0.mca'] | |
name1 = argv[1] | |
name2 = argv[2] | |
file1 = mc.anvil.load_region(name1) | |
file2 = mc.anvil.load_region(name2) | |
chunks1 = set(file1.keys()) | |
chunks2 = set(file2.keys()) | |
if chunks1 != chunks2: | |
print("Chunks missing:") | |
removed = (chunks1-chunks2) | |
added = (chunks2-chunks1) | |
if len(removed) > 0: | |
print(f"-{removed}") | |
if len(added) > 0: | |
print(f"+{added}") | |
def chunkdiff(chunk1, chunk2): | |
keys1 = chunk1.keys() | |
keys2 = chunk2.keys() | |
if keys1 != keys2: | |
removed = set(keys1) - set(keys2) | |
added = set(keys2) - set(keys1) | |
if len(removed) > 0: | |
print(f"-{removed}") | |
if len(added) > 0: | |
print(f"+{added}") | |
for key in keys1: | |
k1 = chunk1[key] | |
k2 = chunk2[key] | |
if k1 != k2: | |
diff = deepdiff.DeepDiff(k1, k2) | |
for path in diff.affected_paths: | |
changed = diff['values_changed'][path] | |
printable_path = re.sub('^root', key, path) | |
print(f"-{printable_path} = {changed['old_value']}") | |
print(f"+{printable_path} = {changed['new_value']}") | |
return None | |
for chunk in set.intersection(chunks1, chunks2): | |
chunk1 = file1[chunk] | |
chunk2 = file2[chunk] | |
if chunk1 != chunk2: | |
print(f"in chunk {chunk}:") | |
chunkdiff(chunk1, chunk2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment