add an exhaust function that returns the last item yielded by an iterator. used to implement the non-iterator versions of various functions
This commit is contained in:
parent
cde2e7c78f
commit
51b052813b
@ -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;
|
||||
|
3
level.py
3
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(
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user