DTweaks/textures/make_bundles.py

106 lines
3.4 KiB
Python
Raw Permalink Normal View History

from PIL import Image
import os
import json
variants = [
{"name": "normal", "data": 0},
{"name": "iron", "data": 100},
{"name": "gold", "data": 200},
{"name": "diamond", "data": 300},
{"name": "netherite", "data": 400}
]
colors = [
{"name": "black", "data": 0},
{"name": "blue", "data": 1},
{"name": "brown", "data": 2},
{"name": "cyan", "data": 3},
{"name": "gray", "data": 4},
{"name": "green", "data": 5},
{"name": "light_blue", "data": 6},
{"name": "light_gray", "data": 7},
{"name": "lime", "data": 8},
{"name": "magenta", "data": 9},
{"name": "orange", "data": 10},
{"name": "pink", "data": 11},
{"name": "purple", "data": 12},
{"name": "red", "data": 13},
{"name": "white", "data": 14},
{"name": "yellow", "data": 15}
]
COLOR_SRC_DIR = "src/bundles/colors"
VARIANT_SRC_DIR = "src/bundles/variants"
MODEL_OUTPUT_DIR = "out/bundles/models"
TEXTURE_OUTPUT_DIR = "out/bundles/textures"
bundle_model = {
"parent": "item/generated",
"textures": {
"layer0": "item/bundle"
},
"overrides": [
{
"predicate": {
"filled": 0.0000001
},
"model": "item/bundle_filled"
},
]
}
for variant in variants:
variant_name = variant["name"]
variant_data = variant["data"]
for color in colors:
color_name = color["name"]
color_data = color["data"]
color_image = Image.open(f"{COLOR_SRC_DIR}/{color_name}_bundle.png")
color_image_filled = Image.open(f"{COLOR_SRC_DIR}/{color_name}_bundle_filled.png")
variant_image = Image.open(f"{VARIANT_SRC_DIR}/cord_{variant_name}.png")
variant_image_filled = Image.open(f"{VARIANT_SRC_DIR}/cord_{variant_name}_filled.png")
color_image.paste(variant_image, None, variant_image)
color_image_filled.paste(variant_image_filled, None, variant_image_filled)
color_image.save(f"{TEXTURE_OUTPUT_DIR}/{color_name}_{variant_name}_bundle.png")
color_image_filled.save(f"{TEXTURE_OUTPUT_DIR}/{color_name}_{variant_name}_bundle_filled.png")
bundle_model["overrides"].append({
"predicate": {
"custom_model_data": (variant_data + color_data)
},
"model": f"item/{color_name}_{variant_name}_bundle"
})
bundle_model["overrides"].append({
"predicate": {
"filled": 0.0000001,
"custom_model_data": variant_data + color_data
},
"model": f"item/{color_name}_{variant_name}_bundle_filled"
})
with open(f"{MODEL_OUTPUT_DIR}/{color_name}_{variant_name}_bundle.json", "w") as output_file:
json.dump({
"parent": "item/bundle",
"textures": {
"layer0": f"item/{color_name}_{variant_name}_bundle"
}
}, output_file, indent=4)
with open(f"{MODEL_OUTPUT_DIR}/{color_name}_{variant_name}_bundle_filled.json", "w") as output_file:
json.dump({
"parent": "item/bundle_filled",
"textures": {
"layer0": f"item/{color_name}_{variant_name}_bundle_filled"
}
}, output_file, indent=4)
with open(f"{MODEL_OUTPUT_DIR}/bundle.json", "w") as output_file:
json.dump(bundle_model, output_file, indent=4)