Skip to content

Instantly share code, notes, and snippets.

@TheonlyTazz
Created April 27, 2023 19:13
Show Gist options
  • Save TheonlyTazz/c4bec488e5f3c83da1838d4fbe0d39a9 to your computer and use it in GitHub Desktop.
Save TheonlyTazz/c4bec488e5f3c83da1838d4fbe0d39a9 to your computer and use it in GitHub Desktop.
NBT BlockPalette Changer
import nbtlib
from nbtlib.tag import *
import os
import json
def main():
while True:
IF = input('Input folder: \n') + '\\'
string_in = input('String to find: \n')
string_out = input('String to replace to: \n')
# Get all files from InputFolder
listfiles = os.listdir(IF)
for filename in listfiles:
if '.nbt' in filename:
nbt_file = nbtlib.load(IF + filename, gzipped=True)
# Open first Compound NBT
file = nbt_file[""]
#te = file['tile_entities']
palette = file['palette']
printfilename = 1
# Change block textures
for x in palette:
name = ''
name = x.get('Name')
if string_in in name:
if printfilename == 1:
print(f"\nFilename> {filename}")
printfilename = 0
replace = name.replace(string_in, string_out)
x.update({'Name': String(replace)})
print(f" - Changed: {x.get('Name')}")
nbt_file.save(IF + filename)
q = input('\nNext folder? \n')
if q.lower() == 'n':
break
if __name__ == '__main__':
main()
@Raidobw2
Copy link

Tazz I'm getting an error on line 19, I just had to comment it out and change line 21 to use nbt_file instead of file (used the debugger to validate program behavior)
image
Example output after this change
image
Works like a charm ;)
Much thanks for the timesaver! ❤️

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