示例#1
0
    def test_name_for_anvil(self):
        """
        Equivalent tests for the Anvil version.
        """

        self.assertEqual(name_for_anvil(30, -3), "r.0.-1.mca")
        self.assertEqual(name_for_anvil(70, -30), "r.2.-1.mca")
示例#2
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (chunk, e))
示例#3
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))
示例#4
0
    def save_chunk(self, chunk):
        tag = self._save_chunk_to_tag(chunk)

        b = StringIO()
        tag.write_file(buffer=b)
        data = b.getvalue()

        name = name_for_anvil(chunk.x, chunk.z)
        fp = self.folder.child("region").child(name)

        # Allocate the region and put the chunk into it. Use ensure() instead
        # of create() so that we don't trash the region.
        region = Region(fp)

        try:
            region.ensure()
            region.put_chunk(chunk.x, chunk.z, data)
        except IOError, e:
            raise SerializerWriteException("Couldn't write to region: %r" % e)
示例#5
0
    def save_chunk(self, chunk):
        tag = self._save_chunk_to_tag(chunk)

        b = StringIO()
        tag.write_file(buffer=b)
        data = b.getvalue()

        name = name_for_anvil(chunk.x, chunk.z)
        fp = self.folder.child("region").child(name)

        # Allocate the region and put the chunk into it. Use ensure() instead
        # of create() so that we don't trash the region.
        region = Region(fp)

        try:
            region.ensure()
            region.put_chunk(chunk.x, chunk.z, data)
        except IOError, e:
            raise SerializerWriteException("Couldn't write to region: %r" % e)