예제 #1
0
	def save_chunk(self, chunk_position):
		x, y, z = chunk_position
		
		# try to load the chunk file
		# if it doesn't exist, create a new one

		chunk_path = self.chunk_position_to_path(chunk_position)

		try:
			chunk_data = nbt.load(chunk_path)
		
		except FileNotFoundError:
			chunk_data = nbt.File({"": nbt.Compound({"Level": nbt.Compound()})})
			
			chunk_data["Level"]["xPos"] = x
			chunk_data["Level"]["zPos"] = z

		# fill the chunk file with the blocks from our chunk

		chunk_blocks = nbt.ByteArray([0] * (chunk.CHUNK_WIDTH * chunk.CHUNK_HEIGHT * chunk.CHUNK_LENGTH))

		for x in range(chunk.CHUNK_WIDTH):
			for y in range(chunk.CHUNK_HEIGHT):
				for z in range(chunk.CHUNK_LENGTH):
					chunk_blocks[
						x * chunk.CHUNK_LENGTH * chunk.CHUNK_HEIGHT +
						z * chunk.CHUNK_HEIGHT +
						y] = self.world.chunks[chunk_position].blocks[x][y][z]
		
		# save the chunk file

		chunk_data["Level"]["Blocks"] = chunk_blocks
		chunk_data.save(chunk_path, gzipped = True)
예제 #2
0
def dump_nbt(
    root: NbtCompound,
    path: Path,
    options: Dict[str, Any] = {},
):
    """Dump a NBT file synchronously."""
    nbtfile = nbtlib.File({"": root})
    nbtfile.save(str(path), **options)
 def save(self, file_path: str, empty_block: str = None):
     root = nbt.Compound()
     root["blocks"] = self.__get_blocks(empty_block)
     root["entities"] = self._entities
     root["palette"] = self.__get_palette()
     root["size"] = self._size
     root["DataVersion"] = self.data_version
     file = nbt.File({"": root})
     file.save(file_path, gzipped=True)
예제 #4
0
파일: convert.py 프로젝트: LXYan2333/MMPAG
print('您要转换的文件是:', argv[1])
img = Image.open(argv[1])
materiallist = set({})
for i in range(0, img.size[0]):
    for j in range(0, img.size[1]):
        materiallist.add(cid2bid(sci(img.load()[i, j])))
materiallist = tuple(materiallist)
new_file = nbtlib.File(
    {
        '':
        Compound({
            'DataVersion':
            Int(1631),
            'size':
            List[Int]([img.size[0], 1, img.size[1]]),
            'palette':
            List[Compound]([{
                'Name': String('minecraft:' + str(i))
            } for i in materiallist]),
            'blocks':
            List[Compound]([{
                'pos':
                List[Int]([j, 0, i]),
                'state':
                Int(materiallist.index(cid2bid(sci(img.load()[j, i]))))
            } for i in range(0, img.size[1]) for j in range(0, img.size[0])])
        })
    },
    gzipped=True)
new_file.save('picture.nbt')
예제 #5
0
 def final(self,filename):
     return nbtlib.File({"":self},gzipped=True).save(filename=filename)
예제 #6
0
for frame in ImageSequence.Iterator(im):
    frame = frame.resize((384, 237))
    for i_ in range(6):

        image = frame.crop((128 * (i_ % 3), 128 * (i_ // 3),
                            128 * (i_ % 3) + 128, 128 * (i_ // 3) + 128))
        image = image.convert("RGB")
        data = image.getdata()
        image.close()
        print(data[0])
        output = nbtlib.File({
            "":
            nbtlib.tag.Compound({
                "data":
                nbtlib.tag.Compound({
                    "zCenter": nbtlib.tag.Int(0),
                    "xCenter": nbtlib.tag.Int(0),
                    "scale": nbtlib.tag.Byte(3),
                    'dimension': nbtlib.tag.Int(7)
                })
            })
        })
        colors = []

        for i in data:
            st = nd = float("inf")
            sti = ndi = -1
            for j, k in colormap.items():
                new = ColourDistance(i, k)
                if new < st:
                    st, nd = new, st
                    sti, ndi = j, sti