diff --git a/infiniteworld.py b/infiniteworld.py index c541258..a81b867 100644 --- a/infiniteworld.py +++ b/infiniteworld.py @@ -37,12 +37,6 @@ Player = 'Player' __all__ = ["ZeroChunk", "InfdevChunk", "MCInfdevOldLevel", "MCAlphaDimension", "ZipSchematic"] -def exhaust(_iter): - i = 0 - for i in _iter: - pass - return i - import re convert = lambda text: int(text) if text.isdigit() else text @@ -1647,7 +1641,7 @@ class MCInfdevOldLevel(EntityLevel): self.loadedChunkQueue.discard(chunk) def chunkDidLoad(self, chunk): - if not chunk in self.loadedChunkQueue: + if chunk not in self.loadedChunkQueue: self.loadedChunkQueue.append(chunk); if self.loadedChunkLimit and (len(self.loadedChunkQueue) > self.loadedChunkLimit): oldestChunk = self.loadedChunkQueue[0]; @@ -2003,8 +1997,7 @@ class MCInfdevOldLevel(EntityLevel): info(u"Saved {0} chunks".format(dirtyChunkCount)) def generateLights(self, dirtyChunks=None): - for i in self.generateLightsIter(dirtyChunks): - pass + return exhaust(self.generateLightsIter(dirtyChunks)) def generateLightsIter(self, dirtyChunks=None): """ dirtyChunks may be an iterable yielding (xPos,zPos) tuples @@ -2570,8 +2563,7 @@ class MCInfdevOldLevel(EntityLevel): def copyBlocksFrom(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True): - for i in self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities): - pass + return exhaust(self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities)) def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True): (x, y, z) = destinationPoint; diff --git a/level.py b/level.py index 0ac3212..3ed2bcf 100644 --- a/level.py +++ b/level.py @@ -476,8 +476,7 @@ class MCLevel(object): def copyBlocksFrom(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True): - for i in self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities): - pass + return exhaust(self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities)) def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True): if (not sourceLevel.isInfinite) and not( diff --git a/mclevelbase.py b/mclevelbase.py index 78f6c46..1936cb0 100644 --- a/mclevelbase.py +++ b/mclevelbase.py @@ -63,4 +63,14 @@ class ChunkNotPresent(Exception): pass class RegionMalformed(Exception): pass class ChunkMalformed(ChunkNotPresent): pass + +def exhaust(_iter): + """Functions named ending in "Iter" return an iterable object that does + long-running work and yields progress information on each call. exhaust() + is used to implement the non-Iter equivalents""" + i = None + for i in _iter: + pass + return i + from level import MCLevel, EntityLevel diff --git a/schematic.py b/schematic.py index 7b7bd7f..37e4ace 100644 --- a/schematic.py +++ b/schematic.py @@ -473,10 +473,7 @@ def adjustExtractionParameters(self, box): return box, (destX, destY, destZ) def extractSchematicFrom(sourceLevel, box, entities=True): - i = None - for i in extractSchematicFromIter(sourceLevel, box, entities): - pass - return i + return exhaust(extractSchematicFromIter(sourceLevel, box, entities)) def extractSchematicFromIter(sourceLevel, box, entities=True): p = sourceLevel.adjustExtractionParameters(box); @@ -496,9 +493,7 @@ MCLevel.adjustExtractionParameters = adjustExtractionParameters import tempfile def extractZipSchematicFrom(sourceLevel, box, zipfilename=None, entities=True): - for i in extractZipSchematicFromIter(sourceLevel, box, zipfilename, entities): - pass - return i + return exhaust(extractZipSchematicFromIter(sourceLevel, box, zipfilename, entities)) def extractZipSchematicFromIter(sourceLevel, box, zipfilename=None, entities=True): #converts classic blocks to alpha