Example #1
0
def get_size(world_folder):
    # uses the nbt library which gives better results for anvil files
    world = AnvilWorldFolder(world_folder)  # Not supported for McRegion
    if not world.nonempty():  # likely still a McRegion file
        sys.stderr.write("World folder %r is empty or not an Anvil formatted world\n" % world_folder)
        return 65  # EX_DATAERR
    bb = world.get_boundingbox()
    return bb.lenx() * bb.lenz()
Example #2
0
def main(world_path: str, check: bool = False):
    total_found = 0

    for world in WORLDS.keys():
        print(f"Checking the {world}")
        world_folder = AnvilWorldFolder(path.join(world_path, WORLDS[world]))

        regions = world_folder.regionfiles

        if len(regions) == 0:
            print(f"Couldn't find region files for the {world}, skipping")
            continue

        with Bar("Checking Regions", fill="█", max=len(regions)) as bar:
            for region_coords in regions.keys():
                region = RegionFile(regions[region_coords])
                chunks = region.get_metadata()

                for chunk in chunks:
                    chunk_x = region_coords[0] * 32 + chunk.x
                    chunk_z = region_coords[1] * 32 + chunk.z

                    nbt = world_folder.get_nbt(chunk_x, chunk_z)
                    found_errors = False
                    entities = nbt["Level"]["TileEntities"]

                    for entity in entities:
                        if not in_chunk(chunk_x, chunk_z, entity['x'],
                                        entity['z']):
                            total_found += 1
                            found_errors = True

                            # Move the entity to the (hopefully) right coordinates
                            entity["x"].value = chunk_x * 16 + (
                                to_int(entity['x']) % 16)
                            entity["z"].value = chunk_z * 16 + (
                                to_int(entity['z']) % 16)

                    if found_errors and not check:
                        region.write_chunk(chunk.x, chunk.z, nbt)

                bar.next()

        print(
            f"{ 'Found' if check else 'Fixed'} {total_found} entities with wrong coordinates"
        )
Example #3
0
def main(world_folder):
    world = AnvilWorldFolder(world_folder)  # Not supported for McRegion
    if not world.nonempty():  # likely still a McRegion file
        sys.stderr.write("World folder %r is empty or not an Anvil formatted world\n" % world_folder)
        return 65  # EX_DATAERR
    biome_totals = [0]*256 # 256 counters for 256 biome IDs
    
    try:
        for chunk in world.iter_nbt():
            for biomeid in chunk["Level"]["Biomes"]:
                biome_totals[biomeid] += 1

    except KeyboardInterrupt:
        print_results(biome_totals)
        return 75 # EX_TEMPFAIL
    
    print_results(biome_totals)
    return 0 # NOERR
Example #4
0
def main(world_folder):
    world = AnvilWorldFolder(world_folder)  # Not supported for McRegion
    if not world.nonempty():  # likely still a McRegion file
        sys.stderr.write("World folder %r is empty or not an Anvil formatted world\n" % world_folder)
        return 65  # EX_DATAERR
    biome_totals = [0]*256 # 256 counters for 256 biome IDs
    
    try:
        for chunk in world.iter_nbt():
            for biomeid in chunk["Level"]["Biomes"]:
                biome_totals[biomeid] += 1

    except KeyboardInterrupt:
        print_results(biome_totals)
        return 75 # EX_TEMPFAIL
    
    print_results(biome_totals)
    return 0 # NOERR