plugins/network/resource-pack/central/generator/build_pack.py
unimatrixgit c9944bb832
Some checks failed
DuneRealms Plugin CI / plugins (push) Failing after 8m59s
Supplied Dune Item Art Build / supplied-item-art (push) Successful in 30s
Keep supplied source text in canonical Git line endings
2026-12-03 20:52:03 +01:00

118 lines
6 KiB
Python

#!/usr/bin/env python3
"""Build the DuneRealms central resource pack (overlay) from procedural art. Run: python3 build_pack.py OUTDIR"""
import json, os, shutil, sys, hashlib, zipfile
from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from PIL import Image
import soft_items as M
import soft_equipment as E
import blocks as B
OUT = sys.argv[1] if len(sys.argv) > 1 else "out/DuneRealms-Central-Pack"
ROOT = Path(__file__).resolve().parents[1]
OLD = str(ROOT / "legacy/assets/dunerealms/textures")
TOOLTIP = str(ROOT / "overlay/assets/dunerealms/textures/gui/sprites/tooltip")
A = f"{OUT}/assets/dunerealms"
MC = f"{OUT}/assets/minecraft"
manifest = {"textures": [], "item_models": []}
def save(img, path):
os.makedirs(os.path.dirname(path), exist_ok=True)
img.save(path, optimize=True)
manifest["textures"].append(os.path.relpath(path, OUT))
def wjson(path, obj):
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
json.dump(obj, f, separators=(",", ":"))
def item_def(rel_id, model_path, tex, handheld=False, parent=None):
"""rel_id: 'currency/coin_001' -> items/currency/coin_001.json ; model_path: 'item/currency/coin_001'"""
wjson(f"{A}/items/{rel_id}.json", {"model": {"type": "minecraft:model", "model": f"dunerealms:{model_path}"}})
wjson(f"{A}/models/{model_path}.json", {"parent": parent or ("minecraft:item/handheld" if handheld else "minecraft:item/generated"), "textures": {"layer0": f"dunerealms:{tex}"}})
manifest["item_models"].append(f"dunerealms:{rel_id}")
# ---- pack.mcmeta -------------------------------------------------------
wjson(f"{OUT}/pack.mcmeta", {"pack": {
"pack_format": 64,
"supported_formats": {"min_inclusive": 46, "max_inclusive": 99},
"description": "§6DuneRealms §7— central Dune pack · soft brass on desert sand"}})
# ---- currency (names match the live pack 1:1) ---------------------------
for n in M.COINS:
save(M.coin(n), f"{A}/textures/item/currency/{n}.png")
item_def(f"currency/{n}", f"item/currency/{n}", f"item/currency/{n}")
for n in M.NOTES:
save(M.note(n), f"{A}/textures/item/currency/{n}.png")
item_def(f"currency/{n}", f"item/currency/{n}", f"item/currency/{n}")
# ---- spy module ----------------------------------------------------------
save(M.spy_module(), f"{A}/textures/item/spy_module.png")
item_def("spy_module", "item/spy_module", "item/spy_module")
# ---- legacy ids kept so older plugin builds still resolve ------------------
for v in ("1", "5", "100", "1000", "5000", "note"):
save(M.legacy_note(v), f"{A}/textures/item/dunemark_{v}.png")
item_def(f"dunemark_{v}", f"item/dunemark_{v}", f"item/dunemark_{v}")
for p in M.PLANET_TINT:
save(M.planet(p, Image.open(f"{OLD}/item/planet_{p}.png")), f"{A}/textures/item/planet_{p}.png")
item_def(f"planet_{p}", f"item/planet_{p}", f"item/planet_{p}")
for k in ("crown", "spice", "water"):
save(M.office(k), f"{A}/textures/item/office_{k}.png")
item_def(f"office_{k}", f"item/office_{k}", f"item/office_{k}")
save(Image.new("RGBA", (1, 1), (0, 0, 0, 0)), f"{A}/textures/item/drgui_transparent.png")
item_def("drgui_transparent", "item/drgui_transparent", "item/drgui_transparent")
# ---- extra icons (hooks the plugins can adopt via item_model) --------------
extras = {
"spice_common": M.spice_crystal("#f4b85f", "#c9692b", "#e8913a"),
"spice_smuggled": M.spice_crystal("#eaa656", "#8f4a1f", "#d9822f", smuggled=True),
"spice_dense": M.spice_crystal("#f8c872", "#c05a1d", "#f0a640", dense=True),
"spice_refined": M.spice_crystal("#fbe2a2", "#e0912f", "#f3c45e", dense=True),
"water_vial": M.water_vial(),
"smugglers_water_vial": M.water_vial("#6ee7d8", smuggled=True),
"imperial_codex": M.imperial_codex(),
}
for n, img in extras.items():
save(img, f"{A}/textures/item/{n}.png")
item_def(n, f"item/{n}", f"item/{n}")
# ---- equipment: every valid (quality, mark) x type -------------------------
count = 0
for quality, mark in E.valid_marks():
tier = E.QUALITY.index(quality)
pips = (mark % 3) + 1 if quality != "mythic" else 3
for kind in E.TYPES:
name = f"{quality}_mk{mark}_{kind}"
save(E.draw(kind, tier, pips), f"{A}/textures/item/equipment/{name}.png")
item_def(f"equipment/{name}", f"item/equipment/{name}", f"item/equipment/{name}", handheld=kind in E.HANDHELD)
count += 1
# ---- blocks ---------------------------------------------------------------
for kind, bid, seed in (("spice", "spice_block", 7), ("smuggled", "smuggled_spice_block", 17), ("contaminated", "contaminated_spice_block", 27)):
for face in ("side", "top", "bottom"):
save(B.spice_face(kind, face, 32, seed), f"{A}/textures/block/{bid}_{face}.png")
wjson(f"{A}/models/block/{bid}.json", {"parent": "minecraft:block/cube_bottom_top", "textures": {
"side": f"dunerealms:block/{bid}_side", "top": f"dunerealms:block/{bid}_top", "bottom": f"dunerealms:block/{bid}_bottom"}})
wjson(f"{A}/items/{bid}.json", {"model": {"type": "minecraft:model", "model": f"dunerealms:block/{bid}"}})
manifest["item_models"].append(f"dunerealms:{bid}")
# carrier: the plugin's spice blocks are DRIED_KELP_BLOCK, so retexture the carrier everywhere
for face in ("side", "top", "bottom"):
save(B.spice_face("spice", face, 32, 7), f"{MC}/textures/block/dried_kelp_{face}.png")
for st in range(4):
save(B.suspicious_sand(st), f"{MC}/textures/block/suspicious_sand_{st}.png")
# ---- tooltip sprites (item-card frame), copied from the approved design ------
for f in ("dune_background.png", "dune_background.png.mcmeta", "dune_frame.png", "dune_frame.png.mcmeta"):
d = f"{A}/textures/gui/sprites/tooltip"
os.makedirs(d, exist_ok=True)
shutil.copy(f"{TOOLTIP}/{f}", f"{d}/{f}")
manifest["textures"].append(os.path.relpath(f"{d}/{f}", OUT))
with open(f"{OUT}/MANIFEST.json", "w") as f:
json.dump(manifest, f, indent=1)
print("equipment icons:", count, "| textures:", len(manifest["textures"]), "| item models:", len(manifest["item_models"]))