コード例 #1
0
    def testCopyConvertBlocks(self):
        indevlevel = self.indevLevel.level
        level = self.anvilLevel.level
        x, y, z = level.bounds.origin
        x += level.bounds.size[0] / 2 & ~15
        z += level.bounds.size[2] / 2 & ~15
        x -= indevlevel.Width / 2
        z -= indevlevel.Height / 2

        middle = (x, y, z)

        oldEntityCount = len(
            level.getEntitiesInBox(BoundingBox(middle,
                                               indevlevel.bounds.size)))
        level.copyBlocksFrom(indevlevel, indevlevel.bounds, middle)

        convertedSourceBlocks, convertedSourceData = block_copy.convertBlocks(
            indevlevel, level, indevlevel.Blocks[0:16, 0:16,
                                                 0:indevlevel.Height],
            indevlevel.Data[0:16, 0:16, 0:indevlevel.Height])

        assert ((level.getChunk(
            x >> 4, z >>
            4).Blocks[0:16, 0:16,
                      0:indevlevel.Height] == convertedSourceBlocks).all())

        assert (oldEntityCount +
                len(indevlevel.getEntitiesInBox(indevlevel.bounds)) == len(
                    level.getEntitiesInBox(
                        BoundingBox(middle, indevlevel.bounds.size))))
コード例 #2
0
    def _degrief(self, command):
        """
    degrief [ <height> ]

    Reverse a few forms of griefing by removing
    Adminium, Obsidian, Fire, and Lava wherever
    they occur above the specified height.
    Without a height, uses height level 32.

    Removes natural surface lava.

    Also see removeEntities
    """
        box = self.level.bounds
        box = BoundingBox(box.origin + (0, 32, 0), box.size - (0, 32, 0))
        if len(command):
            try:
                box.miny = int(command[0])
            except ValueError:
                pass

        print "Removing grief matter and surface lava above height {0}...".format(box.miny)

        self.level.fillBlocks(box,
                              self.level.materials.Air,
                              blocksToReplace=[self.level.materials.Bedrock,
                                self.level.materials.Obsidian,
                                self.level.materials.Fire,
                                self.level.materials.LavaActive,
                                self.level.materials.Lava,
                                ]
                              )
        self.needsSave = True
コード例 #3
0
ファイル: mce.py プロジェクト: 1060460048/Cura
    def _degrief(self, command):
        """
    degrief [ <height> ]

    Reverse a few forms of griefing by removing
    Adminium, Obsidian, Fire, and Lava wherever
    they occur above the specified height.
    Without a height, uses height level 32.

    Removes natural surface lava.

    Also see removeEntities
    """
        box = self.level.bounds
        box = BoundingBox(box.origin + (0, 32, 0), box.size - (0, 32, 0))
        if len(command):
            try:
                box.miny = int(command[0])
            except ValueError:
                pass

        print "Removing grief matter and surface lava above height {0}...".format(box.miny)

        self.level.fillBlocks(box,
                              self.level.materials.Air,
                              blocksToReplace=[self.level.materials.Bedrock,
                                self.level.materials.Obsidian,
                                self.level.materials.Fire,
                                self.level.materials.LavaActive,
                                self.level.materials.Lava,
                                ]
                              )
        self.needsSave = True
コード例 #4
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testCreate(self):
        # info("Schematic from indev")

        size = (64, 64, 64)
        temp = mktemp("testcreate.schematic")
        schematic = MCSchematic(shape=size, filename=temp, mats='Classic')
        level = self.indevlevel.level

        self.failUnlessRaises(
            ValueError, lambda: (schematic.copyBlocksFrom(
                level, BoundingBox((-32, -32, -32), (
                    64,
                    64,
                    64,
                )), (0, 0, 0))))

        schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (
            64,
            64,
            64,
        )), (0, 0, 0))
        assert ((schematic.Blocks[0:64, 0:64,
                                  0:64] == level.Blocks[0:64, 0:64,
                                                        0:64]).all())
        schematic.compress()

        schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (
            64,
            64,
            64,
        )), (-32, -32, -32))
        assert ((schematic.Blocks[0:32, 0:32,
                                  0:32] == level.Blocks[32:64, 32:64,
                                                        32:64]).all())

        schematic.compress()

        schematic.saveInPlace()

        schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
        tempSchematic = MCSchematic(shape=(1, 1, 3))
        tempSchematic.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)),
                                     (0, 0, 0))

        info("Schematic from alpha")
        level = self.alphalevel.level
        for cx, cz in itertools.product(xrange(0, 4), xrange(0, 4)):
            try:
                level.createChunk(cx, cz)
            except ValueError:
                pass
        schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (
            64,
            64,
            64,
        )), (0, 0, 0))
        schematic.close()
        os.remove(temp)
コード例 #5
0
def adjustCopyParameters(destLevel, sourceLevel, sourceBox, destinationPoint):
    log.debug(u"Asked to copy {} blocks \n\tfrom {} in {}\n\tto {} in {}".format(
        sourceBox.volume, sourceBox, sourceLevel, destinationPoint, destLevel))
    if destLevel.Width == 0:
        return sourceBox, destinationPoint

    destBox = BoundingBox(destinationPoint, sourceBox.size)
    actualDestBox = destBox.intersect(destLevel.bounds)

    actualSourceBox = BoundingBox(sourceBox.origin + actualDestBox.origin - destBox.origin, destBox.size)
    actualDestPoint = actualDestBox.origin

    return actualSourceBox, actualDestPoint
コード例 #6
0
ファイル: block_copy.py プロジェクト: f5inet/MCEdit-Unified
def adjustCopyParameters(destLevel, sourceLevel, sourceBox, destinationPoint):
    log.debug(u"Asked to copy {} blocks \n\tfrom {} in {}\n\tto {} in {}".format(
        sourceBox.volume, sourceBox, sourceLevel, destinationPoint, destLevel))
    if destLevel.Width == 0:
        return sourceBox, destinationPoint

    destBox = BoundingBox(destinationPoint, sourceBox.size)
    actualDestBox = destBox.intersect(destLevel.bounds)

    actualSourceBox = BoundingBox(sourceBox.origin + actualDestBox.origin - destBox.origin, destBox.size)
    actualDestPoint = actualDestBox.origin

    return actualSourceBox, actualDestPoint
コード例 #7
0
ファイル: world.py プロジェクト: avlepage/modelcraft
    def getWorldBounds(self):
        if self.chunkCount == 0:
            return BoundingBox((0, 0, 0), (0, 0, 0))

        allChunks = np.array(list(self.allChunks))
        min_cx = (allChunks[:, 0]).min()
        max_cx = (allChunks[:, 0]).max()
        min_cz = (allChunks[:, 1]).min()
        max_cz = (allChunks[:, 1]).max()

        origin = (min_cx << 4, 0, min_cz << 4)
        size = ((max_cx - min_cx + 1) << 4, self.Height,
                (max_cz - min_cz + 1) << 4)

        return BoundingBox(origin, size)
コード例 #8
0
    def _clone(self, command):
        """
    clone <sourceBox> <destPoint> [noair] [nowater]

    Clone blocks in a cuboid starting at sourcePoint and extending for
    sourceSize blocks in each direction. Blocks and entities in the area
    are cloned at destPoint.
    """
        if len(command) == 0:
            self.printUsage("clone")
            return

        box = self.readBox(command)

        destPoint = self.readPoint(command)

        destPoint = map(int, map(floor, destPoint))
        blocksToCopy = self.readBlocksToCopy(command)

        tempSchematic = self.level.extractSchematic(box)
        self.level.copyBlocksFrom(tempSchematic,
                                  BoundingBox((0, 0, 0), box.origin),
                                  destPoint, blocksToCopy)

        self.needsSave = True
        print "Cloned 0 blocks."
コード例 #9
0
def find_or_make_blob(contour, tracked_blobs, frame, frame_num, conf):
    """Find a blob that matches a contour.
    Otherwise create a new one.
    """
    # Find the bounding rectangle and center for each blob
    box = BoundingBox(*cv2.boundingRect(contour))

    ## Optionally draw the rectangle around the blob on the frame
    # that we'll show in a UI later
    cv2.rectangle(frame, box.top_left, box.bottom_right, (0, 0, 255),
                  conf.line_thickness)

    # Look for existing blobs that match this one
    closest_blob = None
    if tracked_blobs:
        closest_blob = get_closest_blob(tracked_blobs, box.center, conf)

    # If we found a blob to attach this blob to, we should
    # do some math to help us with speed detection
    if closest_blob:
        return add_blob_metadata(closest_blob, box, frame_num)

    # If we didn't find a blob, let's make a new one and add it to the list
    return {
        'id': str(uuid.uuid4())[:8],
        'first_seen': frame_num,
        'last_seen': frame_num,
        'dir': None,
        'bumper_x': None,
        'trail': [box.center],
        'box': box,
    }
コード例 #10
0
ファイル: block_copy.py プロジェクト: Alexhb61/MCEdit-Unified
def adjustCopyParameters(destLevel, sourceLevel, sourceBox, destinationPoint):
    # if the destination box is outside the level, it and the source corners are moved inward to fit.
    (dx, dy, dz) = map(int, destinationPoint)

    log.debug(u"Asked to copy {} blocks \n\tfrom {} in {}\n\tto {} in {}".format(
        sourceBox.volume, sourceBox, sourceLevel, destinationPoint, destLevel))
    if destLevel.Width == 0:
        return sourceBox, destinationPoint

    destBox = BoundingBox(destinationPoint, sourceBox.size)
    actualDestBox = destBox.intersect(destLevel.bounds)

    actualSourceBox = BoundingBox(sourceBox.origin + actualDestBox.origin - destBox.origin, destBox.size)
    actualDestPoint = actualDestBox.origin

    return actualSourceBox, actualDestPoint
コード例 #11
0
def adjustCopyParameters(destLevel, sourceLevel, sourceBox, destinationPoint):
    # if the destination box is outside the level, it and the source corners are moved inward to fit.
    (dx, dy, dz) = map(int, destinationPoint)
    
    log.debug(u"Asked to copy {} blocks \n\tfrom {} in {}\n\tto {} in {}".format(
        sourceBox.volume, sourceBox, sourceLevel, destinationPoint, destLevel))
    if destLevel.Width == 0:
        return sourceBox, destinationPoint

    destBox = BoundingBox(destinationPoint, sourceBox.size)
    actualDestBox = destBox.intersect(destLevel.bounds)

    actualSourceBox = BoundingBox(sourceBox.origin + actualDestBox.origin - destBox.origin, destBox.size)
    actualDestPoint = actualDestBox.origin

    return actualSourceBox, actualDestPoint
コード例 #12
0
    def _import(self, command):
        """
    import <filename> <destPoint> [noair] [nowater]
    
    Imports a level or schematic into this world, beginning at destPoint.
    Supported formats include 
    - Alpha single or multiplayer world folder containing level.dat,
    - Zipfile containing Alpha world folder,
    - Classic single-player .mine, 
    - Classic multiplayer server_level.dat,
    - Indev .mclevel
    - Schematic from RedstoneSim, MCEdit, mce
    - .inv from INVEdit (appears as a chest)
    """
        if len(command) == 0:
            self.printUsage("import")
            return

        filename = command.pop(0)
        destPoint = self.readPoint(command)
        blocksToCopy = self.readBlocksToCopy(command)

        importLevel = mclevel.fromFile(filename)

        destBox = BoundingBox(destPoint, importLevel.size)

        self.level.copyBlocksFrom(importLevel,
                                  importLevel.bounds,
                                  destPoint,
                                  blocksToCopy,
                                  create=True)

        self.needsSave = True
        print "Imported {0} blocks.".format(importLevel.bounds.volume)
コード例 #13
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testFill(self):
        level = self.alphalevel.level
        cx, cz = level.allChunks.next()
        box = BoundingBox((cx * 16, 0, cz * 16), (38, level.Height, 25))
        level.fillBlocks(box, level.materials.WoodPlanks)
        c = level.getChunk(cx, cz)

        assert (c.Blocks == 5).all()
コード例 #14
0
def locate_templates(img, templates, start, stop, threshold):
    locations, scale = match(img, templates, start, stop, threshold)
    img_locations = []
    for i in range(len(templates)):
        w, h = templates[i].shape[::-1]
        w *= scale
        h *= scale
        img_locations.append([BoundingBox(pt[0], pt[1], w, h) for pt in zip(*locations[i][::-1])])
    return img_locations
コード例 #15
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
 def testFill(self):
     indevlevel = self.indevlevel.level
     indevlevel.fillBlocks(
         BoundingBox((0, 0, 0), (
             64,
             64,
             64,
         )), indevlevel.materials.Sand,
         [indevlevel.materials.Stone, indevlevel.materials.Dirt])
     indevlevel.saveInPlace()
コード例 #16
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
 def testZipSchematic(self):
     level = self.alphalevel.level
     box = BoundingBox((0, 0, 0), (
         64,
         64,
         64,
     ))
     zs = level.extractZipSchematic(box)
     assert (box.chunkCount == zs.chunkCount)
     zs.close()
     os.remove(zs.filename)
コード例 #17
0
    def testFill(self):
        level = self.anvilLevel.level
        cx, cz = level.allChunks.next()
        box = BoundingBox((cx * 16, 0, cz * 16), (32, level.Height, 32))
        level.fillBlocks(box, level.materials.WoodPlanks)
        level.fillBlocks(box, level.materials.WoodPlanks,
                         [level.materials.Stone])
        level.saveInPlace()
        c = level.getChunk(cx, cz)

        assert (c.Blocks == 5).all()
コード例 #18
0
 def testCopy(self):
     indevlevel = self.indevlevel.level
     srclevel = self.srclevel.level
     indevlevel.copyBlocksFrom(srclevel,
                               BoundingBox((0, 0, 0), (
                                   64,
                                   64,
                                   64,
                               )), (0, 0, 0))
     assert ((indevlevel.Blocks[0:64, 0:64,
                                0:64] == srclevel.Blocks[0:64, 0:64,
                                                         0:64]).all())
コード例 #19
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testImportSchematic(self):
        level = self.alphalevel.level
        cx, cz = level.allChunks.next()

        schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
        box = BoundingBox((cx * 16, 64, cz * 16), schem.bounds.size)
        level.copyBlocksFrom(schem, schem.bounds, (0, 64, 0))
        schem = MCSchematic(shape=schem.bounds.size)
        schem.copyBlocksFrom(level, box, (0, 0, 0))
        convertedSourceBlocks, convertedSourceData = schem.convertBlocksFromLevel(
            level, schem.Blocks, schem.Data)
        assert (level.getChunk(
            cx, cz).Blocks[0:1, 0:3, 64:65] == convertedSourceBlocks).all()
コード例 #20
0
def adjustExtractionParameters(self, box):
    x, y, z = box.origin
    w, h, l = box.size
    destX = destY = destZ = 0

    if y < 0:
        destY -= y
        h += y
        y = 0

    if y >= self.Height:
        return

    if y + h >= self.Height:
        h -= y + h - self.Height
        y = self.Height - h

    if h <= 0:
        return

    if self.Width:
        if x < 0:
            w += x
            destX -= x
            x = 0
        if x >= self.Width:
            return

        if x + w >= self.Width:
            w = self.Width - x

        if w <= 0:
            return

        if z < 0:
            l += z
            destZ -= z
            z = 0

        if z >= self.Length:
            return

        if z + l >= self.Length:
            l = self.Length - z

        if l <= 0:
            return

    box = BoundingBox((x, y, z), (w, h, l))

    return box, (destX, destY, destZ)
コード例 #21
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testCopyConvertBlocks(self):
        indevlevel = self.indevlevel.level
        level = self.alphalevel.level
        cx, cz = level.allChunks.next()
        level.copyBlocksFrom(indevlevel, BoundingBox(
            (0, 0, 0), (256, 128, 256)), (cx * 16, 0, cz * 16))

        convertedSourceBlocks, convertedSourceData = indevlevel.convertBlocksFromLevel(
            level, indevlevel.Blocks[0:16, 0:16, 0:indevlevel.Height],
            indevlevel.Data[0:16, 0:16, 0:indevlevel.Height])
        assert (level.getChunk(
            cx,
            cz).Blocks[0:16, 0:16,
                       0:indevlevel.Height] == convertedSourceBlocks).all()
コード例 #22
0
    def readBox(self, command):
        self.prettySplit(command)

        sourcePoint = self.readIntPoint(command)
        if command[0].lower() == "to":
            command.pop(0)
            sourcePoint2 = self.readIntPoint(command)
            sourceSize = sourcePoint2 - sourcePoint
        else:
            sourceSize = self.readIntPoint(command, isPoint=False)
        if len([p for p in sourceSize if p <= 0]):
            raise UsageError("Box size cannot be zero or negative")
        box = BoundingBox(sourcePoint, sourceSize)
        return box
コード例 #23
0
    def testZipSchematic(self):
        level = self.anvilLevel.level

        x, y, z = level.bounds.origin
        x += level.bounds.size[0] / 2 & ~15
        z += level.bounds.size[2] / 2 & ~15

        box = BoundingBox((x, y, z), (
            64,
            64,
            64,
        ))
        zs = level.extractZipSchematic(box)
        assert (box.chunkCount == zs.chunkCount)
        zs.close()
        os.remove(zs.filename)
コード例 #24
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testCopy(self):
        indevlevel = self.indevlevel.level
        creativelevel = self.creativelevel.level

        creativelevel.copyBlocksFrom(indevlevel,
                                     BoundingBox((0, 0, 0), (
                                         64,
                                         64,
                                         64,
                                     )), (0, 0, 0))
        assert (numpy.array(
            (indevlevel.Blocks[0:64, 0:64,
                               0:64]) == (creativelevel.Blocks[0:64, 0:64,
                                                               0:64])).all())

        creativelevel.saveInPlace()
コード例 #25
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
    def testSaveRelight(self):
        indevlevel = self.indevlevel.level
        level = self.alphalevel.level

        cx, cz = -3, -1

        level.deleteChunk(cx, cz)

        level.createChunk(cx, cz)
        level.copyBlocksFrom(indevlevel, BoundingBox((0, 0, 0), (
            32,
            64,
            32,
        )), (-96, 32, 0))

        level.generateLights()
        level.saveInPlace()
コード例 #26
0
    def adjustCopyParameters(self, sourceLevel, sourceBox, destinationPoint):

        # if the destination box is outside the level, it and the source corners are moved inward to fit.
        # ValueError is raised if the source corners are outside sourceLevel
        (x, y, z) = map(int, destinationPoint)

        sourceBox = BoundingBox(sourceBox.origin, sourceBox.size)

        (lx, ly, lz) = sourceBox.size
        debug(u"Asked to copy {0} blocks \n\tfrom {1} in {3}\n\tto {2} in {4}".
              format(ly * lz * lx, sourceBox, destinationPoint, sourceLevel,
                     self))

        # clip the source ranges to this level's edges.  move the destination point as needed.
        # xxx abstract this
        if y < 0:
            sourceBox.origin[1] -= y
            sourceBox.size[1] += y
            y = 0
        if y + sourceBox.size[1] > self.Height:
            sourceBox.size[1] -= y + sourceBox.size[1] - self.Height
            y = self.Height - sourceBox.size[1]

        # for infinite levels, don't clip along those dimensions because the
        # infinite copy func will just skip missing chunks
        if self.Width != 0:
            if x < 0:
                sourceBox.origin[0] -= x
                sourceBox.size[0] += x
                x = 0
            if x + sourceBox.size[0] > self.Width:
                sourceBox.size[0] -= x + sourceBox.size[0] - self.Width
                # x=self.Width-sourceBox.size[0]

        if self.Length != 0:
            if z < 0:
                sourceBox.origin[2] -= z
                sourceBox.size[2] += z
                z = 0
            if z + sourceBox.size[2] > self.Length:
                sourceBox.size[2] -= z + sourceBox.size[2] - self.Length
                # z=self.Length-sourceBox.size[2]

        destinationPoint = (x, y, z)

        return sourceBox, destinationPoint
コード例 #27
0
def main():
    """Run the tracker."""
    parser = argparse.ArgumentParser(
        description='Calculate speed of objects in a video.')
    parser.add_argument('input', nargs='*', help='Video file to analyze')
    parser.add_argument('--config',
                        '-c',
                        default='settings.yaml',
                        help='path to config file')
    parser.add_argument('--display',
                        '-d',
                        action='store_true',
                        default=False,
                        help='Show video display')
    parser.add_argument('--speed',
                        '-s',
                        type=float,
                        default=1.0,
                        help='Playback speed')
    parser.add_argument('--focus-speed',
                        '-f',
                        dest='focus_speed',
                        type=float,
                        default=0.25,
                        help='Playback speed when objects are in ROI')
    parser.add_argument('--verbose',
                        '-v',
                        action='store_true',
                        default=False,
                        help='Print extra output')

    args = parser.parse_args()
    conf = Config(args.config)
    conf.update('display', args.display)
    conf.update('speed', args.speed)
    conf.update('focus_speed', args.focus_speed)
    conf.update('verbose', args.verbose)

    # Get region of interest
    roi = BoundingBox(*conf.roi)
    print 'ROI:', roi.top_left, roi.bottom_right

    for input_path in args.input:
        track(input_path, roi, conf)
コード例 #28
0
ファイル: level.py プロジェクト: Lasbleic/GDMC
 def bounds(self):
     cx, cz = self.chunkPosition
     return BoundingBox((cx << 4, 0, cz << 4), self.size)
コード例 #29
0
ファイル: level.py プロジェクト: Lasbleic/GDMC
 def bounds(self):
     return BoundingBox((0, 0, 0), self.size)
コード例 #30
0
ファイル: level.py プロジェクト: Lasbleic/GDMC
 def getWorldBounds(self):
     return BoundingBox((0, 0, 0), self.size)
コード例 #31
0
ファイル: tests.py プロジェクト: dcoshea/pymclevel
 def _testCreate(filename):
     gen.createLevel(filename,
                     BoundingBox((-128, 0, -128), (128, 128, 128)))
コード例 #32
0
def copyBlocksFromIter(destLevel,
                       sourceLevel,
                       sourceBox,
                       destinationPoint,
                       blocksToCopy=None,
                       entities=True,
                       create=False):
    """ copy blocks between two infinite levels by looping through the
    destination's chunks. make a sub-box of the source level for each chunk
    and copy block and entities in the sub box to the dest chunk."""

    (lx, ly, lz) = sourceBox.size

    sourceBox, destinationPoint = adjustCopyParameters(destLevel, sourceLevel,
                                                       sourceBox,
                                                       destinationPoint)
    # needs work xxx
    log.info(u"Copying {0} blocks from {1} to {2}".format(
        ly * lz * lx, sourceBox, destinationPoint))
    startTime = datetime.now()

    destBox = BoundingBox(destinationPoint, sourceBox.size)
    chunkCount = destBox.chunkCount
    i = 0
    e = 0
    t = 0

    sourceMask = sourceMaskFunc(blocksToCopy)

    copyOffset = [d - s for s, d in zip(sourceBox.origin, destinationPoint)]

    # Visit each chunk in the destination area.
    #   Get the region of the source area corresponding to that chunk
    #   Visit each chunk of the region of the source area
    #     Get the slices of the destination chunk
    #     Get the slices of the source chunk
    #     Copy blocks and data

    for destCpos in destBox.chunkPositions:
        cx, cz = destCpos

        destChunkBox = BoundingBox(
            (cx << 4, 0, cz << 4),
            (16, destLevel.Height, 16)).intersect(destBox)
        destChunkBoxInSourceLevel = BoundingBox(
            [d - o for o, d in zip(copyOffset, destChunkBox.origin)],
            destChunkBox.size)

        if not destLevel.containsChunk(*destCpos):
            if create and any(
                    sourceLevel.containsChunk(*c)
                    for c in destChunkBoxInSourceLevel.chunkPositions):
                # Only create chunks in the destination level if the source level has chunks covering them.
                destLevel.createChunk(*destCpos)
            else:
                continue

        destChunk = destLevel.getChunk(*destCpos)

        i += 1
        yield (i, chunkCount)
        if i % 100 == 0:
            log.info("Chunk {0}...".format(i))

        for srcCpos in destChunkBoxInSourceLevel.chunkPositions:
            if not sourceLevel.containsChunk(*srcCpos):
                continue

            sourceChunk = sourceLevel.getChunk(*srcCpos)

            sourceChunkBox, sourceSlices = sourceChunk.getChunkSlicesForBox(
                destChunkBoxInSourceLevel)
            sourceChunkBoxInDestLevel = BoundingBox(
                [d + o for o, d in zip(copyOffset, sourceChunkBox.origin)],
                sourceChunkBox.size)

            _, destSlices = destChunk.getChunkSlicesForBox(
                sourceChunkBoxInDestLevel)

            sourceBlocks = sourceChunk.Blocks[sourceSlices]
            sourceData = sourceChunk.Data[sourceSlices]

            mask = sourceMask(sourceBlocks)
            convertedSourceBlocks, convertedSourceData = convertBlocks(
                destLevel, sourceLevel, sourceBlocks, sourceData)

            destChunk.Blocks[destSlices][mask] = convertedSourceBlocks[mask]
            if convertedSourceData is not None:
                destChunk.Data[destSlices][mask] = convertedSourceData[mask]

            if entities:
                ents = sourceChunk.getEntitiesInBox(destChunkBoxInSourceLevel)
                e += len(ents)
                for entityTag in ents:
                    eTag = Entity.copyWithOffset(entityTag, copyOffset)
                    destLevel.addEntity(eTag)

            tileEntities = sourceChunk.getTileEntitiesInBox(
                destChunkBoxInSourceLevel)
            t += len(tileEntities)
            for tileEntityTag in tileEntities:
                eTag = TileEntity.copyWithOffset(tileEntityTag, copyOffset)
                destLevel.addTileEntity(eTag)

        destChunk.chunkChanged()

    log.info("Duration: {0}".format(datetime.now() - startTime))
    log.info("Copied {0} entities and {1} tile entities".format(e, t))
コード例 #33
0
 def getWorldBounds(self):
     return BoundingBox((0, 0, 0), (self.Width, self.Height, self.Length))