MC/tools/build-arrakis-fauna-pack.mjs
2026-11-27 23:43:05 +00:00

31 lines
2.8 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {createHash} from 'node:crypto';
import {textureEntries,zip} from './build-planet-texture-packs.mjs';
import {faunaModels,faunaSpriteAtlasEntries} from './build-fauna-models.mjs';
export function build(output){
const entries=textureEntries('arrakis');
const metadata=JSON.parse(entries.get('pack.mcmeta'));
Object.assign(metadata.pack,{supported_formats:{min_inclusive:64,max_inclusive:97},max_format:[97,1]});
entries.set('pack.mcmeta',Buffer.from(JSON.stringify(metadata)));
for(const [name,bytes] of faunaSpriteAtlasEntries())entries.set(name,bytes);
for(const [name,model]of Object.entries(faunaModels())){
entries.set(`assets/dunerealms/models/entity/${name}.json`,Buffer.from(JSON.stringify({ambientocclusion:false,...model})));
entries.set(`assets/dunerealms/items/entity/${name}.json`,Buffer.from(JSON.stringify({model:{type:'minecraft:model',model:`dunerealms:entity/${name}`}})));
}
entries.set('assets/dunerealms/textures/entity/jerboa.png',fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)),'../DuneRealmsGUI/ecology/textures/jerboa.png')));
for(const name of ['idle','hurt'])entries.set(`assets/dunerealms/sounds/jerboa_${name}.ogg`,fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)),`../DuneRealmsGUI/ecology/sounds/jerboa_${name}.ogg`)));
entries.set('assets/dunerealms/sounds.json',Buffer.from(JSON.stringify(Object.fromEntries(['idle','hurt'].map(name=>[`jerboa.${name}`,{sounds:[`dunerealms:jerboa_${name}`]}])))));
entries.set('licenses/Runes-and-Dunes-MIT.txt',fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)),'../DuneRealmsGUI/ecology/vendor/runes-and-dunes/NOTICE.txt')));
// Local Windows checkouts and Linux release workers must produce equal bytes.
for(const [name,bytes]of entries)if(/\.(?:txt|md)$/.test(name))entries.set(name,Buffer.from(bytes.toString('utf8').replaceAll('\r\n','\n')));
// v5 is the separately pinned, byte-preserving repair of published v4.
// Generated future candidates must not replace either immutable release.
const filename='DuneRealms-Materials-arrakis-v7.zip',bytes=zip(entries);
fs.mkdirSync(output,{recursive:true});fs.writeFileSync(path.join(output,filename),bytes);
const digest=algorithm=>createHash(algorithm).update(bytes).digest('hex');
const record={filename,url:'https://www.dunerealms.com/downloads/'+filename,sha1:digest('sha1'),sha256:digest('sha256'),bytes:bytes.length,entries:entries.size};
fs.writeFileSync(path.join(output,'arrakis-fauna-manifest.json'),JSON.stringify(record,null,2)+'\n');return record;
}
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url))console.log(JSON.stringify(build(path.resolve(process.argv[2]||'output/arrakis-fauna-pack'))));