forked from unimatrix/web
Give central pack planet assets their own namespaces
This commit is contained in:
parent
f5156942f9
commit
e43845b8b8
3 changed files with 35 additions and 12 deletions
|
|
@ -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 2
|
||||
node tools/build-central-resource-pack.mjs central-pack-base central-pack-output 3
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import {fileURLToPath} from 'node:url';
|
|||
import {profiles,textureEntries,zip} from './build-planet-texture-packs.mjs';
|
||||
|
||||
const texturePrefix='assets/minecraft/textures/';
|
||||
const packPrefix='assets/dunerealms/textures/planets/';
|
||||
const planetNamespaces={
|
||||
guild:'dr_guild',arrakis:'dr_arrakis',caladan:'dr_caladan',giedi_prime:'dr_giedi',
|
||||
kaitain:'dr_kaitain',sigma_draconis_iv:'dr_sigma',
|
||||
giedi_prime_nether:'dr_giedi',sigma_draconis_iv_the_end:'dr_sigma'
|
||||
};
|
||||
const blocksAtlas='assets/minecraft/atlases/blocks.json';
|
||||
const generatedLicenceText=new Set(['CREDITS-Sand.txt','LICENSE-Sand-Luanti.txt']);
|
||||
const cubeItems=fs.readFileSync(new URL('../JarvisConnector/src/main/resources/planet-cube-items.txt',import.meta.url),'utf8')
|
||||
|
|
@ -30,10 +34,14 @@ export function centralPackEntries(base,planetEntries=textureEntries){
|
|||
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)){
|
||||
const namespace=planetNamespaces[planet];
|
||||
if(!namespace)throw Error('Missing asset namespace for '+planet);
|
||||
const dimension=planet.endsWith('_nether')?'nether/':planet.endsWith('_the_end')?'the_end/':'';
|
||||
const textureDirectory='assets/'+namespace+'/textures/'+dimension;
|
||||
for(const [name,bytes] of planetEntries(planet)){
|
||||
if(name==='pack.mcmeta')continue;
|
||||
const target=name.startsWith(texturePrefix)
|
||||
?packPrefix+planet+'/'+name.slice(texturePrefix.length)
|
||||
?textureDirectory+name.slice(texturePrefix.length)
|
||||
:'licenses/planet-materials/'+name;
|
||||
// The standalone planet archives retain their existing published checksums.
|
||||
const content=generatedLicenceText.has(name)?Buffer.from(bytes.toString('utf8').replaceAll('\r\n','\n')):bytes;
|
||||
|
|
@ -41,19 +49,26 @@ export function centralPackEntries(base,planetEntries=textureEntries){
|
|||
}
|
||||
for(const material of cubeItems){
|
||||
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:')){
|
||||
const palette='block/'+material;
|
||||
const texture=merged.has(textureDirectory+palette+'.png')?namespace+':'+dimension+palette:'minecraft:block/'+material;
|
||||
if(texture.startsWith(namespace+':')){
|
||||
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);
|
||||
}
|
||||
}
|
||||
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({
|
||||
const model=namespace+':item/'+dimension+material;
|
||||
const definition=json({model:{type:'minecraft:model',model}});
|
||||
addEntry(merged,'assets/'+namespace+'/items/'+dimension+material+'.json',definition);
|
||||
addEntry(merged,'assets/'+namespace+'/models/item/'+dimension+material+'.json',json({
|
||||
parent:'minecraft:block/cube_all',textures:{all:texture}
|
||||
}));
|
||||
// Previously issued item stacks retain their stored item_model component.
|
||||
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:model}));
|
||||
}
|
||||
}
|
||||
merged.set(blocksAtlas,json(atlas));
|
||||
|
|
@ -74,7 +89,11 @@ export function buildCentralPack(baseDir,output,version){
|
|||
if(!/^[1-9][0-9]*$/.test(version))throw Error('A positive integer release version is required');
|
||||
const entries=centralPackEntries(readDirectory(baseDir));
|
||||
if(entries.size>65535)throw Error('The central pack exceeds the ZIP entry limit');
|
||||
const metadata=JSON.parse(entries.get('pack.mcmeta'));
|
||||
metadata.pack.description='DuneRealms Central Resource Pack v'+version;
|
||||
entries.set('pack.mcmeta',json(metadata));
|
||||
const bytes=zip(entries),filename='DuneRealms-Central-v'+version+'.zip';
|
||||
if(bytes.length>=250*1024*1024)throw Error('The central pack exceeds the Java client download limit');
|
||||
const manifest={
|
||||
filename,url:'https://www.dunerealms.com/downloads/'+filename,
|
||||
sha1:hash('sha1',bytes),sha256:hash('sha256',bytes),
|
||||
|
|
|
|||
|
|
@ -76,13 +76,17 @@ test('the central pack registers its planet block sprites without replacing exis
|
|||
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;
|
||||
if(!/^assets\/dr_[a-z]+\/models\/item\//.test(name))continue;
|
||||
const texture=JSON.parse(bytes).textures.all;
|
||||
if(!texture.startsWith('dunerealms:'))continue;
|
||||
if(!texture.startsWith('dr_'))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'));
|
||||
for(const planet of ['arrakis','caladan'])assert(sprites.has('dr_'+planet+':block/stone'));
|
||||
const canonical=JSON.parse(entries.get('assets/dr_arrakis/items/stone.json'));
|
||||
assert.equal(canonical.model.model,'dr_arrakis:item/stone');
|
||||
const legacy=JSON.parse(entries.get('assets/dunerealms/models/item/planets/arrakis/stone.json'));
|
||||
assert.equal(legacy.parent,canonical.model.model);
|
||||
assert.deepEqual(centralPackEntries(entries).get(atlasPath),entries.get(atlasPath));
|
||||
});
|
||||
|
||||
|
|
@ -112,7 +116,7 @@ test('the central builder preserves compatible common runtime assets and leaves
|
|||
const entries=centralPackEntries(base);
|
||||
for(const name of inherited)assert.deepEqual(entries.get(name),base.get(name),name);
|
||||
assert(!entries.has('assets/minecraft/textures/block/stone.png'));
|
||||
assert(entries.has('assets/dunerealms/textures/planets/arrakis/block/stone.png'));
|
||||
assert(entries.has('assets/dr_arrakis/textures/block/stone.png'));
|
||||
});
|
||||
|
||||
test('central generated licence text has identical ZIP bytes for Windows and LF inputs',()=>{
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff