Last active
November 25, 2016 20:06
-
-
Save infinitewarp/bfeea7b7e03b234cb0ab776324d9043c to your computer and use it in GitHub Desktop.
Get potential full size of a map from a list of Minecraft region files
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
from __future__ import print_function | |
import re | |
from sys import argv, exit | |
pattern = r'.*r\.(-?[0-9]+)\.(-?[0-9]+)\.mca$' | |
matcher = re.compile(pattern) | |
north, south, east, west = None, None, None, None | |
def region_blocks(rx, rz): | |
min_x = 512 * rx | |
max_x = min_x + 511 | |
min_z = 512 * rz | |
max_z = min_z + 511 | |
return min_x, max_x, min_z, max_z | |
for filename in argv[1:]: | |
match = matcher.match(filename) | |
if match: | |
anvil_x, anvil_z = map(int, match.groups()) | |
if west is None or anvil_x < west[0]: | |
west = anvil_x, filename | |
if north is None or anvil_z < north[0]: | |
north = anvil_z, filename | |
if east is None or anvil_x > east[0]: | |
east = anvil_x, filename | |
if south is None or anvil_z > south[0]: | |
south = anvil_z, filename | |
else: | |
print("Not a region file: {0}".format(filename)) | |
if None in (north, south, east, west): | |
print("No region filenames found") | |
exit(1) | |
min_x, _, min_z, _ = region_blocks(west[0], north[0]) | |
_, max_x, _, max_z = region_blocks(east[0], south[0]) | |
for direction, value in (('west', west), ('north', north), ('east', east), ('south', south)): | |
print("Most {0}ern region file is {1} at {2}".format(direction, value[1], value[0])) | |
print("Possible blocks span ({0}, {1}) to ({2}, {3})".format(min_z, min_x, max_z, max_x)) | |
print("x-delta, z-delta is {0}, {1}".format(abs(max_x - min_x + 1), abs(max_z - min_z + 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment