From 13c9750a43f2cb84e79a94e73a0d3ae3b64f6fa4 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sat, 11 Jun 2011 04:58:51 -0400 Subject: [PATCH] fixed crash when spawn point does not have an associated region file (closes issue #399) --- world.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/world.py b/world.py index f02098c..564d193 100644 --- a/world.py +++ b/world.py @@ -208,23 +208,25 @@ class World(object): ## The filename of this chunk chunkFile = self.get_region_path(chunkX, chunkY) - - data=nbt.load_from_region(chunkFile, chunkX, chunkY)[1] - level = data['Level'] - blockArray = numpy.frombuffer(level['Blocks'], dtype=numpy.uint8).reshape((16,16,128)) - - ## The block for spawn *within* the chunk - inChunkX = spawnX - (chunkX*16) - inChunkZ = spawnZ - (chunkY*16) - - ## find the first air block - while (blockArray[inChunkX, inChunkZ, spawnY] != 0): - spawnY += 1 - if spawnY == 128: - break + + if chunkFile is not None: + data = nbt.load_from_region(chunkFile, chunkX, chunkY)[1] + if data is not None: + level = data['Level'] + blockArray = numpy.frombuffer(level['Blocks'], dtype=numpy.uint8).reshape((16,16,128)) + + ## The block for spawn *within* the chunk + inChunkX = spawnX - (chunkX*16) + inChunkZ = spawnZ - (chunkY*16) + + ## find the first air block + while (blockArray[inChunkX, inChunkZ, spawnY] != 0): + spawnY += 1 + if spawnY == 128: + break self.POI.append( dict(x=spawnX, y=spawnY, z=spawnZ, - msg="Spawn", type="spawn", chunk=(inChunkX,inChunkZ))) + msg="Spawn", type="spawn", chunk=(chunkX, chunkY))) self.spawn = (spawnX, spawnY, spawnZ) def go(self, procs):