Exemplo n.º 1
0
class Buildfile(object):
    def __init__(self, path, world_path):
        self.path = path
        log.info('loading minecraft world, path: %s' % world_path)
        self.level = mclevel.fromFile(world_path)
        log.info('world loaded, title: %s' % self.level.displayName)
        self.post_title = None
        self.force_sign = False # replace non-existing signs just by xml definition

        self.signs = SignList()
        self.blocks = []
        self.root = None

    def load_signs(self):
        for i, cPos in enumerate(self.level.allChunks):
            try:
                chunk = self.level.getChunk(*cPos)
            except mclevelbase.ChunkMalformed:
                continue

            for tile in chunk.TileEntities:
                if tile["id"].value == "Sign":
                    x = tile['x'].value
                    y = tile['y'].value
                    z = tile['z'].value

                    blockId = self.level.blockAt(x, y, z)
                    blockData = self.level.blockDataAt(x, y, z)

                    log.info('sign found @ x%d y%d z%d ID=%d Data=%d' %(x, y, z, blockId, blockData))
                    
                    sign = Sign.from_tile(tile, blockId, blockData)
                    if sign: # this returns None if the sign is not in the correct format
                        self.signs.add_sign(sign)

            if i % 100 == 0:
                log.info('reading tiles from chunk %d' % i)

    def load_xml(self):
        """Loads the xml buildfile."""
        try:
            self.root = XMLReader(self.path).root

            #for sign in self.root.findall('./signs/sign'):
            #    self.load_sign_xml(sign)

            for block in self.root.findall('./blocks/block'):
                self.load_block_xml(block)

            # load replacments etc...
        except Exception, e:
            log.exception('error loading buildfile')
Exemplo n.º 2
0
    def load_xml(self):
        """Loads the xml buildfile."""
        try:
            self.root = XMLReader(self.path).root

            #for sign in self.root.findall('./signs/sign'):
            #    self.load_sign_xml(sign)

            for block in self.root.findall('./blocks/block'):
                self.load_block_xml(block)

            # load replacments etc...
        except Exception, e:
            log.exception('error loading buildfile')