当前位置: 首页>>代码示例>>Python>>正文


Python Tree.placetreesinregion方法代码示例

本文整理汇总了Python中tree.Tree.placetreesinregion方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.placetreesinregion方法的具体用法?Python Tree.placetreesinregion怎么用?Python Tree.placetreesinregion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Tree的用法示例。


在下文中一共展示了Tree.placetreesinregion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import placetreesinregion [as 别名]
def main():
    """Builds a region."""
    # example:
    # ./BuildRegion.py --name BlockIsland

    # parse options and get results
    parser = argparse.ArgumentParser(description='Builds Minecraft worlds from regions.')
    parser.add_argument('--name', required=True, type=str, help='name of the region to be built')
    parser.add_argument('--debug', action='store_true', help='enable debug output')
    parser.add_argument('--single', action='store_true', help='enable single-threaded mode for debugging or profiling')
    args = parser.parse_args()

    # enable debug
    if (args.debug):
        print "Do something!"

    # build the region
    print "Building region %s..." % args.name
    yamlfile = file(os.path.join('Regions', args.name, 'Region.yaml'))
    myRegion = yaml.load(yamlfile)
    yamlfile.close()

    # exit if map does not exist
    if not os.path.exists(myRegion.mapname):
        raise IOError, "no map file exists"

    # tree and ore variables
    treeobjs = dict([(tree.name, tree) for tree in treeObjs])
    trees = dict([(name, list()) for name in treeobjs])
    oreobjs = dict([(ore.name, ore) for ore in oreObjs])
    ores = dict([(name, list()) for name in oreobjs])

    # generate overall world
    worlddir = os.path.join('Worlds', args.name)
    world = mclevel.MCInfdevOldLevel(worlddir, create=True)
    peak = [0, 0, 0]

    # generate individual tiles
    tilexrange = xrange(myRegion.tiles['xmin'], myRegion.tiles['xmax'])
    tileyrange = xrange(myRegion.tiles['ymin'], myRegion.tiles['ymax'])
    name = myRegion.name
    tiles = [(name, x, y) for x, y in product(tilexrange, tileyrange)]
    if args.single:
        # single process version - works
        for tile in tiles:
            buildtile(tile)
    else:
        # multi-process ... let's see...
        pool = Pool()
        pool.map(buildtile, tiles)
        pool.close()
        pool.join()

    # merge individual worlds into it
    print "Merging %d tiles into one world..." % len(tiles)
    for tile in tiles:
        (name, x, y) = tile
        tiledir = os.path.join('Regions', name, 'Tiles', '%dx%d' % (x, y))
        tilefile = file(os.path.join(tiledir, 'Tile.yaml'))
        newtile = yaml.load(tilefile)
        tilefile.close()
        if (newtile.peak[1] > peak[1]):
            peak = newtile.peak
        for treetype in newtile.trees:
            trees.setdefault(treetype, []).extend(newtile.trees[treetype])
        if myRegion.doOre:
            for oretype in newtile.ores:
                ores.setdefault(oretype, []).extend(newtile.ores[oretype])
        tileworld = mclevel.MCInfdevOldLevel(tiledir, create=False)
        world.copyBlocksFrom(tileworld, tileworld.bounds, tileworld.bounds.origin)
        tileworld = False

    # plant trees in our world
    print "Planting %d trees at the region level..." % sum([len(trees[treetype]) for treetype in trees])
    Tree.placetreesinregion(trees, treeobjs, world)

    # deposit ores in our world
    if myRegion.doOre:
        print "Depositing %d ores at the region level..." % sum([len(ores[oretype]) for oretype in ores])
        Ore.placeoreinregion(ores, oreobjs, world)

    # replace all 'end stone' with stone
    print "Replacing all 'end stone' with stone..."
    EndStoneID = world.materials["End Stone"].ID
    StoneID = world.materials["Stone"].ID
    for xpos, zpos in world.allChunks:
        chunk = world.getChunk(xpos, zpos)
        chunk.Blocks[chunk.Blocks == EndStoneID] = StoneID

    # tie up loose ends
    setspawnandsave(world, peak)
开发者ID:jiwalker-usgs,项目名称:TopoMC,代码行数:93,代码来源:BuildRegion.py

示例2: main

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import placetreesinregion [as 别名]

#.........这里部分代码省略.........
        log.log_warn("Single-threaded region merge")
        for tile in tiles:
            buildtile(tile)
    else:
        # multi-process version
        pool = Pool()
        rs = pool.map_async(buildtile, tiles)
        pool.close()
        while not(rs.ready()):
            remaining = rs._number_left
            log.log_info("Waiting for %s buildtile tasks to complete..." %
                         remaining)
            time.sleep(10)
        pool.join()        # Just as a precaution.

    # Necessary for tile-welding -> regions
    cleanmkdir(worlddir)
    cleanmkdir(os.path.join(worlddir, 'region'))

    # Generate regions
    if not(args.safemerge):
        regionsize = 32 * 16
        regionxrange = xrange(int(floor(myRegion.tiles['xmin'] * (myRegion.tilesize / float(regionsize)))), \
                              int(ceil(myRegion.tiles['xmax'] * (myRegion.tilesize / float(regionsize)))))
        regionyrange = xrange(int(floor(myRegion.tiles['ymin'] * (myRegion.tilesize / float(regionsize)))), \
                              int(ceil(myRegion.tiles['ymax'] * (myRegion.tilesize / float(regionsize)))))
    
        regions = [(log, name, x, y) for x, y in product(regionxrange, regionyrange)]
    
        # merge individual tiles into regions
        log.log_info("Merging %d tiles into one world..." % len(tiles))
        for tile in tiles:
            (dummy, name, x, y) = tile
            tiledir = os.path.join('Regions', name, 'Tiles', '%dx%d' % (x, y))
            if not(os.path.isfile(os.path.join(tiledir, 'Tile.yaml'))):
                log.log_fatal("The following tile is missing. Please re-run this script:\n%s" % \
                      os.path.join(tiledir, 'Tile.yaml'))

        if args.single:
            # single process version
            log.log_warn("Single-threaded region merge")
            for region in regions:
                buildregion(region)
        else:
            # multi-process version
            pool = Pool()
            rs = pool.map_async(buildregion, regions)
            pool.close()
            while not(rs.ready()):
                remaining = rs._number_left
                log.log_info("Waiting for %s buildregion tasks to complete..." %
                             remaining)
                time.sleep(10)
            pool.join()        # Just as a precaution.

    world = mclevel.MCInfdevOldLevel(worlddir, create=True)
    if not(args.safemerge):
        mcoffsetx = myRegion.tiles['xmin'] * myRegion.tilesize
        mcoffsetz = myRegion.tiles['ymin'] * myRegion.tilesize
        mcsizex   = (myRegion.tiles['xmax'] - myRegion.tiles['xmin']) * myRegion.tilesize
        mcsizez   = (myRegion.tiles['ymax'] - myRegion.tiles['ymin']) * myRegion.tilesize
        tilebox = box.BoundingBox((mcoffsetx, 0, mcoffsetz), (mcsizex, world.Height, mcsizez))
        world.createChunksInBox(tilebox)

    for tile in tiles:
        (dummy, name, x, y) = tile
        tiledir = os.path.join('Regions', name, 'Tiles', '%dx%d' % (x, y))
        tilefile = file(os.path.join(tiledir, 'Tile.yaml'))
        newtile = yaml.load(tilefile)
        tilefile.close()
        if (newtile.peak[1] > peak[1]):
            peak = newtile.peak
        for treetype in newtile.trees:
            trees.setdefault(treetype, []).extend(newtile.trees[treetype])
        if myRegion.doOre:
            for oretype in newtile.ores:
                ores.setdefault(oretype, []).extend(newtile.ores[oretype])
        if args.safemerge:
            tileworld = mclevel.MCInfdevOldLevel(tiledir, create=False)
            world.copyBlocksFrom(tileworld, tileworld.bounds, tileworld.bounds.origin)
            tileworld = False

    # plant trees in our world
    log.log_info("Planting %d trees at the region level..." % \
                 sum([len(trees[treetype]) for treetype in trees]))
    Tree.placetreesinregion(trees, treeobjs, world)

    # deposit ores in our world
    if myRegion.doOre:
        log.log_info("Depositing %d ores at the region level..." % \
                     sum([len(ores[oretype]) for oretype in ores]))
        Ore.placeoreinregion(ores, oreobjs, world)

    # tie up loose ends
    world.setPlayerGameType(1)
    setspawnandsave(world, peak)
    oldyamlpath = os.path.join('Regions', args.name, 'Region.yaml')
    newyamlpath = os.path.join('Worlds', args.name, 'Region.yaml')
    shutil.copy(oldyamlpath, newyamlpath)
    shutil.rmtree(os.path.join('Regions', name, 'Tiles'))
开发者ID:KermMartian,项目名称:TopoMC,代码行数:104,代码来源:BuildRegion.py


注:本文中的tree.Tree.placetreesinregion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。