Created
November 6, 2020 17:03
-
-
Save Grissess/af06b084278977f5d5a1017a4700fad4 to your computer and use it in GitHub Desktop.
MC Schematic to Bill of Materials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python 3, depends on twoolie's NBT:
pip3 install NBT