From c7638d5f948088652c59b1de346f703921db50e0 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sat, 28 Nov 2026 09:41:25 +0100 Subject: [PATCH] Register planet textures in the central block atlas --- tools/build-central-resource-pack.mjs | 13 +++++++++++++ tools/build-planet-texture-packs.test.mjs | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/build-central-resource-pack.mjs b/tools/build-central-resource-pack.mjs index 75cb8cb2..5981b00b 100644 --- a/tools/build-central-resource-pack.mjs +++ b/tools/build-central-resource-pack.mjs @@ -7,6 +7,7 @@ import {profiles,textureEntries,zip} from './build-planet-texture-packs.mjs'; const texturePrefix='assets/minecraft/textures/'; const packPrefix='assets/dunerealms/textures/planets/'; +const blocksAtlas='assets/minecraft/atlases/blocks.json'; const cubeItems=fs.readFileSync(new URL('../JarvisConnector/src/main/resources/planet-cube-items.txt',import.meta.url),'utf8') .split(/\r?\n/).map(line=>line.trim()).filter(Boolean); if(new Set(cubeItems).size!==cubeItems.length||cubeItems.some(item=>!/^[a-z0-9_]+$/.test(item)))throw Error('Invalid planet cube item catalogue'); @@ -18,6 +19,10 @@ export function centralPackEntries(base){ if(!merged.has('pack.mcmeta'))throw Error('The base must be an extracted network resource pack'); const packInfo=JSON.parse(merged.get('pack.mcmeta')); if(!packInfo.pack)throw Error('The network pack metadata is invalid'); + const atlas=merged.has(blocksAtlas)?JSON.parse(merged.get(blocksAtlas)):{sources:[]}; + if(!Array.isArray(atlas.sources))throw Error('The network blocks atlas is invalid'); + const sprites=new Map(atlas.sources.filter(source=>source.type==='single'||source.type==='minecraft:single') + .map(source=>[source.sprite??source.resource,source.resource])); for(const planet of Object.keys(profiles)){ for(const [name,bytes] of textureEntries(planet)){ if(name==='pack.mcmeta')continue; @@ -31,12 +36,20 @@ export function centralPackEntries(base){ const id=planet+'/'+material; const palette=planet+'/block/'+material; const texture=merged.has(packPrefix+palette+'.png')?'dunerealms:planets/'+palette:'minecraft:block/'+material; + if(texture.startsWith('dunerealms:')){ + if(sprites.has(texture)&&sprites.get(texture)!==texture)throw Error('Conflicting block atlas sprite: '+texture); + if(!sprites.has(texture)){ + atlas.sources.push({type:'single',resource:texture,sprite:texture}); + sprites.set(texture,texture); + } + } merged.set('assets/dunerealms/items/planets/'+id+'.json',json({model:{type:'minecraft:model',model:'dunerealms:item/planets/'+id}})); merged.set('assets/dunerealms/models/item/planets/'+id+'.json',json({ parent:'minecraft:block/cube_all',textures:{all:texture} })); } } + merged.set(blocksAtlas,json(atlas)); return merged; } diff --git a/tools/build-planet-texture-packs.test.mjs b/tools/build-planet-texture-packs.test.mjs index 40768834..d04ebd1a 100644 --- a/tools/build-planet-texture-packs.test.mjs +++ b/tools/build-planet-texture-packs.test.mjs @@ -7,6 +7,7 @@ import os from 'node:os'; import path from 'node:path'; import {build,profiles,textureEntries,protectedTextures} from './build-planet-texture-packs.mjs'; import {sandPalettes} from './flat-sand.mjs'; +import {centralPackEntries} from './build-central-resource-pack.mjs'; function chunks(png,type){const found=[];for(let i=8;i{ @@ -62,3 +63,25 @@ test('release archives round-trip, rebuild identically, and match client downloa } }finally{fs.rmSync(dir,{recursive:true,force:true});} }); + +test('the central pack registers its planet block sprites without replacing existing atlas sources',()=>{ + const atlasPath='assets/minecraft/atlases/blocks.json'; + const baseSource={type:'single',resource:'dunerealms:gui/imperial_menu_atlas_v2'}; + const base=new Map([ + ['pack.mcmeta',Buffer.from(JSON.stringify({pack:{pack_format:64}}))], + [atlasPath,Buffer.from(JSON.stringify({sources:[baseSource]}))] + ]); + const entries=centralPackEntries(base); + const atlas=JSON.parse(entries.get(atlasPath)); + assert.deepEqual(atlas.sources[0],baseSource); + const sprites=new Set(atlas.sources.map(source=>source.sprite??source.resource)); + for(const [name,bytes] of entries){ + if(!name.startsWith('assets/dunerealms/models/item/planets/'))continue; + const texture=JSON.parse(bytes).textures.all; + if(!texture.startsWith('dunerealms:'))continue; + assert(sprites.has(texture),'Missing atlas sprite '+texture); + assert(entries.has('assets/'+texture.replace(':','/textures/')+'.png'),'Missing texture file '+texture); + } + for(const planet of ['arrakis','caladan'])assert(sprites.has('dunerealms:planets/'+planet+'/block/stone')); + assert.deepEqual(centralPackEntries(entries).get(atlasPath),entries.get(atlasPath)); +});