Пример #1
0
    def _save_inventory_to_tag(self, inventory):
        tag = TAG_List(type=TAG_Compound)

        for slot, item in enumerate(inventory.save_to_list()):
            if item is not None:
                d = TAG_Compound()
                id, damage, count = item
                d["id"] = TAG_Short(id)
                d["Damage"] = TAG_Short(damage)
                d["Count"] = TAG_Byte(count)
                d["Slot"] = TAG_Byte(slot)
                tag.tags.append(d)

        return tag
Пример #2
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
Пример #3
0
 def _save_painting_to_tag(self, painting, tag):
     tag["Dir"] = TAG_Byte(painting.direction)
     tag["Motive"] = TAG_String(painting.motive)
     # Both tile and position will be the center of the image.
     tag["TileX"] = TAG_Int(painting.location.pos.x)
     tag["TileY"] = TAG_Int(painting.location.pos.y)
     tag["TileZ"] = TAG_Int(painting.location.pos.z)
Пример #4
0
    def _save_inventory_to_tag(self, inventory):
        tag = TAG_List(type=TAG_Compound)

        for i, item in enumerate(
                chain(inventory.crafted, inventory.crafting, inventory.armor,
                      inventory.storage, inventory.holdables)):
            if item is not None:
                d = TAG_Compound()
                id, damage, count = item
                d["id"] = TAG_Short(id)
                d["Damage"] = TAG_Short(damage)
                d["Count"] = TAG_Byte(count)
                d["Slot"] = TAG_Byte(i)
                tag.tags.append(d)

        return tag
Пример #5
0
    def test_load_entity_from_tag_painting(self):
        tag = TAG_Compound()
        tag["Pos"] = TAG_List(type=TAG_Double)
        tag["Pos"].tags = [TAG_Double(10), TAG_Double(5), TAG_Double(-15)]
        tag["Rotation"] = TAG_List(type=TAG_Double)
        tag["Rotation"].tags = [TAG_Double(90), TAG_Double(0)]
        tag["OnGround"] = TAG_Byte(1)
        tag["id"] = TAG_String("Painting")

        tag["Dir"] = TAG_Byte(1)
        tag["Motive"] = TAG_String("Sea")
        tag["TileX"] = TAG_Int(32)
        tag["TileY"] = TAG_Int(32)
        tag["TileZ"] = TAG_Int(32)

        entity = self.s._load_entity_from_tag(tag)
        self.assertEqual(entity.motive, "Sea")
        self.assertEqual(entity.direction, 1)
Пример #6
0
    def test_load_entity_from_tag(self):
        tag = TAG_Compound()
        tag["Pos"] = TAG_List(type=TAG_Double)
        tag["Pos"].tags = [TAG_Double(10), TAG_Double(5), TAG_Double(-15)]
        tag["Rotation"] = TAG_List(type=TAG_Double)
        tag["Rotation"].tags = [TAG_Double(90), TAG_Double(0)]
        tag["OnGround"] = TAG_Byte(1)
        tag["id"] = TAG_String("Item")

        tag["Item"] = TAG_Compound()
        tag["Item"]["id"] = TAG_Short(3)
        tag["Item"]["Damage"] = TAG_Short(0)
        tag["Item"]["Count"] = TAG_Short(5)

        entity = self.serializer._load_entity_from_tag(tag)
        self.assertEqual(entity.location.x, 10)
        self.assertEqual(entity.location.yaw, 90)
        self.assertEqual(entity.location.grounded, True)
        self.assertEqual(entity.item[0], 3)
Пример #7
0
    def _save_entity_to_tag(self, entity):
        tag = NBTFile()
        tag.name = ""

        tag["id"] = TAG_String(entity.name)

        position = entity.location.pos
        tag["Pos"] = TAG_List(type=TAG_Double)
        tag["Pos"].tags = [TAG_Double(i) for i in position]

        rotation = entity.location.ori.to_degs()
        tag["Rotation"] = TAG_List(type=TAG_Double)
        tag["Rotation"].tags = [TAG_Double(i) for i in rotation]

        tag["OnGround"] = TAG_Byte(int(entity.location.grounded))

        self._entity_savers[entity.name](entity, tag)

        return tag
Пример #8
0
    def _save_chunk_to_tag(self, chunk):
        tag = NBTFile()
        tag.name = ""

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

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

        level["Blocks"].value = chunk.blocks.tostring()
        level["HeightMap"].value = chunk.heightmap.tostring()
        level["BlockLight"].value = pack_nibbles(chunk.blocklight)
        level["Data"].value = pack_nibbles(chunk.metadata)
        level["SkyLight"].value = pack_nibbles(chunk.skylight)

        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:
                print "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:
                print "Unknown tile entity %s" % tile.name

        return tag
Пример #9
0
 def _save_music_to_tag(self, music, tag):
     tag["Music"] = TAG_Byte(music.note)
Пример #10
0
 def _save_wolf_to_tag(self, wolf, tag):
     tag["Owner"] = TAG_String(wolf.owner)
     tag["Sitting"] = TAG_Byte(wolf.sitting)
     tag["Angry"] = TAG_Byte(wolf.angry)
Пример #11
0
 def _save_slime_to_tag(self, slime, tag):
     tag["Size"] = TAG_Byte(slime.size)
Пример #12
0
 def _save_sheep_to_tag(self, sheep, tag):
     tag["Sheared"] = TAG_Byte(sheep.sheared)
     tag["Color"] = TAG_Byte(sheep.color)
Пример #13
0
 def _save_pig_to_tag(self, pig, tag):
     tag["Saddle"] = TAG_Byte(pig.saddle)