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"]
|
__all__ = ["ZeroChunk", "InfdevChunk", "MCInfdevOldLevel", "MCAlphaDimension", "ZipSchematic"]
|
||||||
|
|
||||||
def exhaust(_iter):
|
|
||||||
i = 0
|
|
||||||
for i in _iter:
|
|
||||||
pass
|
|
||||||
return i
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
convert = lambda text: int(text) if text.isdigit() else text
|
convert = lambda text: int(text) if text.isdigit() else text
|
||||||
@ -1647,7 +1641,7 @@ class MCInfdevOldLevel(EntityLevel):
|
|||||||
self.loadedChunkQueue.discard(chunk)
|
self.loadedChunkQueue.discard(chunk)
|
||||||
|
|
||||||
def chunkDidLoad(self, chunk):
|
def chunkDidLoad(self, chunk):
|
||||||
if not chunk in self.loadedChunkQueue:
|
if chunk not in self.loadedChunkQueue:
|
||||||
self.loadedChunkQueue.append(chunk);
|
self.loadedChunkQueue.append(chunk);
|
||||||
if self.loadedChunkLimit and (len(self.loadedChunkQueue) > self.loadedChunkLimit):
|
if self.loadedChunkLimit and (len(self.loadedChunkQueue) > self.loadedChunkLimit):
|
||||||
oldestChunk = self.loadedChunkQueue[0];
|
oldestChunk = self.loadedChunkQueue[0];
|
||||||
@ -2003,8 +1997,7 @@ class MCInfdevOldLevel(EntityLevel):
|
|||||||
info(u"Saved {0} chunks".format(dirtyChunkCount))
|
info(u"Saved {0} chunks".format(dirtyChunkCount))
|
||||||
|
|
||||||
def generateLights(self, dirtyChunks=None):
|
def generateLights(self, dirtyChunks=None):
|
||||||
for i in self.generateLightsIter(dirtyChunks):
|
return exhaust(self.generateLightsIter(dirtyChunks))
|
||||||
pass
|
|
||||||
|
|
||||||
def generateLightsIter(self, dirtyChunks=None):
|
def generateLightsIter(self, dirtyChunks=None):
|
||||||
""" dirtyChunks may be an iterable yielding (xPos,zPos) tuples
|
""" 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):
|
def copyBlocksFrom(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
||||||
for i in self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities):
|
return exhaust(self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities))
|
||||||
pass
|
|
||||||
|
|
||||||
def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
||||||
(x, y, z) = destinationPoint;
|
(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):
|
def copyBlocksFrom(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
||||||
for i in self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities):
|
return exhaust(self.copyBlocksFromIter(sourceLevel, sourceBox, destinationPoint, blocksToCopy, entities))
|
||||||
pass
|
|
||||||
|
|
||||||
def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
def copyBlocksFromIter(self, sourceLevel, sourceBox, destinationPoint, blocksToCopy=None, entities=True):
|
||||||
if (not sourceLevel.isInfinite) and not(
|
if (not sourceLevel.isInfinite) and not(
|
||||||
|
@ -63,4 +63,14 @@ class ChunkNotPresent(Exception): pass
|
|||||||
class RegionMalformed(Exception): pass
|
class RegionMalformed(Exception): pass
|
||||||
class ChunkMalformed(ChunkNotPresent): 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
|
from level import MCLevel, EntityLevel
|
||||||
|
@ -473,10 +473,7 @@ def adjustExtractionParameters(self, box):
|
|||||||
return box, (destX, destY, destZ)
|
return box, (destX, destY, destZ)
|
||||||
|
|
||||||
def extractSchematicFrom(sourceLevel, box, entities=True):
|
def extractSchematicFrom(sourceLevel, box, entities=True):
|
||||||
i = None
|
return exhaust(extractSchematicFromIter(sourceLevel, box, entities))
|
||||||
for i in extractSchematicFromIter(sourceLevel, box, entities):
|
|
||||||
pass
|
|
||||||
return i
|
|
||||||
|
|
||||||
def extractSchematicFromIter(sourceLevel, box, entities=True):
|
def extractSchematicFromIter(sourceLevel, box, entities=True):
|
||||||
p = sourceLevel.adjustExtractionParameters(box);
|
p = sourceLevel.adjustExtractionParameters(box);
|
||||||
@ -496,9 +493,7 @@ MCLevel.adjustExtractionParameters = adjustExtractionParameters
|
|||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
def extractZipSchematicFrom(sourceLevel, box, zipfilename=None, entities=True):
|
def extractZipSchematicFrom(sourceLevel, box, zipfilename=None, entities=True):
|
||||||
for i in extractZipSchematicFromIter(sourceLevel, box, zipfilename, entities):
|
return exhaust(extractZipSchematicFromIter(sourceLevel, box, zipfilename, entities))
|
||||||
pass
|
|
||||||
return i
|
|
||||||
|
|
||||||
def extractZipSchematicFromIter(sourceLevel, box, zipfilename=None, entities=True):
|
def extractZipSchematicFromIter(sourceLevel, box, zipfilename=None, entities=True):
|
||||||
#converts classic blocks to alpha
|
#converts classic blocks to alpha
|
||||||
|
Reference in New Issue
Block a user