Exemple #1
0
    def findTrueSpawn(self):
        """Adds the true spawn location to self.POI.  The spawn Y coordinate
        is almost always the default of 64.  Find the first air block above
        that point for the true spawn location"""

        ## read spawn info from level.dat
        data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]
        spawnX = data['Data']['SpawnX']
        spawnY = data['Data']['SpawnY']
        spawnZ = data['Data']['SpawnZ']
   
        ## The chunk that holds the spawn location 
        chunkX = spawnX/16
        chunkY = spawnZ/16

        ## 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

        self.POI.append( dict(x=spawnX, y=spawnY, z=spawnZ, 
                msg="Spawn", type="spawn", chunk=(inChunkX,inChunkZ)))
Exemple #2
0
def get_lvldata(filename, x, y):
    """Takes a filename and chunkcoords and returns the Level struct, which contains all the
    level info"""

    d =  nbt.load_from_region(filename, x, y)
    if not d: raise NoSuchChunk(x,y)
    return d[1]['Level']
Exemple #3
0
def get_lvldata(filename, x, y):
    """Takes a filename and chunkcoords and returns the Level struct, which contains all the
    level info"""
    
    try:
        d =  nbt.load_from_region(filename, x, y)
    except Exception, e:
        logging.warning("Error opening chunk (%i, %i) in %s. It may be corrupt. %s", x, y, filename, e)
        raise ChunkCorrupt(str(e))
Exemple #4
0
    def find_true_spawn(self):
        """Adds the true spawn location to self.POI.  The spawn Y coordinate
        is almost always the default of 64.  Find the first air block above
        that point for the true spawn location"""

        ## read spawn info from level.dat
        data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]
        disp_spawnX = spawnX = data['Data']['SpawnX']
        spawnY = data['Data']['SpawnY']
        disp_spawnZ = spawnZ = data['Data']['SpawnZ']
        if self.north_direction == 'upper-left':
            temp = spawnX
            spawnX = -spawnZ
            spawnZ = temp
        elif self.north_direction == 'upper-right':
            spawnX = -spawnX
            spawnZ = -spawnZ
        elif self.north_direction == 'lower-right':
            temp = spawnX
            spawnX = spawnZ
            spawnZ = -temp
   
        ## The chunk that holds the spawn location 
        chunkX = spawnX/16
        chunkY = spawnZ/16
        
        ## clamp spawnY to a sane value, in-chunk value
        if spawnY < 0:
            spawnY = 0
        if spawnY > 127:
            spawnY = 127
        
        try:
            ## The filename of this chunk
            chunkFile = self.get_region_path(chunkX, chunkY)
            if chunkFile is not None:
                data = nbt.load_from_region(chunkFile, chunkX, chunkY, self.north_direction)
                if data is not None:
                    level = data[1]['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
        except chunk.ChunkCorrupt:
            #ignore corrupt spawn, and continue
            pass
        self.POI.append( dict(x=disp_spawnX, y=spawnY, z=disp_spawnZ,
                msg="Spawn", type="spawn", chunk=(chunkX, chunkY)))
        self.spawn = (disp_spawnX, spawnY, disp_spawnZ)
def get_lvldata(filename, x, y):
    """Takes a filename and chunkcoords and returns the Level struct, which contains all the
    level info"""

    try:
        d = nbt.load_from_region(filename, x, y)
    except Exception, e:
        logging.warning(
            "Error opening chunk (%i, %i) in %s. It may be corrupt. %s", x, y,
            filename, e)
        raise ChunkCorrupt(str(e))
    def findTrueSpawn(self):
        """Adds the true spawn location to self.POI.  The spawn Y coordinate
        is almost always the default of 64.  Find the first air block above
        that point for the true spawn location"""

        ## read spawn info from level.dat
        data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]
        disp_spawnX = spawnX = data["Data"]["SpawnX"]
        spawnY = data["Data"]["SpawnY"]
        disp_spawnZ = spawnZ = data["Data"]["SpawnZ"]
        if self.north_direction == "upper-left":
            temp = spawnX
            spawnX = -spawnZ
            spawnZ = temp
        elif self.north_direction == "upper-right":
            spawnX = -spawnX
            spawnZ = -spawnZ
        elif self.north_direction == "lower-right":
            temp = spawnX
            spawnX = spawnZ
            spawnZ = -temp

        ## The chunk that holds the spawn location
        chunkX = spawnX / 16
        chunkY = spawnZ / 16

        try:
            ## The filename of this chunk
            chunkFile = self.get_region_path(chunkX, chunkY)
            if chunkFile is not None:
                data = nbt.load_from_region(chunkFile, chunkX, chunkY, self.north_direction)[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
        except ChunkCorrupt:
            # ignore corrupt spawn, and continue
            pass
        self.POI.append(dict(x=disp_spawnX, y=spawnY, z=disp_spawnZ, msg="Spawn", type="spawn", chunk=(chunkX, chunkY)))
        self.spawn = (disp_spawnX, spawnY, disp_spawnZ)
Exemple #7
0
def get_blockarray_fromfile(filename, north_direction='lower-left'):
    """Same as get_blockarray except takes a filename. This is a shortcut"""
    d = nbt.load_from_region(filename, x, y, north_direction)
    level = d[1]['Level']
    chunk_data = level
    rots = 0
    if self.north_direction == 'upper-left':
        rots = 1
    elif self.north_direction == 'upper-right':
        rots = 2
    elif self.north_direction == 'lower-right':
        rots = 3

    chunk_data['Blocks'] = numpy.rot90(
        numpy.frombuffer(level['Blocks'], dtype=numpy.uint8).reshape(
            (16, 16, 128)), rots)
    return get_blockarray(chunk_data)
Exemple #8
0
def get_blockarray_fromfile(filename, north_direction='lower-left'):
    """Same as get_blockarray except takes a filename. This is a shortcut"""
    d = nbt.load_from_region(filename, x, y, north_direction)
    level = d[1]['Level']
    chunk_data = level
    rots = 0
    if self.north_direction == 'upper-left':
        rots = 1
    elif self.north_direction == 'upper-right':
        rots = 2
    elif self.north_direction == 'lower-right':
        rots = 3

    chunk_data['Blocks'] = numpy.rot90(numpy.frombuffer(
            level['Blocks'], dtype=numpy.uint8).reshape((16,16,128)),
            rots)
    return get_blockarray(chunk_data)
    def findTrueSpawn(self):
        """Adds the true spawn location to self.POI.  The spawn Y coordinate
        is almost always the default of 64.  Find the first air block above
        that point for the true spawn location"""

        ## read spawn info from level.dat
        data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]
        spawnX = data['Data']['SpawnX']
        spawnY = data['Data']['SpawnY']
        spawnZ = data['Data']['SpawnZ']

        ## The chunk that holds the spawn location
        chunkX = spawnX / 16
        chunkY = spawnZ / 16

        ## 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

        self.POI.append(
            dict(x=spawnX,
                 y=spawnY,
                 z=spawnZ,
                 msg="Spawn",
                 type="spawn",
                 chunk=(inChunkX, inChunkZ)))
Exemple #10
0
def get_blockarray_fromfile(filename):
    """Same as get_blockarray except takes a filename. This is a shortcut"""
    d =  nbt.load_from_region(filename, x, y)
    level = d[1]['Level']
    return get_blockarray(level)
Exemple #11
0
    def find_true_spawn(self):
        """Adds the true spawn location to self.POI.  The spawn Y coordinate
        is almost always the default of 64.  Find the first air block above
        that point for the true spawn location"""

        ## read spawn info from level.dat
        data = nbt.load(os.path.join(self.worlddir, "level.dat"))[1]
        disp_spawnX = spawnX = data['Data']['SpawnX']
        spawnY = data['Data']['SpawnY']
        disp_spawnZ = spawnZ = data['Data']['SpawnZ']
        if self.north_direction == 'upper-left':
            temp = spawnX
            spawnX = -spawnZ
            spawnZ = temp
        elif self.north_direction == 'upper-right':
            spawnX = -spawnX
            spawnZ = -spawnZ
        elif self.north_direction == 'lower-right':
            temp = spawnX
            spawnX = spawnZ
            spawnZ = -temp

        ## The chunk that holds the spawn location
        chunkX = spawnX / 16
        chunkY = spawnZ / 16

        ## clamp spawnY to a sane value, in-chunk value
        if spawnY < 0:
            spawnY = 0
        if spawnY > 127:
            spawnY = 127

        try:
            ## The filename of this chunk
            chunkFile = self.get_region_path(chunkX, chunkY)
            if chunkFile is not None:
                data = nbt.load_from_region(chunkFile, chunkX, chunkY,
                                            self.north_direction)
                if data is not None:
                    level = data[1]['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
        except chunk.ChunkCorrupt:
            #ignore corrupt spawn, and continue
            pass
        self.POI.append(
            dict(x=disp_spawnX,
                 y=spawnY,
                 z=disp_spawnZ,
                 msg="Spawn",
                 type="spawn",
                 chunk=(chunkX, chunkY)))
        self.spawn = (disp_spawnX, spawnY, disp_spawnZ)