From 4b9d8282d03b2ad07019c2add80d88c1d0736b2b Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:49:32 +0100 Subject: [PATCH] Share identical imperial atlas artwork in the central pack --- .forgejo/workflows/resourcepack-ci.yml | 2 +- tools/build-central-resource-pack.mjs | 25 +++++++++++++++++++++++ tools/build-planet-texture-packs.test.mjs | 22 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/resourcepack-ci.yml b/.forgejo/workflows/resourcepack-ci.yml index 8d06dea0..cf7b282b 100644 --- a/.forgejo/workflows/resourcepack-ci.yml +++ b/.forgejo/workflows/resourcepack-ci.yml @@ -102,7 +102,7 @@ jobs: target.parent.mkdir(parents=True, exist_ok=True) target.write_bytes(data) PYTHON - node tools/build-central-resource-pack.mjs central-pack-base central-pack-output 4 network/resource-pack/shared + node tools/build-central-resource-pack.mjs central-pack-base central-pack-output 5 network/resource-pack/shared printf '%s\n' "$GITHUB_SHA" > central-pack-output/SOURCE_COMMIT (cd central-pack-output && sha256sum -- *.zip central-pack-manifest.json SOURCE_COMMIT > SHA256SUMS) - uses: actions/upload-artifact@v3 diff --git a/tools/build-central-resource-pack.mjs b/tools/build-central-resource-pack.mjs index 1e5d6bce..cc4368eb 100644 --- a/tools/build-central-resource-pack.mjs +++ b/tools/build-central-resource-pack.mjs @@ -61,11 +61,36 @@ export function mergePackAssets(base,sources){ return merged; } +function deduplicateImperialAtlas(entries){ + const legacy='dunerealms:gui/imperial_menu_atlas_v2'; + const canonical='dunerealms:gui/imperial-menu-atlas-v2'; + const legacyFile='assets/dunerealms/textures/gui/imperial_menu_atlas_v2.png'; + const canonicalFile='assets/dunerealms/textures/gui/imperial-menu-atlas-v2.png'; + const oldBytes=entries.get(legacyFile),newBytes=entries.get(canonicalFile); + if(!oldBytes||!newBytes||!oldBytes.equals(newBytes)||entries.has(legacyFile+'.mcmeta')||entries.has(canonicalFile+'.mcmeta'))return; + for(const [name,data] of entries){ + if(name.endsWith('.json')&&data.includes(Buffer.from(legacy+'.png')))return; + } + const aliases=new Map(); + for(const path of [blocksAtlas,'assets/minecraft/atlases/items.json']){ + if(!entries.has(path))return; + const atlas=JSON.parse(entries.get(path)); + const index=atlas.sources?.findIndex(source=> + (source.type==='single'||source.type==='minecraft:single')&&source.resource===legacy&&(source.sprite??source.resource)===legacy); + if(index==null||index<0)return; + atlas.sources[index]={...atlas.sources[index],resource:canonical,sprite:legacy}; + aliases.set(path,json(atlas)); + } + for(const [name,bytes] of aliases)entries.set(name,bytes); + entries.delete(legacyFile); +} + export function centralPackEntries(base,planetEntries=textureEntries,assetSources=[]){ const merged=mergePackAssets(base,assetSources); 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'); + deduplicateImperialAtlas(merged); 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') diff --git a/tools/build-planet-texture-packs.test.mjs b/tools/build-planet-texture-packs.test.mjs index 39731f8a..09da2cad 100644 --- a/tools/build-planet-texture-packs.test.mjs +++ b/tools/build-planet-texture-packs.test.mjs @@ -172,3 +172,25 @@ test('the supplied DuneMenus logo glyph points to compact shared artwork',()=>{ assert(image.readUInt32BE(20)<=36); assert(image.length<16*1024); }); + +test('identical imperial atlas artwork shares a texture while retaining both sprite registrations',()=>{ + const atlasPaths=['assets/minecraft/atlases/blocks.json','assets/minecraft/atlases/items.json']; + const legacy='dunerealms:gui/imperial_menu_atlas_v2', canonical='dunerealms:gui/imperial-menu-atlas-v2'; + const oldFile='assets/dunerealms/textures/gui/imperial_menu_atlas_v2.png'; + const newFile='assets/dunerealms/textures/gui/imperial-menu-atlas-v2.png'; + const source=Buffer.from(JSON.stringify({sources:[{type:'single',resource:legacy}]})); + const fixture=new Map([['pack.mcmeta',Buffer.from('{"pack":{"pack_format":64}}')], + [oldFile,Buffer.from('identical')],[newFile,Buffer.from('identical')],...atlasPaths.map(name=>[name,source])]); + const entries=centralPackEntries(fixture,()=>new Map()); + assert(!entries.has(oldFile)); + assert(entries.has(newFile)); + for(const name of atlasPaths){ + assert.deepEqual(JSON.parse(entries.get(name)).sources[0],{type:'single',resource:canonical,sprite:legacy}); + } + const different=new Map(fixture); + different.set(oldFile,Buffer.from('different')); + assert(centralPackEntries(different,()=>new Map()).has(oldFile)); + const direct=new Map(fixture); + direct.set('assets/dunerealms/font/direct.json',Buffer.from(JSON.stringify({providers:[{file:legacy+'.png'}]}))); + assert(centralPackEntries(direct,()=>new Map()).has(oldFile)); +});