Created
August 26, 2022 11:15
-
-
Save rotolonico/70b6a04b950e1454e72d714f2f5f61ad to your computer and use it in GitHub Desktop.
Generates Minecraft resource packs using the bash 'convert' tool!
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 os | |
| import shutil | |
| import random | |
| rp = "[PATH_OF_RP_TO_MODIFY]" | |
| vanilla = "[PATH_OF_VANILLA_RP_TO_RESET]" | |
| # Set this to true to reset the resource pack back to the vanilla one every tiem you hit play | |
| reset_rp = True | |
| if reset_rp: | |
| try: | |
| shutil.rmtree(rp) | |
| print("Removed rp folder!") | |
| except OSError as error: | |
| print(error) | |
| print("Rp folder already removed!") | |
| shutil.copytree(vanilla, rp) | |
| print("Copied back vanilla rp") | |
| # Logs every image it is working on | |
| verbose = ' -verbose' | |
| # Makes the rp half the size (16x16 -> 8x8) | |
| resize_50 = ' -resize 50%' | |
| # Makes the rp 16x the size (16x16 -> 256x256) | |
| resize_1600 = ' -resize 1600%' | |
| # Adds a border of 2 pixels to make a 3d effect | |
| transform_raise = ' -raise 2' | |
| # Colorizes every texture pink | |
| colorize_pink = ' -colorize 100x50x50' | |
| # Rotates every texture x degrees | |
| rotate_45 = " -rotate 45" | |
| rotate_90 = " -rotate 90" | |
| rotate_180 = " -rotate 180" | |
| # Negates everything | |
| invert = " -channel RGB -negate" | |
| # Shift every texture color of 50 | |
| modulate_50 = ' -modulate 100,100,50' | |
| # If set to false, it will apply template_all in bulk to all textures in the path If set to true, it will use the for | |
| # else, it loops to iterate on every file and apply template_singular (use this for do random actions for every block) | |
| use_singular = False | |
| if use_singular: | |
| for root, dirs, files in os.walk(rp): | |
| for file in files: | |
| if file.endswith('.png'): | |
| f = os.path.join(root, file) | |
| # Colorizes any texture randomly | |
| colorize_random = ' -colorize ' + str(random.randint(0, 256)) + "x" + str( | |
| random.randint(0, 256)) + "x" + str(random.randint(0, 256)) | |
| modulate_random = ' -modulate 100,100,' + str(random.randint(0, 201)) | |
| # Rotates any texture randomly | |
| rotate_random = ' -rotate ' + str(random.randint(0, 361)) | |
| # You can add things to do here (right now it's invert, but you can replace it with anything) | |
| template_singular = 'convert' + invert + ' ' + f.replace(" ", "\ ") + ' ' + f.replace( | |
| " ", | |
| "\ ") | |
| os.system(template_singular) | |
| else: | |
| # You can add things to do here (right now it's rotate_180, but you can replace it with anything) | |
| template_all = 'find ' + rp.replace(" ", | |
| "\ ") + ' -maxdepth 5 -iname "*.png" | xargs -L1 -I{} convert' + rotate_180 + ' {} {}' | |
| os.system(template_all) | |
| print("DONE!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment