2017-07-19 23:44:43 +03:00
|
|
|
#!/usr/bin/env python
|
2018-06-05 02:58:40 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-06-05 02:44:57 +03:00
|
|
|
# Texture Converter.
|
|
|
|
# Converts Minecraft resource packs to Minetest texture packs.
|
|
|
|
# See README.md.
|
2017-07-19 23:44:43 +03:00
|
|
|
|
|
|
|
__author__ = "Wuzzy"
|
2017-11-18 03:25:55 +03:00
|
|
|
__license__ = "MIT License"
|
2017-07-19 23:44:43 +03:00
|
|
|
__status__ = "Development"
|
|
|
|
|
2024-01-09 11:16:05 +03:00
|
|
|
import shutil, csv, os, tempfile, sys, argparse, glob
|
2024-01-09 10:56:29 +03:00
|
|
|
from PIL import Image
|
|
|
|
from collections import Counter
|
2017-11-18 04:33:43 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
from libtextureconverter.utils import detect_pixel_size, target_dir, colorize, colorize_alpha, handle_default_minecraft_texture, find_all_minecraft_resourcepacks
|
2024-01-09 20:28:43 +03:00
|
|
|
from libtextureconverter.convert import convert_textures
|
2024-01-10 06:31:45 +03:00
|
|
|
from libtextureconverter.config import SUPPORTED_MINECRAFT_VERSION, working_dir, mineclone2_path, appname, home
|
2017-11-18 05:40:29 +03:00
|
|
|
|
2024-01-09 11:16:05 +03:00
|
|
|
# Argument parsing
|
|
|
|
description_text = f"""This is the official MineClone 2 Texture Converter.
|
|
|
|
This will convert textures from Minecraft resource packs to
|
|
|
|
a Minetest texture pack.
|
|
|
|
|
|
|
|
Supported Minecraft version: {SUPPORTED_MINECRAFT_VERSION} (Java Edition)
|
|
|
|
"""
|
|
|
|
parser = argparse.ArgumentParser(description=description_text)
|
2024-01-10 06:31:45 +03:00
|
|
|
parser.add_argument("-i", "--input", help="Directory of Minecraft resource pack to convert")
|
2024-01-09 11:16:05 +03:00
|
|
|
parser.add_argument("-o", "--output", default=working_dir, help="Directory in which to put the resulting Minetest texture pack")
|
|
|
|
parser.add_argument("-p", "--pixelsize", type=int, help="Size (in pixels) of the original textures")
|
|
|
|
parser.add_argument("-d", "--dry_run", action="store_true", help="Pretend to convert textures without changing any files")
|
|
|
|
parser.add_argument("-v", "--verbose", action="store_true", help="Print out all copying actions")
|
2024-01-10 06:31:45 +03:00
|
|
|
parser.add_argument("-def", "--default", action="store_true", help="Use the default Minecraft texture pack")
|
2024-01-10 07:08:30 +03:00
|
|
|
parser.add_argument("-a", "--all", action="store_true", help="Convert all known Minecraft texturepacks")
|
2024-01-09 11:16:05 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
### SETTINGS ###
|
|
|
|
base_dir = args.input
|
|
|
|
output_dir = args.output
|
|
|
|
PXSIZE = args.pixelsize
|
|
|
|
# If True, will only make console output but not convert anything.
|
|
|
|
dry_run = args.dry_run
|
|
|
|
# If True, prints all copying actions
|
|
|
|
verbose = args.verbose
|
|
|
|
# If True, textures will be put into a texture pack directory structure.
|
|
|
|
# If False, textures will be put into MineClone 2 directories.
|
|
|
|
make_texture_pack = True # Adjust as needed
|
2017-11-18 04:33:43 +03:00
|
|
|
|
2024-01-10 06:31:45 +03:00
|
|
|
if args.default:
|
|
|
|
base_dir = handle_default_minecraft_texture(home, output_dir)
|
2024-01-09 10:56:29 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
if base_dir == None and not args.all:
|
2017-11-18 04:33:43 +03:00
|
|
|
print(
|
2018-06-05 03:03:07 +03:00
|
|
|
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
|
2017-11-18 04:33:43 +03:00
|
|
|
Mind-reading has not been implemented yet.
|
|
|
|
|
|
|
|
Try this:
|
2024-01-10 06:31:45 +03:00
|
|
|
"""+appname+""" -i <path to resource pack>
|
2017-11-18 04:33:43 +03:00
|
|
|
|
|
|
|
For the full help, use:
|
2017-11-18 05:42:44 +03:00
|
|
|
"""+appname+""" -h""")
|
2017-11-18 04:33:43 +03:00
|
|
|
sys.exit(2);
|
2017-07-19 23:44:43 +03:00
|
|
|
|
2017-11-18 04:33:43 +03:00
|
|
|
### END OF SETTINGS ###
|
2017-07-19 23:44:43 +03:00
|
|
|
|
2024-01-10 06:31:45 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
resource_packs = []
|
2017-07-19 23:44:43 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
if args.all:
|
|
|
|
for resource_path in find_all_minecraft_resourcepacks():
|
|
|
|
resource_packs.append(resource_path)
|
2019-02-08 00:22:07 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
if make_texture_pack and args.input:
|
|
|
|
resource_packs.append(args.input)
|
2017-07-28 15:20:50 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
for base_dir in resource_packs:
|
|
|
|
tex_dir = base_dir + "/assets/minecraft/textures"
|
2017-07-28 15:20:50 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
# Get texture pack name (from directory name)
|
|
|
|
bdir_split = base_dir.split("/")
|
|
|
|
output_dir_name = bdir_split[-1]
|
|
|
|
if len(output_dir_name) == 0:
|
|
|
|
if len(bdir_split) >= 2:
|
|
|
|
output_dir_name = base_dir.split("/")[-2]
|
|
|
|
else:
|
|
|
|
# Fallback
|
|
|
|
output_dir_name = "New_MineClone_2_Texture_Pack"
|
2017-07-28 15:20:50 +03:00
|
|
|
|
2024-01-10 07:08:30 +03:00
|
|
|
# ENTRY POINT
|
|
|
|
if make_texture_pack and not os.path.isdir(output_dir+"/"+output_dir_name):
|
|
|
|
os.mkdir(output_dir+"/"+output_dir_name)
|
|
|
|
|
|
|
|
# If, set to convert all resourcepacks, then autodetect pixel size
|
|
|
|
if args.all:
|
|
|
|
PXSIZE = None
|
|
|
|
|
|
|
|
if PXSIZE is None:
|
|
|
|
PXSIZE = detect_pixel_size(base_dir)
|
|
|
|
tempfile1 = tempfile.NamedTemporaryFile()
|
|
|
|
tempfile2 = tempfile.NamedTemporaryFile()
|
|
|
|
|
|
|
|
convert_textures(make_texture_pack, dry_run, verbose, base_dir, tex_dir, tempfile1, tempfile2, output_dir, output_dir_name, mineclone2_path, PXSIZE)
|
|
|
|
|
|
|
|
tempfile1.close()
|
|
|
|
tempfile2.close()
|