Created
April 27, 2023 19:13
-
-
Save TheonlyTazz/c4bec488e5f3c83da1838d4fbe0d39a9 to your computer and use it in GitHub Desktop.
NBT BlockPalette Changer
This file contains 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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 offile
(used the debugger to validate program behavior)Example output after this change
Works like a charm ;)
Much thanks for the timesaver! ❤️