def save_to_tag(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["TileEntities"] = TAG_List(type=TAG_Compound) for tile in chunk.tiles.itervalues(): level["TileEntities"].tags.append(tile.save_to_tag()) return tag
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
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