forked from unimatrix/web
Register planet textures in the central block atlas
This commit is contained in:
parent
5f58251ee3
commit
c7638d5f94
2 changed files with 36 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<png.length;){const n=png.readUInt32BE(i);if(png.subarray(i+4,i+8).toString()===type)found.push(png.subarray(i+8,i+8+n));i+=12+n;}return Buffer.concat(found);}
|
||||
test('every sand palette has identical grain, darker spice, and zero shader relief',()=>{
|
||||
|
|
@ -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));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff