Skip to content

Instantly share code, notes, and snippets.

@tofran
Created December 26, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tofran/87a5d712e5646fccacc25304e4d38d2c to your computer and use it in GitHub Desktop.
Save tofran/87a5d712e5646fccacc25304e4d38d2c to your computer and use it in GitHub Desktop.
Copy minecraft NBT properties from one file into another
#!/usr/bin/env python3
# Copy minecraft NBT properties from one file into another
# Usage:
# ./nbt-copy.py <source_file> <destination_file> <property> [properties]
#
# Requires nbt:
# pip install nbt
import argparse
from nbt import nbt
def copy_attributes(nbt_src, nbt_dest, keys_to_copy):
for key in keys_to_copy:
if key not in nbt_src:
raise ValueError(f"{key} not in source file")
nbt_dest[key] = nbt_src[key]
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("source_file")
parser.add_argument("destination_file")
parser.add_argument("properties", nargs="+")
args = parser.parse_args()
nbt_src = nbt.NBTFile(args.source_file, "rb")
nbt_dest = nbt.NBTFile(args.destination_file, "rb")
copy_attributes(
nbt_src,
nbt_dest,
list(args.properties),
)
nbt_dest.write_file(args.destination_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment