Provide matching Bedrock item art and food component mappings

This commit is contained in:
unimatrixgit 2026-12-06 15:13:06 +01:00
commit 36d1f02ef6
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,43 @@
"""Build additive Geyser v2 item-model mappings and the matching Bedrock artwork pack.
Format/component contract: https://geysermc.org/wiki/geyser/custom-items/
No Java or existing Bedrock pack is replaced. Source is the same authored99-item catalogue.
"""
import argparse,json,uuid
from pathlib import Path
from plugin_wild_update import digest,write_archive
from cooking_beta_artwork import artwork,STONE,STONE_SHA
def build(source,output):
source=Path(source);output=Path(output);output.mkdir(parents=True,exist_ok=True)
rows=json.loads((source/'network/content-assets/cookbook/regional-cooking.json').read_text(encoding='utf-8'))['items']
sprites=artwork(source);mapping={'format_version':2,'items':{}};textures={};files={};names=[]
for row in rows:
ident=row['id'];key='dr_cooking_'+ident;bedrock='dunerealms:cooking_'+ident
if row['kind']=='resource':components={'!minecraft:food':{},'!minecraft:consumable':{}}
else:
drink=row['kind']=='drink'or bool(row.get('alcohol'))
components={'minecraft:food':{'nutrition':row['nutrition'],'saturation':row['saturation'],'can_always_eat':drink},'minecraft:consumable':{'animation':'drink'if drink else'eat','consume_seconds':1.6}}
definition={'type':'definition','model':row['model'],'bedrock_identifier':bedrock,'display_name':row['name'],'bedrock_options':{'icon':key,'allow_offhand':True,'creative_category':'items'},'components':components}
mapping['items'].setdefault('minecraft:'+row['material'],[]).append(definition)
textures[key]={'textures':'textures/items/cooking/'+ident}
files['textures/items/cooking/'+ident+'.png']=sprites['assets/dunerealms/textures/item/cooking/'+ident+'.png']
names.append('item.'+bedrock+'.name='+row['name'])
encode=lambda d:(json.dumps(d,indent=2,ensure_ascii=False)+'\n').encode('utf-8')
packid=str(uuid.uuid5(uuid.NAMESPACE_URL,'https://www.dunerealms.com/packs/cooking-baking-beta/bedrock/v1'))
moduleid=str(uuid.uuid5(uuid.NAMESPACE_URL,'https://www.dunerealms.com/packs/cooking-baking-beta/bedrock/v1/resources'))
files['manifest.json']=encode({'format_version':2,'header':{'name':'DuneRealms Cooking & Baking Beta','description':'Regional food, drink and ingredient artwork. Original DuneRealms pixel art.','uuid':packid,'version':[1,0,0],'min_engine_version':[1,21,0]},'modules':[{'type':'resources','uuid':moduleid,'version':[1,0,0]}]})
files['textures/item_texture.json']=encode({'resource_pack_name':'dunerealms_cooking_beta','texture_name':'atlas.items','texture_data':textures})
files['texts/en_US.lang']=('\n'.join(names)+'\n').encode('utf-8')
files['pack_icon.png']=sprites['assets/dunerealms/textures/item/cooking/praline_box.png']
stone=(source/'network/resource-pack/realistic-stone-family'/STONE).read_bytes()
if digest(stone)!=STONE_SHA:raise ValueError('Unreviewed Bedrock stone override')
files['textures/blocks/stone.png']=stone
pack=write_archive(files);mapping_bytes=encode(mapping)
(output/'DuneRealms-Cooking-Beta-Bedrock-v1.mcpack').write_bytes(pack)
(output/'dunerealms-cooking-beta-v2.json').write_bytes(mapping_bytes)
proof={'items':len(rows),'packUuid':packid,'packSha256':digest(pack),'mappingSha256':digest(mapping_bytes),'entries':{n:digest(b)for n,b in files.items()},'source':'network/content-assets/cookbook/regional-cooking.json'}
(output/'bedrock-cooking-proof.json').write_bytes(encode(proof));return proof
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('source',type=Path);p.add_argument('output',type=Path);a=p.parse_args();r=build(a.source,a.output);print(json.dumps({k:v if not isinstance(v,dict)else len(v)for k,v in r.items()}))

View file

@ -0,0 +1,27 @@
import json,sys,tempfile,unittest,zipfile
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parent))
import build_cooking_bedrock as b
ROOT=Path(__file__).resolve().parents[1]
class BedrockCookingTest(unittest.TestCase):
def test_all99_model_and_food_contracts_match_native_and_pack(self):
rows=json.loads((ROOT/'network/content-assets/cookbook/regional-cooking.json').read_text())['items']
with tempfile.TemporaryDirectory()as tmp:
out=Path(tmp);proof=b.build(ROOT,out);mapping=json.loads((out/'dunerealms-cooking-beta-v2.json').read_bytes());defs=[d for group in mapping['items'].values()for d in group]
self.assertEqual(len(defs),99);self.assertEqual(len({d['bedrock_identifier']for d in defs}),99)
self.assertEqual(len({d['model']for d in defs}),99)
with zipfile.ZipFile(out/'DuneRealms-Cooking-Beta-Bedrock-v1.mcpack')as z:
textures=json.loads(z.read('textures/item_texture.json'))['texture_data'];manifest=json.loads(z.read('manifest.json'))
self.assertNotEqual(manifest['header']['uuid'],manifest['modules'][0]['uuid'])
self.assertEqual(len(textures),99)
for row in rows:
d=next(x for x in defs if x['model']==row['model']);key=d['bedrock_options']['icon'];self.assertIn(textures[key]['textures']+'.png',z.namelist())
self.assertIn(d,mapping['items']['minecraft:'+row['material']])
if row['kind']=='resource':self.assertEqual(d['components'],{'!minecraft:food':{},'!minecraft:consumable':{}})
else:
self.assertEqual(d['components']['minecraft:food']['nutrition'],row['nutrition']);self.assertEqual(d['components']['minecraft:food']['saturation'],row['saturation'])
drink=row['kind']=='drink'or bool(row.get('alcohol'));self.assertEqual(d['components']['minecraft:food']['can_always_eat'],drink)
first=(out/'DuneRealms-Cooking-Beta-Bedrock-v1.mcpack').read_bytes();b.build(ROOT,out);self.assertEqual(first,(out/'DuneRealms-Cooking-Beta-Bedrock-v1.mcpack').read_bytes())
if __name__=='__main__':unittest.main()