本文整理汇总了Python中mclevel.fromFile函数的典型用法代码示例。如果您正苦于以下问题:Python fromFile函数的具体用法?Python fromFile怎么用?Python fromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testINVEditChests
def testINVEditChests(self):
info("INVEdit chest")
invFile = mclevel.fromFile("schematics/Chests/TinkerersBox.inv")
info("Blocks: %s", invFile.Blocks)
info("Data: %s", invFile.Data)
info("Entities: %s", invFile.Entities)
info("TileEntities: %s", invFile.TileEntities)
示例2: _import
def _import(self, command):
"""
import <filename> <destPoint> [noair] [nowater]
Imports a level or schematic into this world, beginning at destPoint.
Supported formats include
- Alpha single or multiplayer world folder containing level.dat,
- Zipfile containing Alpha world folder,
- Classic single-player .mine,
- Classic multiplayer server_level.dat,
- Indev .mclevel
- Schematic from RedstoneSim, MCEdit, mce
- .inv from INVEdit (appears as a chest)
"""
if len(command) == 0:
self.printUsage("import")
return
filename = command.pop(0)
destPoint = self.readPoint(command)
blocksToCopy = self.readBlocksToCopy(command)
importLevel = mclevel.fromFile(filename)
self.level.copyBlocksFrom(importLevel, importLevel.bounds, destPoint, blocksToCopy, create=True)
self.needsSave = True
print "Imported {0} blocks.".format(importLevel.bounds.volume)
示例3: testCreate
def testCreate(self):
# log.info("Schematic from indev")
size = (64, 64, 64)
temp = mktemp("testcreate.schematic")
schematic = MCSchematic(shape=size, filename=temp, mats='Classic')
level = self.indevLevel.level
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
assert((schematic.Blocks[0:64, 0:64, 0:64] == level.Blocks[0:64, 0:64, 0:64]).all())
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (-32, -32, -32))
assert((schematic.Blocks[0:32, 0:32, 0:32] == level.Blocks[32:64, 32:64, 32:64]).all())
schematic.saveInPlace()
schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
tempSchematic = MCSchematic(shape=(1, 1, 3))
tempSchematic.copyBlocksFrom(schem, BoundingBox((0, 0, 0), (1, 1, 3)), (0, 0, 0))
level = self.anvilLevel.level
for cx, cz in itertools.product(xrange(0, 4), xrange(0, 4)):
try:
level.createChunk(cx, cz)
except ValueError:
pass
schematic.copyBlocksFrom(level, BoundingBox((0, 0, 0), (64, 64, 64,)), (0, 0, 0))
schematic.close()
os.remove(temp)
示例4: _import
def _import(self, command):
"""
import <filename> <destPoint> [noair] [nowater]
Imports a level or schematic into this world, beginning at destPoint.
Supported formats include
- Classic single-player .mine,
- Classic multiplayer server_level.dat,
- Indev .mclevel
- Schematic from RedstoneSim, MCEdit, mce
- .inv from INVEdit (appears as a chest)
"""
if len(command) == 0:
self.printUsage("import")
return;
filename = command.pop(0)
destPoint = self.readPoint(command)
blocksToCopy = self.readBlocksToCopy(command)
importLevel = mclevel.fromFile(filename)
destBox = BoundingBox(destPoint, importLevel.size)
self.level.createChunksInBox(destBox);
self.level.copyBlocksFrom(importLevel, importLevel.getWorldBounds(), destPoint, blocksToCopy);
self.needsSave = True;
print "Imported {0} blocks.".format(importLevel.getWorldBounds().volume)
示例5: loadWorld
def loadWorld(self, world):
worldpath = os.path.expanduser(world)
if os.path.exists(worldpath):
self.level = mclevel.fromFile(worldpath)
else:
self.level = mclevel.loadWorld(world)
示例6: find_edges
def find_edges(worldDir, edgeFilename):
level = mclevel.fromFile(worldDir)
edgeFile = open(edgeFilename, "w")
sys.stdout.write("finding edges...")
chunks = []
for chunk in level.allChunks:
chunks.append(chunk)
erodeTasks = []
examined = 0
lastProgress = 0
numChunks = len(chunks)
for chunk in chunks:
checkChunk(level, chunk, erodeTasks)
examined += 1
progress = examined * 100 / numChunks
if progress != lastProgress:
lastProgress = progress
sys.stdout.write("\rfinding edges (%d%%)..." % (progress))
print("")
edgeFile.write("# erodeType erodeDirection posX posZ\n")
numEdgeChunks = 0
for task in erodeTasks:
edgeFile.write("%s\n" % (task))
numEdgeChunks += 1
edgeFile.close()
print("found %d edge(s)" % (numEdgeChunks))
示例7: loadWorld
def loadWorld(self, world):
try:
worldNum = int(world)
if str(worldNum) == world:
self.level = mclevel.loadWorldNumber(worldNum)
except ValueError:
self.level = mclevel.fromFile(world)
示例8: testImportSchematic
def testImportSchematic(self):
level = self.anvilLevel.level
cx, cz = level.allChunks.next()
schem = mclevel.fromFile("schematics/CreativeInABox.schematic")
box = BoundingBox((cx * 16, 64, cz * 16), schem.bounds.size)
level.copyBlocksFrom(schem, schem.bounds, (0, 64, 0))
schem = MCSchematic(shape=schem.bounds.size)
schem.copyBlocksFrom(level, box, (0, 0, 0))
convertedSourceBlocks, convertedSourceData = block_copy.convertBlocks(schem, level, schem.Blocks, schem.Data)
assert (level.getChunk(cx, cz).Blocks[0:1, 0:3, 64:65] == convertedSourceBlocks).all()
示例9: loadWorld
def loadWorld(self, world, dimension):
worldpath = os.path.expanduser(world)
if os.path.exists(worldpath):
level = mclevel.fromFile(worldpath)
else:
level = mclevel.loadWorld(world)
if dimension is not None:
if dimension in level.dimensions:
level = level.dimensions[dimension]
else:
raise InvalidDimensionError, "Dimension {0} does not exist".format(dimension)
return level
示例10: __init__
def __init__(self, filename, createFunc=None):
if not os.path.exists(filename):
filename = join("testfiles", filename)
tmpname = mktemp(os.path.basename(filename))
if os.path.exists(filename):
if os.path.isdir(filename):
shutil.copytree(filename, tmpname)
else:
shutil.copy(filename, tmpname)
else:
createFunc(tmpname)
self.tmpname = tmpname
self.level = mclevel.fromFile(tmpname)
示例11: manmade_relight
def manmade_relight():
t = templevel.TempLevel("TimeRelight", createFunc=lambda f:MCInfdevOldLevel(f, create=True))
world = t.level
station = mclevel.fromFile("testfiles/station.schematic")
times = 2
for x in range(times):
for z in range(times):
world.copyBlocksFrom(station, station.bounds, (x * station.Width, 63, z * station.Length), create=True)
t = timeit(lambda: world.generateLights(world.allChunks), number=1)
print "Relight manmade building: %d chunks in %.02f seconds (%.02fms per chunk)" % (world.chunkCount, t, t / world.chunkCount * 1000)
示例12: loadWorld
def loadWorld(self, world):
try:
worldNum = int(world)
except ValueError:
self.level = mclevel.fromFile(world)
self.filename = self.level.filename
else:
if str(worldNum) == world:
if worldNum > 0 and worldNum <= 5:
self.level = mclevel.loadWorldNumber(worldNum)
self.filename = self.level.filename
示例13: __init__
def __init__(self, filename, createFunc=None):
if not os.path.exists(filename):
filename = join("testfiles", filename)
tmpname = mktemp(os.path.basename(filename))
if os.path.exists(filename):
if os.path.isdir(filename):
shutil.copytree(filename, tmpname)
else:
shutil.copy(filename, tmpname)
elif createFunc:
createFunc(tmpname)
else:
raise IOError, "File %s not found." % filename
self.tmpname = tmpname
self.level = mclevel.fromFile(tmpname)
atexit.register(self.removeTemp)
示例14: loadWorld
def loadWorld(self, world):
try:
worldNum = int(world)
except ValueError:
self.level = mclevel.fromFile(world)
self.filename = self.level.filename
self.shortWorld = os.path.split(self.level.filename)[1];
if self.shortWorld == "level.dat":
self.shortWorld = os.path.split(os.path.split(self.level.filename)[0])[1];
else:
if str(worldNum) == world:
if worldNum > 0 and worldNum <= 5:
self.level = mclevel.loadWorldNumber(worldNum)
self.filename = self.level.filename
self.shortWorld = "World{0}".format(worldNum)
示例15: extractZipSchematicFromIter
def extractZipSchematicFromIter(sourceLevel, box, zipfilename=None, entities=True):
# converts classic blocks to alpha
# probably should only apply to alpha levels
if zipfilename is None:
zipfilename = tempfile.mktemp("zipschematic")
p = sourceLevel.adjustExtractionParameters(box)
if p is None:
return
sourceBox, destPoint = p
destPoint = (0, 0, 0)
tempfolder = tempfile.mktemp("schematic")
try:
tempSchematic = MCInfdevOldLevel(tempfolder, create=True)
tempSchematic.materials = sourceLevel.materials
for i in tempSchematic.copyBlocksFromIter(sourceLevel, sourceBox, destPoint, entities=entities, create=True):
yield i
tempSchematic.saveInPlace() # lights not needed for this format - crashes minecraft though
schematicDat = nbt.TAG_Compound()
schematicDat.name = "Mega Schematic"
schematicDat["Width"] = nbt.TAG_Int(sourceBox.size[0])
schematicDat["Height"] = nbt.TAG_Int(sourceBox.size[1])
schematicDat["Length"] = nbt.TAG_Int(sourceBox.size[2])
schematicDat["Materials"] = nbt.TAG_String(tempSchematic.materials.name)
schematicDat.save(os.path.join(tempfolder, "schematic.dat"))
zipdir(tempfolder, zipfilename)
import mclevel
yield mclevel.fromFile(zipfilename)
finally:
# We get here if the generator is GCed also
if os.path.exists(tempfolder):
shutil.rmtree(tempfolder, False)