예제 #1
0
파일: world.py 프로젝트: welterde/beta
    def load_chunk(self, x, z):
        """
        Retrieve a `Chunk`.

        This method does lots of automatic caching of chunks to ensure that
        disk I/O is kept to a minimum.
        """

        if (x, z) in self.chunk_cache:
            return self.chunk_cache[x, z]

        chunk = Chunk(x, z)
        self.chunk_cache[x, z] = chunk

        filename = os.path.join(self.folder, base36(x & 63), base36(z & 63),
            "c.%s.%s.dat" % (base36(x), base36(z)))
        tag = retrieve_nbt(filename)
        chunk.set_tag(tag)

        if not chunk.populated:
            self.populate_chunk(chunk)
            chunk.populated = True
            chunk.dirty = True

        # Apply the current season to the chunk.
        if self.season:
            self.season.transform(chunk)

        return chunk
예제 #2
0
파일: world.py 프로젝트: welterde/beta
    def __init__(self, folder):
        """
        Load a world from disk.

        :Parameters:
            folder : str
                The directory containing the world.
        """

        self.folder = folder
        self.chunk_cache = weakref.WeakValueDictionary()

        self.level = retrieve_nbt(os.path.join(self.folder, "level.dat"))

        if "Data" in self.level:
            self.load_level_data()
        else:
            self.generate_level()