nbt2blueprint/extract_java_textures.py

56 lines
2.4 KiB
Python

import zipfile
import os
def extract_java_textures(java_jar_path, output_dir):
"""
Extracts block textures from a Minecraft Java Edition client JAR.
Args:
java_jar_path (str): Full path to the Minecraft client JAR file (e.g., "C:/Users/YourUser/AppData/Roaming/.minecraft/versions/1.20.1/1.20.1.jar").
output_dir (str): Directory where the extracted textures will be saved.
"""
if not os.path.exists(java_jar_path):
print(f"Error: Java JAR file not found at {java_jar_path}")
return
texture_source_path_in_jar = 'assets/minecraft/textures/block/'
extracted_texture_path = os.path.join(output_dir, 'java_textures')
os.makedirs(extracted_texture_path, exist_ok=True)
print(f"Extracting textures from {java_jar_path} to {extracted_texture_path}...")
with zipfile.ZipFile(java_jar_path, 'r') as zip_ref:
for member in zip_ref.namelist():
if member.startswith(texture_source_path_in_jar) and member.endswith('.png'):
# Get the relative path within the block textures folder
relative_path = os.path.relpath(member, texture_source_path_in_jar)
# Construct the full output path
destination_path = os.path.join(extracted_texture_path, relative_path)
# Ensure the directory exists
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
# Extract the file
with open(destination_path, 'wb') as outfile:
outfile.write(zip_ref.read(member))
print("Texture extraction complete.")
if __name__ == "__main__":
# --- IMPORTANT: Set these paths correctly ---
# Path to your Minecraft Java Edition JAR file
mc_java_version = "1.21.5"
java_game_jar = f"C:/Users/NP110306/AppData/Roaming/.minecraft/versions/{mc_java_version}/{mc_java_version}.jar" # Adjust as needed!
# Directory where you want to save the extracted Java textures
output_textures_base_dir = "resources/" # Adjust as needed!
extract_java_textures(java_game_jar, output_textures_base_dir)
# Now, the 'java_textures' folder inside output_textures_base_dir
# will contain all the Java block PNGs.
# You can then directly map "minecraft:stone" to
# "C:/Users/NP110306/Desktop/Blueprint_Resources/java_textures/stone.png"
# (after handling the .png extension)