copyEntitiesFromInfiniteIter now accepts the 'entities' argument, telling it when to copy both entities and tileentities.... xxx find a way to compose functions that operate on chunk-slices

This commit is contained in:
David Vierra 2011-08-17 00:27:26 -10:00
parent 3cc5f77874
commit 5ddcd6bb40

View File

@ -633,17 +633,18 @@ class MCLevel(object):
class EntityLevel(MCLevel): class EntityLevel(MCLevel):
"""Abstract subclass of MCLevel that adds default entity behavior""" """Abstract subclass of MCLevel that adds default entity behavior"""
def copyEntitiesFromInfiniteIter(self, sourceLevel, sourceBox, destinationPoint): def copyEntitiesFromInfiniteIter(self, sourceLevel, sourceBox, destinationPoint, entities):
chunkCount = sourceBox.chunkCount chunkCount = sourceBox.chunkCount
i = 0 i = 0
copyOffset = map(lambda x, y:x - y, destinationPoint, sourceBox.origin) copyOffset = map(lambda x, y:x - y, destinationPoint, sourceBox.origin)
e = t = 0
for (chunk, slices, point) in sourceLevel.getChunkSlices(sourceBox): for (chunk, slices, point) in sourceLevel.getChunkSlices(sourceBox):
self.copyEntitiesFromInfiniteChunk(chunk, slices, point, sourceBox, copyOffset)
yield (i, chunkCount) yield (i, chunkCount)
i += 1 i += 1
def copyEntitiesFromInfiniteChunk(self, chunk, slices, point, sourceBox, copyOffset): if entities:
e += len(chunk.Entities)
for entityTag in chunk.Entities: for entityTag in chunk.Entities:
x, y, z = Entity.pos(entityTag) x, y, z = Entity.pos(entityTag)
if (x, y, z) not in sourceBox: continue if (x, y, z) not in sourceBox: continue
@ -652,6 +653,7 @@ class EntityLevel(MCLevel):
self.addEntity(eTag); self.addEntity(eTag);
t += len(chunk.TileEntities)
for tileEntityTag in chunk.TileEntities: for tileEntityTag in chunk.TileEntities:
x, y, z = TileEntity.pos(tileEntityTag) x, y, z = TileEntity.pos(tileEntityTag)
if (x, y, z) not in sourceBox: continue if (x, y, z) not in sourceBox: continue
@ -660,6 +662,7 @@ class EntityLevel(MCLevel):
self.addTileEntity(eTag) self.addTileEntity(eTag)
info("Copied {0} entities, {1} tile entities".format(e, t))
@ -670,7 +673,7 @@ class EntityLevel(MCLevel):
sourcePoint1 = sourceBox.maximum; sourcePoint1 = sourceBox.maximum;
if sourceLevel.isInfinite: if sourceLevel.isInfinite:
for i in self.copyEntitiesFromInfiniteIter(sourceLevel, sourceBox, destinationPoint): for i in self.copyEntitiesFromInfiniteIter(sourceLevel, sourceBox, destinationPoint, entities):
yield i yield i
else: else:
entsCopied = 0; entsCopied = 0;
@ -699,7 +702,7 @@ class EntityLevel(MCLevel):
pass pass
yield yield
debug(u"Copied {0} entities, {1} tile entities".format(entsCopied, tileEntsCopied)) info(u"Copied {0} entities, {1} tile entities".format(entsCopied, tileEntsCopied))
def getEntitiesInBox(self, box): def getEntitiesInBox(self, box):
"""Returns a list of references to entities in this chunk, whose positions are within box""" """Returns a list of references to entities in this chunk, whose positions are within box"""