def test_section_region_mapping_offset_single_region(): coord_range = { "min_x": 0, "min_z": 0, "max_x": 512, "max_z": 512, } offset_x = 512 offset_z = 512 offset = math.coord_offset(offset_x, offset_z) min_bound = math.coord_to_region(coord_range['min_x'], coord_range['min_z']) max_bound = math.coord_to_region(coord_range['max_x'], coord_range['max_z']) regions = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1]) mappings = tuple(math.region_mappings(regions, offset)) print(mappings, sep='\n') assert len(mappings) == 4 assert mappings[0] == ((0, 0), (1, 1)), "head of region mapping not valid" assert mappings[3] == ((1, 1), (2, 2)), "tail of region mapping not valid"
def test_region_for_invalid_range_z(): min_x = 0 min_z = 0 max_x = 0 max_z = -200 min_bound = math.coord_to_region(min_x, min_z) max_bound = math.coord_to_region(max_x, max_z) with pytest.raises(AssertionError): region_ranges = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1])
def test_region_min_max_bounds(): min_x = -1210 min_z = -1357 max_x = 6206 max_z = 6281 min_bound = math.coord_to_region(min_x, min_z) max_bound = math.coord_to_region(max_x, max_z) region_ranges = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1]) assert [-3, -3] in region_ranges, "lower region bound does not exist" assert [12, 12] in region_ranges, "max region bound does not exist"
def output_region_cmd(reg, offset, from_path, to_path): offset = math.coord_to_region(offset[0], offset[1]) from_xy = reg[0] to_xy = reg[1] src_region_file = 'r.{0}.{1}.mca'.format(*from_xy) src_full_file = '{0}/{1}'.format(from_path, src_region_file) dest_region_file = 'r.{0}.{1}.mca'.format(*to_xy) dest_full_file = '{0}/{1}'.format(to_path, dest_region_file) if (path.isfile(src_full_file)): try: nbt_data = region.load_region(src_full_file) region.relocate_region(offset, nbt_data) region.save_region(to_path, dest_region_file, nbt_data) print('Copied "{0}" to "{1}"\n'.format(src_region_file, dest_region_file)) "" except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() print( repr( traceback.format_exception(exc_type, exc_value, exc_traceback))) msg = 'Source doesn\'t exist. Failed to copy "{0}" to "{1}"\n' print(msg.format(src_region_file, dest_region_file)) else: print('Region File Doesn\'t Exist "{0}" to "{1}"\n'.format( src_full_file, dest_full_file))
def test_region_for_coords_0_0_to_neg200_neg200(): max_x = 0 max_z = 0 min_x = -200 min_z = -200 min_bound = math.coord_to_region(min_x, min_z) max_bound = math.coord_to_region(max_x, max_z) region_ranges = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1]) assert [0, 0] in region_ranges, "higher region bound does not exist" assert [-1, -1] in region_ranges, "lower region bound does not exist" assert len( region_ranges) == 4, "small bounds can't be bigger than 1 region"
def calculate_regions(coord_range, offset_coord, from_path, to_path): offset_x = offset_coord[0] offset_z = offset_coord[1] offset = math.coord_offset(offset_x, offset_z) min_bound = math.coord_to_region(coord_range[0], coord_range[1]) max_bound = math.coord_to_region(coord_range[2], coord_range[3]) regions = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1]) mappings = tuple(math.region_mappings(regions, offset)) args = [] l = numpy.array_split(mappings, 8) for region in l: args.append({ 'offset': (offset_x, offset_z), 'from_path': from_path, 'to_path': to_path, 'regions': region }) p = Pool(8) p.map(pool_output_regions, args)
def test_b173_to_v115(): coord_range = { "min_x": -1203, "min_z": -1342, "max_x": 6208, "max_z": 6280, } offset_x = 10000 offset_z = -13000 offset = math.coord_offset(offset_x, offset_z) min_bound = math.coord_to_region(coord_range['min_x'], coord_range['min_z']) max_bound = math.coord_to_region(coord_range['max_x'], coord_range['max_z']) regions = math.regions_for_range(min_bound[0], min_bound[1], max_bound[0], max_bound[1]) mappings = tuple(math.region_mappings(regions, offset)) assert len(mappings) != 0
def test_region_file_offset(datadir): import cProfile with cProfile.Profile() as pr: bio = io.BytesIO() buf = io.BufferedWriter(bio) lines = '' nbt_path = datadir.join('r.0.0.mca.old') nbt_data = region.load_region(str(nbt_path)) offset = region_math.coord_to_region(8192, 8192) region.relocate_region(offset, nbt_data) region.save_region('region', 'r.16.16.mca', nbt_data) pr.print_stats() assert False
def test_invalid_coords(): x = -30000000 z = -30000000 with pytest.raises(AssertionError): math.coord_to_region(x, z)
def test_coords_to_region_0_1(): x = 511 z = 512 assert math.coord_to_region(x, z) == (0, 1)
def test_coords_to_region_1_0(): x = 512 z = 511 assert math.coord_to_region(x, z) == (1, 0)
def test_coords_to_region_1_1(): x = 512 z = 512 assert math.coord_to_region(x, z) == (1, 1)
def test_coords_to_region_0_0(): x = 2 z = 59 assert math.coord_to_region(x, z) == (0, 0)
def test_neg_coords_to_region_0_0(): x = -5 z = -513 assert math.coord_to_region(x, z) == (-1, -2)