Skip to content

Instantly share code, notes, and snippets.

@Grissess
Created November 6, 2020 17:03
Show Gist options
  • Save Grissess/af06b084278977f5d5a1017a4700fad4 to your computer and use it in GitHub Desktop.
Save Grissess/af06b084278977f5d5a1017a4700fad4 to your computer and use it in GitHub Desktop.
MC Schematic to Bill of Materials
import nbt, sys
if len(sys.argv) > 1:
f = open(sys.argv[1], 'rb')
else:
f = sys.stdin
n = nbt.nbt.NBTFile(fileobj = f)
pal = {v.value: v.name.partition('[')[0] for v in n['Palette'].values()}
counts = {v: n['BlockData'].value.count(v) for v in pal.keys()}
bom = {}
for k, v in counts.items():
bom.setdefault(pal[k], 0)
bom[pal[k]] += v
for nm, ct in sorted(bom.items(), key = lambda p: p[1], reverse = True):
pnm = nm.partition(':')[2] if nm.startswith('minecraft:') else nm
print(f'- {pnm}: {ct}')
@Grissess
Copy link
Author

Grissess commented Nov 6, 2020

Python 3, depends on twoolie's NBT: pip3 install NBT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment