Exemple #1
0
def main(argv=None):
    args = parse_args(argv)

    # setup_logging(args.loglevel)
    logging.basicConfig(level=args.loglevel,
                        format='%(levelname)s: %(message)s')
    log.debug(args)

    world = mc.load(args.world)

    for name, arg, func in (
        ('entity', args.entity, find_entity),
        ('block', args.block, find_block),
    ):
        if arg is None:
            continue
        log.info("Searching for %s '%s' on the entire world", name, arg)
        eid = ename = arg.lower()
        if ':' not in eid:
            eid = 'minecraft:' + eid
        count = 0
        for chunk in world.get_chunks(
                progress=(args.loglevel >= logging.INFO)):
            ename, ecount = func(chunk, eid, ename)
            count += ecount
        print(f"{ename} [{eid}]: {count}")
        return

    if (args.tag_value is not None or args.tag_name is not None
            or args.tag_type is not None or args.tag_path is not None):
        find_nbt(world, args)
        return
Exemple #2
0
def make_world(from_world, region, ranges, to_world=None):
    if to_world is None:
        to_world = from_world
    print(from_world, region, ranges, to_world)
    ensure_dir_exists(to_world + '/floors')
    jsn_file = from_world + '.json'
    world = mc.load(make_world_path(from_world))
    print()
    # print_regions(world.regions)
    # for chunk in world.get_chunks():
    #     mc.pretty(chunk)

    all_blocks, important_blocks = mg.generate_maps(world, region, ranges,
                                                    to_world, False)
    mg.generate_json(all_blocks, ranges, to_world, jsn_file)
Exemple #3
0
def importbook(levelname,
               playername=None,
               filename=None,
               separator="---",
               append=True,
               create=True,
               save=False):
    try:
        sep = "\n%s\n" % separator
        with openstd(filename, 'r') as (fd, name):
            pages = fd.read()[:-1].rstrip(sep).split(sep)
            log.debug("Importing %d pages from %s", len(pages), name)

        world = mc.load(levelname)
        player = world.get_player(playername)

    except (mc.MCError, IOError) as e:
        log.error(e)
        return

    log.info("Importing book to '%s' in '%s' ('%s')", player.name, world.name,
             world.filename)

    try:
        book, bookpages = get_bookpages(player.inventory)
        log.debug("Found book in inventory slot %d", book["Slot"])

    except LookupError as e:
        if not create:
            log.error("%s, and create is not enabled.", e)
            return

        log.info("%s, so creating a new one.", e)
        try:
            book, bookpages = new_book(player.inventory)
            log.debug("Created book in inventory slot %d\n%r", book["Slot"],
                      book)
        except LookupError as e:
            log.error(e)
            return

    if not append:
        del (bookpages[:])

    for page in pages:
        bookpages.append(mc.nbt.String(page))

    mc.save_world(world, save)
Exemple #4
0
def exportbook(levelname, playername=None, filename=None, separator="---"):
    try:
        world = mc.load(levelname)
        player = world.get_player(playername)

        log.info("Exporting book from '%s' in '%s' (%r)", player.name,
                 world.name, world.filename)

        book, pages = get_bookpages(player.inventory)

        log.debug("Found book in inventory slot %d", book["Slot"])

        with openstd(filename, 'w') as (fd, name):
            log.debug("Exporting %d pages to %s", len(pages), name)
            fd.write(("\n%s\n" % separator).join(pages) + "\n")

    except (mc.MCError, LookupError, IOError) as e:
        log.error(e)
        return
Exemple #5
0
## pip3 install nbtlib
import map_generator as mg
import sys

sys.path.append('MCWorldlib.egg')
import mcworldlib as mc
from os.path import join

world_name = 'Saturn_Training_Feb4'  ## 'Falcon v1.02' ## name of the Minecraft world folder in input/worlds/
region = (
    -5, 0
)  ## name of the .mca file where you can find the building  22, 25 or 60, 63

building_ranges = {  ## x_low, x_high, z_low, z_high, y_low, y_high
    'Singleplayer': (-2192, -2129, 144, 191, 28, 30),
    'Sparky v3.03': (-2176, -2097, 144, 207, 52, 54),
    #     'Saturn_Feb4': (-2240, -2065, -96, -1, 60, 64), # r.-5.-1.mca
    'Saturn_Training_Feb4': (-2240, -2065, 0, 143, 60, 63),  # r.-5.0.mca
    #     'Falcon v1.02': (-2112, -2049, 128, 207, 60, 62)   # r.-5.0.mca
    #     'Falcon v1.02': (-2048, -2017, 128, 207, 60, 62)   # r.-4.0.mca
}
ranges = building_ranges[world_name]

## load the world folder, which takes a while but only need to do it once
world = mc.load(join('inputs', 'worlds', world_name))

all_blocks, important_blocks = mg.generate_maps(world, region, ranges)
mg.generate_json(all_blocks, ranges)
mg.generate_csv(important_blocks, ranges)