Files
sanctuary-beta/tools/generate-fourneau-models.py
T
2026-09-17 03:10:39 +02:00

42 lines
2.8 KiB
Python

"""Tile original 48px artwork across the six faces of a 3x3x3 furnace.
No image resampling: JSON UVs select thirds of the supplied source PNGs.
"""
import json
import copy
from pathlib import Path
embers = json.loads(Path(__file__).with_name('fourneau-embers.json').read_text())
root = Path(__file__).resolve().parents[1] / 'mods/sanctuary/src/main/resources/assets/sanctuary/models/block/fourneau'
root.mkdir(parents=True, exist_ok=True)
for facing in ('north', 'east', 'south', 'west'):
for y in range(3):
for z in range(3):
for x in range(3):
faces = {}
for direction, u, v in [('north',2-x,2-y),('south',x,2-y),('east',2-z,2-y),('west',z,2-y),('up',x,z),('down',x,2-z)]:
texture = 'top' if direction in ('up','down') else 'front' if direction == facing else 'side'
faces[direction] = {'texture':'#'+texture, 'cullface':direction, 'uv':[u*16/3,v*16/3,(u+1)*16/3,(v+1)*16/3]}
model = {'textures':{n:'sanctuary:block/fourneau/'+n for n in ('front','side','top')} | {'particle':'sanctuary:block/fourneau/side'},
'elements':[{'from':[0,0,0],'to':[16,16,16],'faces':faces}]}
(root / f'{facing}_{x}_{y}_{z}.json').write_text(json.dumps(model,indent=2)+'\n')
# Preserve every original masonry pixel. Only the dark aperture strips
# receive the generated fire artwork, slightly ahead of the native face.
lit = copy.deepcopy(model)
lit['textures']['embers'] = 'sanctuary:block/fourneau/front_on'
front = {'north': z == 0, 'south': z == 2, 'east': x == 2, 'west': x == 0}[facing]
u0 = {'north': 2-x, 'south': x, 'east': 2-z, 'west': z}[facing]*16
v0 = (2-y)*16
if front:
for row, start, end in embers:
lo, hi = max(start,u0), min(end,u0+16)
if not v0 <= row < v0+16 or lo >= hi:
continue
a,b = lo-u0,hi-u0
bottom,top = 15-(row-v0),16-(row-v0)
if facing == 'north': begin,finish = [16-b,bottom,-.002],[16-a,top,-.002]
elif facing == 'south': begin,finish = [a,bottom,16.002],[b,top,16.002]
elif facing == 'east': begin,finish = [16.002,bottom,16-b],[16.002,top,16-a]
else: begin,finish = [-.002,bottom,a],[-.002,top,b]
lit['elements'].append({'from':begin,'to':finish,'faces':{facing:{
'texture':'#embers','cullface':facing,'uv':[lo/3,row/3,hi/3,(row+1)/3]}}})
(root / f'{facing}_{x}_{y}_{z}_lit.json').write_text(json.dumps(lit,indent=2)+'\n')