forked from unimatrix/web
Build and verify central pack candidates in development CI
This commit is contained in:
parent
7215f9aab2
commit
09cba2e732
2 changed files with 64 additions and 4 deletions
|
|
@ -14,6 +14,11 @@ if(new Set(cubeItems).size!==cubeItems.length||cubeItems.some(item=>!/^[a-z0-9_]
|
|||
const json=value=>Buffer.from(JSON.stringify(value));
|
||||
const hash=(algorithm,bytes)=>createHash(algorithm).update(bytes).digest('hex');
|
||||
|
||||
function addEntry(entries,name,bytes){
|
||||
if(entries.has(name)&&!entries.get(name).equals(bytes))throw Error('Conflicting pack entry: '+name);
|
||||
entries.set(name,bytes);
|
||||
}
|
||||
|
||||
export function centralPackEntries(base){
|
||||
const merged=new Map(base);
|
||||
if(!merged.has('pack.mcmeta'))throw Error('The base must be an extracted network resource pack');
|
||||
|
|
@ -29,8 +34,7 @@ export function centralPackEntries(base){
|
|||
const target=name.startsWith(texturePrefix)
|
||||
?packPrefix+planet+'/'+name.slice(texturePrefix.length)
|
||||
:'licenses/planet-materials/'+name;
|
||||
if(merged.has(target)&&!merged.get(target).equals(bytes))throw Error('Conflicting pack entry: '+target);
|
||||
merged.set(target,bytes);
|
||||
addEntry(merged,target,bytes);
|
||||
}
|
||||
for(const material of cubeItems){
|
||||
const id=planet+'/'+material;
|
||||
|
|
@ -43,8 +47,8 @@ export function centralPackEntries(base){
|
|||
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({
|
||||
addEntry(merged,'assets/dunerealms/items/planets/'+id+'.json',json({model:{type:'minecraft:model',model:'dunerealms:item/planets/'+id}}));
|
||||
addEntry(merged,'assets/dunerealms/models/item/planets/'+id+'.json',json({
|
||||
parent:'minecraft:block/cube_all',textures:{all:texture}
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,3 +85,14 @@ test('the central pack registers its planet block sprites without replacing exis
|
|||
for(const planet of ['arrakis','caladan'])assert(sprites.has('dunerealms:planets/'+planet+'/block/stone'));
|
||||
assert.deepEqual(centralPackEntries(entries).get(atlasPath),entries.get(atlasPath));
|
||||
});
|
||||
|
||||
test('central generation refuses to overwrite a different item definition or model',()=>{
|
||||
const metadata=Buffer.from(JSON.stringify({pack:{pack_format:64}}));
|
||||
const generated=centralPackEntries(new Map([['pack.mcmeta',metadata]]));
|
||||
for(const prefix of ['items','models/item']){
|
||||
const file='assets/dunerealms/'+prefix+'/planets/arrakis/stone.json';
|
||||
assert(generated.has(file));
|
||||
assert.throws(()=>centralPackEntries(new Map([['pack.mcmeta',metadata],[file,Buffer.from('{}')]])),
|
||||
error=>error.message==='Conflicting pack entry: '+file);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff