示例#1
0
    def save_to_packet(self):
        """
        Generate a chunk packet.
        """

        mask = 0
        packed = []

        ls = segment_array(self.blocklight)

        for i, section in enumerate(self.sections):
            if any(section.blocks):
                mask |= 1 << i
                packed.append(section.blocks.tostring())

        for i, section in enumerate(self.sections):
            if mask & 1 << i:
                packed.append(pack_nibbles(section.metadata))

        for i, l in enumerate(ls):
            if mask & 1 << i:
                packed.append(pack_nibbles(l))

        for i, section in enumerate(self.sections):
            if mask & 1 << i:
                packed.append(pack_nibbles(section.skylight))

        # Fake the biome data.
        packed.append("\x00" * 256)

        packet = make_packet("chunk", x=self.x, z=self.z, continuous=True,
                primary=mask, add=0x0, data="".join(packed))
        return packet
示例#2
0
    def test_unpack_nibbles_overflow(self):
        """
        No spurious OverflowErrors should occur when packing nibbles.

        This test doesn't even assert anything; it will raise instead if
        there's a regression.
        """

        pack_nibbles(array([0xff, 0xff]))
示例#3
0
    def test_unpack_nibbles_overflow(self):
        """
        No spurious OverflowErrors should occur when packing nibbles.

        This test doesn't even assert anything; it will raise instead if
        there's a regression.
        """

        pack_nibbles([0xff, 0xff])
示例#4
0
    def save_to_packet(self):
        """
        Generate a chunk packet.
        """

        array = self.blocks.tostring()
        array += pack_nibbles(self.metadata)
        array += pack_nibbles(self.blocklight)
        array += pack_nibbles(self.skylight)
        packet = make_packet("chunk", x=self.x * 16, y=0, z=self.z * 16,
            x_size=15, y_size=127, z_size=15, data=array)
        return packet
示例#5
0
    def save_to_packet(self):
        """
        Generate a chunk packet.
        """

        array = self.blocks.tostring()
        array += pack_nibbles(self.metadata)
        array += pack_nibbles(self.blocklight)
        array += pack_nibbles(self.skylight)
        packet = make_packet("chunk", x=self.x * 16, y=0, z=self.z * 16,
            x_size=15, y_size=127, z_size=15, data=array)
        return packet
示例#6
0
    def _save_chunk_to_tag(self, chunk):
        tag = NBTFile()
        tag.name = ""

        level = TAG_Compound()
        tag["Level"] = level

        level["xPos"] = TAG_Int(chunk.x)
        level["zPos"] = TAG_Int(chunk.z)

        level["HeightMap"] = TAG_Byte_Array()
        level["BlockLight"] = TAG_Byte_Array()
        level["SkyLight"] = TAG_Byte_Array()

        level["Sections"] = TAG_List(type=TAG_Compound)
        for i, s in enumerate(chunk.sections):
            if s:
                section = TAG_Compound()
                section.name = ""
                section["Y"] = TAG_Byte(i)
                section["Blocks"] = TAG_Byte_Array()
                section["Blocks"].value = s.blocks.tostring()
                section["Data"] = TAG_Byte_Array()
                section["Data"].value = pack_nibbles(s.metadata)
                section["SkyLight"] = TAG_Byte_Array()
                section["SkyLight"].value = pack_nibbles(s.skylight)
                level["Sections"].tags.append(section)

        level["HeightMap"].value = chunk.heightmap.tostring()
        level["BlockLight"].value = pack_nibbles(chunk.blocklight)

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

        level["Entities"] = TAG_List(type=TAG_Compound)
        for entity in chunk.entities:
            try:
                entitytag = self._save_entity_to_tag(entity)
                level["Entities"].tags.append(entitytag)
            except KeyError:
                log.msg("Unknown entity %s" % entity.name)

        level["TileEntities"] = TAG_List(type=TAG_Compound)
        for tile in chunk.tiles.itervalues():
            try:
                tiletag = self._save_tile_to_tag(tile)
                level["TileEntities"].tags.append(tiletag)
            except KeyError:
                log.msg("Unknown tile entity %s" % tile.name)

        return tag
示例#7
0
    def _save_chunk_to_tag(self, chunk):
        tag = NBTFile()
        tag.name = ""

        level = TAG_Compound()
        tag["Level"] = level

        level["xPos"] = TAG_Int(chunk.x)
        level["zPos"] = TAG_Int(chunk.z)

        level["HeightMap"] = TAG_Byte_Array()
        level["BlockLight"] = TAG_Byte_Array()
        level["SkyLight"] = TAG_Byte_Array()

        level["Sections"] = TAG_List(type=TAG_Compound)
        for i, s in enumerate(chunk.sections):
            if s:
                section = TAG_Compound()
                section.name = ""
                section["Y"] = TAG_Byte(i)
                section["Blocks"] = TAG_Byte_Array()
                section["Blocks"].value = s.blocks.tostring()
                section["Data"] = TAG_Byte_Array()
                section["Data"].value = pack_nibbles(s.metadata)
                section["SkyLight"] = TAG_Byte_Array()
                section["SkyLight"].value = pack_nibbles(s.skylight)
                level["Sections"].tags.append(section)

        level["HeightMap"].value = chunk.heightmap.tostring()
        level["BlockLight"].value = pack_nibbles(chunk.blocklight)

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

        level["Entities"] = TAG_List(type=TAG_Compound)
        for entity in chunk.entities:
            try:
                entitytag = self._save_entity_to_tag(entity)
                level["Entities"].tags.append(entitytag)
            except KeyError:
                log.msg("Unknown entity %s" % entity.name)

        level["TileEntities"] = TAG_List(type=TAG_Compound)
        for tile in chunk.tiles.itervalues():
            try:
                tiletag = self._save_tile_to_tag(tile)
                level["TileEntities"].tags.append(tiletag)
            except KeyError:
                log.msg("Unknown tile entity %s" % tile.name)

        return tag
示例#8
0
    def test_unpack_nibbles_overflow(self):
        """
        No spurious OverflowErrors should occur when packing nibbles.

        This test will raise if there's a regression.
        """

        self.assertEqual(pack_nibbles(array("B", [0xff, 0xff])), "\xff")
示例#9
0
    def test_unpack_nibbles_overflow(self):
        """
        No spurious OverflowErrors should occur when packing nibbles.

        This test will raise if there's a regression.
        """

        self.assertEqual(pack_nibbles(array("B", [0xff, 0xff])), "\xff")
示例#10
0
文件: chunk.py 项目: Zebetus/bravo
    def save_to_packet(self):
        """
        Generate a chunk packet.
        """

        mask = 0
        packed = []

        ls = segment_array(self.blocklight)

        for i, section in enumerate(self.sections):
            if any(section.blocks):
                mask |= 1 << i
                packed.append(section.blocks.tostring())

        for i, section in enumerate(self.sections):
            if mask & 1 << i:
                packed.append(pack_nibbles(section.metadata))

        for i, l in enumerate(ls):
            if mask & 1 << i:
                packed.append(pack_nibbles(l))

        for i, section in enumerate(self.sections):
            if mask & 1 << i:
                packed.append(pack_nibbles(section.skylight))

        # Fake the biome data.
        packed.append("\x00" * 256)

        packet = make_packet("chunk",
                             x=self.x,
                             z=self.z,
                             continuous=True,
                             primary=mask,
                             add=0x0,
                             data="".join(packed))
        return packet
示例#11
0
 def test_pack_nibbles(self):
     self.assertEqual(pack_nibbles(array([1, 6])), "a")
     self.assertEqual(
         pack_nibbles(array([14, 6, 9, 6, 2, 6, 3, 7])),
         "nibs")
示例#12
0
 def test_nibble_reflexivity(self):
     self.assertEqual("nibbles", pack_nibbles(unpack_nibbles("nibbles")))
示例#13
0
 def test_pack_nibbles_multiple(self):
     self.assertEqual(
         pack_nibbles(array("B", [14, 6, 9, 6, 2, 6, 3, 7])),
         "nibs")
示例#14
0
 def test_pack_nibbles_single(self):
     self.assertEqual(pack_nibbles(array("B", [1, 6])), "a")
示例#15
0
 def test_pack_nibbles_single(self):
     self.assertEqual(pack_nibbles(array("B", [1, 6])), "a")
示例#16
0
 def test_pack_nibbles(self):
     self.assertEqual(pack_nibbles(array([1, 6])), "a")
     self.assertEqual(
         pack_nibbles(array([14, 6, 9, 6, 2, 6, 3, 7])),
         "nibs")
示例#17
0
 def test_pack_nibbles_multiple(self):
     self.assertEqual(pack_nibbles(array("B", [14, 6, 9, 6, 2, 6, 3, 7])),
                      "nibs")
示例#18
0
 def test_nibble_reflexivity(self):
     self.assertEqual("nibbles", pack_nibbles(unpack_nibbles("nibbles")))