Example #1
0
    def _load_chunk_from_tag(self, chunk, tag):
        """
        Load a chunk from a tag.

        We cannot instantiate chunks, ever, so pass it in from above.
        """

        level = tag["Level"]

        # These fromstring() calls are designed to raise if there are any
        # issues, but still be speedy.

        # Loop through the sections and unpack anything that we find.
        for tag in level["Sections"].tags:
            index = tag["Y"].value
            section = Section()
            section.blocks = array("B")
            section.blocks.fromstring(tag["Blocks"].value)
            section.metadata = array("B", unpack_nibbles(tag["Data"].value))
            section.skylight = array("B",
                                     unpack_nibbles(tag["SkyLight"].value))
            chunk.sections[index] = section

        chunk.heightmap = array("B")
        chunk.heightmap.fromstring(level["HeightMap"].value)
        chunk.blocklight = array("B",
                                 unpack_nibbles(level["BlockLight"].value))

        chunk.populated = bool(level["TerrainPopulated"])

        if "Entities" in level:
            for tag in level["Entities"].tags:
                try:
                    entity = self._load_entity_from_tag(tag)
                    chunk.entities.add(entity)
                except KeyError:
                    log.msg("Unknown entity %s" % tag["id"].value)
                    log.msg("Tag for entity:")
                    log.msg(tag.pretty_tree())

        if "TileEntities" in level:
            for tag in level["TileEntities"].tags:
                try:
                    tile = self._load_tile_from_tag(tag)
                    chunk.tiles[tile.x, tile.y, tile.z] = tile
                except KeyError:
                    log.msg("Unknown tile entity %s" % tag["id"].value)
                    log.msg("Tag for tile:")
                    log.msg(tag.pretty_tree())

        chunk.dirty = not chunk.populated
Example #2
0
    def _load_chunk_from_tag(self, chunk, tag):
        """
        Load a chunk from a tag.

        We cannot instantiate chunks, ever, so pass it in from above.
        """

        level = tag["Level"]

        # These fromstring() calls are designed to raise if there are any
        # issues, but still be speedy.

        # Loop through the sections and unpack anything that we find.
        for tag in level["Sections"].tags:
            index = tag["Y"].value
            section = Section()
            section.blocks = array("B")
            section.blocks.fromstring(tag["Blocks"].value)
            section.metadata = array("B", unpack_nibbles(tag["Data"].value))
            section.skylight = array("B",
                                     unpack_nibbles(tag["SkyLight"].value))
            chunk.sections[index] = section

        chunk.heightmap = array("B")
        chunk.heightmap.fromstring(level["HeightMap"].value)
        chunk.blocklight = array("B",
            unpack_nibbles(level["BlockLight"].value))

        chunk.populated = bool(level["TerrainPopulated"])

        if "Entities" in level:
            for tag in level["Entities"].tags:
                try:
                    entity = self._load_entity_from_tag(tag)
                    chunk.entities.add(entity)
                except KeyError:
                    log.msg("Unknown entity %s" % tag["id"].value)
                    log.msg("Tag for entity:")
                    log.msg(tag.pretty_tree())

        if "TileEntities" in level:
            for tag in level["TileEntities"].tags:
                try:
                    tile = self._load_tile_from_tag(tag)
                    chunk.tiles[tile.x, tile.y, tile.z] = tile
                except KeyError:
                    log.msg("Unknown tile entity %s" % tag["id"].value)
                    log.msg("Tag for tile:")
                    log.msg(tag.pretty_tree())

        chunk.dirty = not chunk.populated