本文整理汇总了Python中entity.TileEntity.copyWithOffset方法的典型用法代码示例。如果您正苦于以下问题:Python TileEntity.copyWithOffset方法的具体用法?Python TileEntity.copyWithOffset怎么用?Python TileEntity.copyWithOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entity.TileEntity
的用法示例。
在下文中一共展示了TileEntity.copyWithOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyEntitiesFromInfiniteIter
# 需要导入模块: from entity import TileEntity [as 别名]
# 或者: from entity.TileEntity import copyWithOffset [as 别名]
def copyEntitiesFromInfiniteIter(self, sourceLevel, sourceBox, destinationPoint, entities):
chunkCount = sourceBox.chunkCount
i = 0
copyOffset = map(lambda x, y: x - y, destinationPoint, sourceBox.origin)
e = t = 0
for (chunk, slices, point) in sourceLevel.getChunkSlices(sourceBox):
yield (i, chunkCount)
i += 1
if entities:
e += len(chunk.Entities)
for entityTag in chunk.Entities:
x, y, z = Entity.pos(entityTag)
if (x, y, z) not in sourceBox:
continue
eTag = Entity.copyWithOffset(entityTag, copyOffset)
self.addEntity(eTag)
t += len(chunk.TileEntities)
for tileEntityTag in chunk.TileEntities:
x, y, z = TileEntity.pos(tileEntityTag)
if (x, y, z) not in sourceBox:
continue
eTag = TileEntity.copyWithOffset(tileEntityTag, copyOffset)
self.addTileEntity(eTag)
info("Copied {0} entities, {1} tile entities".format(e, t))
示例2: copyEntitiesFromIter
# 需要导入模块: from entity import TileEntity [as 别名]
# 或者: from entity.TileEntity import copyWithOffset [as 别名]
def copyEntitiesFromIter(self, sourceLevel, sourceBox, destinationPoint, entities=True):
# assume coords have already been adjusted by copyBlocks
# if not self.hasEntities or not sourceLevel.hasEntities:
# return
sourcePoint0 = sourceBox.origin
if sourceLevel.isInfinite:
for i in self.copyEntitiesFromInfiniteIter(sourceLevel, sourceBox, destinationPoint, entities):
yield i
else:
entsCopied = 0
tileEntsCopied = 0
copyOffset = map(lambda x, y: x - y, destinationPoint, sourcePoint0)
if entities:
for entity in sourceLevel.getEntitiesInBox(sourceBox):
eTag = Entity.copyWithOffset(entity, copyOffset)
self.addEntity(eTag)
entsCopied += 1
i = 0
for entity in sourceLevel.getTileEntitiesInBox(sourceBox):
i += 1
if i % 100 == 0:
yield
if not 'x' in entity:
continue
eTag = TileEntity.copyWithOffset(entity, copyOffset)
try:
self.addTileEntity(eTag)
tileEntsCopied += 1
except ChunkNotPresent:
pass
yield
info(u"Copied {0} entities, {1} tile entities".format(entsCopied, tileEntsCopied))
示例3: copyBlocksFromIter
# 需要导入模块: from entity import TileEntity [as 别名]
# 或者: from entity.TileEntity import copyWithOffset [as 别名]
def copyBlocksFromIter(destLevel, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True,
create=False, biomes=False, tileTicks=True, staticCommands=False, moveSpawnerPos=False, regenerateUUID=False, first=False, cancelCommandBlockOffset=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
tt = 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)
if sourceChunkBox.volume == 0:
continue
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]
def copy(p):
return p in sourceChunkBoxInDestLevel and (blocksToCopy is None or mask[
int(p[0] - sourceChunkBoxInDestLevel.minx),
int(p[2] - sourceChunkBoxInDestLevel.minz),
int(p[1] - sourceChunkBoxInDestLevel.miny),
])
if entities:
destChunk.removeEntities(copy)
ents = sourceChunk.getEntitiesInBox(destChunkBoxInSourceLevel)
e += len(ents)
for entityTag in ents:
eTag = Entity.copyWithOffset(entityTag, copyOffset, regenerateUUID)
destLevel.addEntity(eTag)
destChunk.removeTileEntities(copy)
tileEntities = sourceChunk.getTileEntitiesInBox(destChunkBoxInSourceLevel)
t += len(tileEntities)
for tileEntityTag in tileEntities:
eTag = TileEntity.copyWithOffset(tileEntityTag, copyOffset, staticCommands, moveSpawnerPos, first, cancelCommandBlockOffset)
destLevel.addTileEntity(eTag)
#.........这里部分代码省略.........
示例4: copyBlocksFromIter
# 需要导入模块: from entity import TileEntity [as 别名]
# 或者: from entity.TileEntity import copyWithOffset [as 别名]
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)
if sourceChunkBox.volume == 0:
continue
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))