-
-
Save Ljiong201108/e5a2fe8f8ac63f3cc70bf5557a948377 to your computer and use it in GitHub Desktop.
| import shutil | |
| import argparse | |
| import zipfile | |
| import os | |
| from pathlib import Path | |
| def move_files(root_dir, suffix, target_subfolder): | |
| root = Path(root_dir) | |
| count = 0 | |
| for file_path in root.rglob(f'*{suffix}'): | |
| try: | |
| parts = file_path.parts | |
| if 'assets' not in parts or 'textures' not in parts: | |
| continue | |
| texture_dir = None | |
| for parent in file_path.parents: | |
| if parent.name == 'textures': | |
| texture_dir = parent | |
| break | |
| if texture_dir is None: | |
| continue | |
| if target_subfolder in file_path.relative_to(texture_dir).parts: | |
| continue | |
| rel_path = file_path.relative_to(texture_dir) | |
| dest_path = texture_dir / target_subfolder / rel_path | |
| dest_path.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.move(str(file_path), str(dest_path)) | |
| count += 1 | |
| except Exception as e: | |
| print(f" [Error] Processing {file_path.name}: {e}") | |
| return count | |
| def zip_folder(folder_path, output_path): | |
| folder_path = Path(folder_path) | |
| with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf: | |
| for file in folder_path.rglob('*'): | |
| if file.is_file(): | |
| zipf.write(file, arcname=file.relative_to(folder_path)) | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Unzip, organize textures, re-zip, and clean up.") | |
| parser.add_argument("zip_file", help="The path to the source .zip file") | |
| args = parser.parse_args() | |
| zip_path = Path(args.zip_file).resolve() | |
| if not zip_path.exists() or zip_path.suffix.lower() != '.zip': | |
| print(f"Error: File '{zip_path}' not found or is not a .zip file.") | |
| return | |
| temp_extract_dir = zip_path.parent / (zip_path.stem + "_temp_processing") | |
| output_zip_path = zip_path.parent / (zip_path.stem + "_processed.zip") | |
| try: | |
| print(f"1. Extracting '{zip_path.name}' to temporary folder...") | |
| if temp_extract_dir.exists(): | |
| shutil.rmtree(temp_extract_dir) | |
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | |
| zip_ref.extractall(temp_extract_dir) | |
| print(f"2. Organizing textures inside temp folder...") | |
| s_count = move_files(temp_extract_dir, "_s.png", "specular") | |
| n_count = move_files(temp_extract_dir, "_n.png", "normal") | |
| print(f" - Moved {s_count} specular maps.") | |
| print(f" - Moved {n_count} normal maps.") | |
| print(f"3. Re-packing into '{output_zip_path.name}'...") | |
| zip_folder(temp_extract_dir, output_zip_path) | |
| except Exception as e: | |
| print(f"\n[CRITICAL ERROR]: {e}") | |
| print("Cleanup may not have finished due to error.") | |
| return | |
| finally: | |
| if temp_extract_dir.exists(): | |
| print(f"4. Cleaning up temporary files...") | |
| shutil.rmtree(temp_extract_dir) | |
| print("-" * 30) | |
| print("Success! Process completed.") | |
| print(f"New file location: {output_zip_path}") | |
| if __name__ == "__main__": | |
| main() |
- Make sure you have python installed in your computer
- Create an empty folder and an empty .py file, maybe call it
resource_pack_processer.py - Copy all the code above into the .py file you created
- For simplicity, copy your resource pack zip file into the folder you created
- Launch powershell, navigate to the current directory
- Run
python resource_pack_processer.py <your resource pack zip file name>.zip(if the name of the resource pack contains spaces, warp the name with", e.g."abc def.zip") - The new zip file with name ended with
processedis the file you need
- Make sure you have python installed in your computer
- Create an empty folder and an empty .py file, maybe call it
resource_pack_processer.py- Copy all the code above into the .py file you created
- For simplicity, copy your resource pack zip file into the folder you created
- Launch powershell, navigate to the current directory
- Run
python resource_pack_processer.py <your resource pack zip file name>.zip(if the name of the resource pack contains spaces, warp the name with", e.g."abc def.zip")- The new zip file with name ended with
processedis the file you need
thx <3
- Make sure you have python installed in your computer
- Create an empty folder and an empty .py file, maybe call it
resource_pack_processer.py- Copy all the code above into the .py file you created
- For simplicity, copy your resource pack zip file into the folder you created
- Launch powershell, navigate to the current directory
- Run
python resource_pack_processer.py <your resource pack zip file name>.zip(if the name of the resource pack contains spaces, warp the name with", e.g."abc def.zip")- The new zip file with name ended with
processedis the file you need
thank u for making life easier
hey yall i need some help, every time i do it, it spits out
File "C:\Users\User\Desktop\Rp_processor\resource_pack_processer.py", line 56
... print(f"Error: File '{zip_path}' not found or is not a .zip file.")
IndentationError: expected an indented block after 'if' statement on line 55
am i missing something? my command is python resource_pack_processer.py Vanilla-labPBR-1-3-2.zip no matter what resource pack i use it doesnt seem to work, tried administrator and recopying the script maybe a dozen times now lol, it just keeps spitting out not found. thanks in advance!
quick edit: ive also tried the full file path to .zip with and without double quotation
hey yall i need some help, every time i do it, it spits out
File "C:\Users\User\Desktop\Rp_processor\resource_pack_processer.py", line 56 ... print(f"Error: File '{zip_path}' not found or is not a .zip file.") IndentationError: expected an indented block after 'if' statement on line 55am i missing something? my command is
python resource_pack_processer.py Vanilla-labPBR-1-3-2.zipno matter what resource pack i use it doesnt seem to work, tried administrator and recopying the script maybe a dozen times now lol, it just keeps spitting out not found. thanks in advance! quick edit: ive also tried the full file path to .zip with and without double quotation
don't copy code
download script directy
right click on raw then Save link as
it will download script and wont give error
could you please post an example of how the command should look in PowerShell?
don't copy code
download script directy
right click on raw then Save link as
it will download script and wont give error
Thank you! this worked.
don't copy code
download script directy
right click on raw then Save link as
it will download script and wont give errorThank you! this worked.
what did you type in powershell? i've been trying for an hour straight
don't copy code
download script directy
right click on raw then Save link as
it will download script and wont give errorThank you! this worked.
what did you type in powershell? i've been trying for an hour straight
Make sure you have installed python
And PS is in same folder where process_pbr_pack.py and .zip is
For Vanilla-labPBR-1-3-2.zip
Cmd should look like this
python process_pbr_pack.py "Vanilla-labPBR-1-3-2.zip"
don't copy code
download script directy
right click on raw then Save link as
it will download script and wont give errorThank you! this worked.
what did you type in powershell? i've been trying for an hour straight
Make sure you have installed python And PS is in same folder where process_pbr_pack.py and .zip is For Vanilla-labPBR-1-3-2.zip Cmd should look like this
python process_pbr_pack.py "Vanilla-labPBR-1-3-2.zip"
it worked, i thought i had python installed but apparently not, thanks
I used ai for my problem https://chatgpt.com/share/69a71d31-47fc-800b-977c-eba5ef8fee95
hey yall i need some help, every time i do it, it spits out
File "C:\Users\User\Desktop\Rp_processor\resource_pack_processer.py", line 56 ... print(f"Error: File '{zip_path}' not found or is not a .zip file.") IndentationError: expected an indented block after 'if' statement on line 55am i missing something? my command is
python resource_pack_processer.py Vanilla-labPBR-1-3-2.zipno matter what resource pack i use it doesnt seem to work, tried administrator and recopying the script maybe a dozen times now lol, it just keeps spitting out not found. thanks in advance! quick edit: ive also tried the full file path to .zip with and without double quotationdon't copy code download script directy right click on raw then Save link as it will download script and wont give error
https://chatgpt.com/share/69a71d31-47fc-800b-977c-eba5ef8fee95
hey does anyone else have a weird issue where none of the resourcepacks you drop in the folder show up in the actual menu in minecraft itself?
hey does anyone else have a weird issue where none of the resourcepacks you drop in the folder show up in the actual menu in minecraft itself?
Yes but I'm unsure how to fix it yet.
Step by step guide for noobs:
- Download Python
- Download the Python file by clicking Raw > Right click > Save as > Save
- Create an Empty Folder. Put the Resource Pack .zip file you want to re-process in the folder as well as process_pbr_pack.py.
- Right click an empty spot in the folder and Open Terminal. This will open Powershell.
- In Powershell type:
python process_pbr_pack.py "SPBR-18_7[Legacy].zip"<--- replace what's inside "" with whatever your Resoure Pack's file name is, including .zip. - Drag and Drop the new Processed Zip file into your resource packs folder.
Step by step guide for noobs:
5. In Powershell type:python process_pbr_pack.py "SPBR-18_7[Legacy].zip"<--- replace what's inside "" with whatever your Resoure
Pack's file name is, including .zip.
In step 5, you can also type python and then use the Tab key to select files in the folder in the correct order.
hey does anyone else have a weird issue where none of the resourcepacks you drop in the folder show up in the actual menu in minecraft itself?
same issue here with spbr and pixili seems to put the game stuck in the mojang loading screen
Hey, I was wondering, could you show me how I can use this script as I want to try the radiance mod with the texture pack