65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
const decompress = require('decompress');
|
|
const fs = require('fs');
|
|
const jsonfile = require('jsonfile');
|
|
const file = 'blocks.json';
|
|
let blocks;
|
|
jsonfile.readFile(file, function (err, obj) {
|
|
if (err) console.error(err);
|
|
blocks = obj;
|
|
});
|
|
|
|
|
|
extract('1.8');
|
|
// extract("1.20.1")
|
|
// TODO (maybe): clock and compass textures
|
|
function extract(string) {
|
|
const extractedPath = 'out/assets/minecraft/textures/';
|
|
decompress(`test/${string}.zip`, 'out/').then(files => {
|
|
files.forEach(element => {
|
|
if (!element.path.includes('assets/minecraft/textures/')) {
|
|
return;
|
|
}
|
|
const texture = element.path.match(/(?:[A-Za-z]*\/)*([A-Za-z]*)\/([A-Za-z_0-9]*)\.(png\.mcmeta|png)/);
|
|
/*
|
|
[
|
|
'assets/minecraft/textures/misc/vignette.png.mcmeta',
|
|
'misc',
|
|
'vignette',
|
|
'png.mcmeta',
|
|
index: 0,
|
|
input: 'assets/minecraft/textures/misc/vignette.png.mcmeta',
|
|
groups: undefined
|
|
]
|
|
*/
|
|
if (texture) {
|
|
// const path = texture[0];
|
|
const type = texture[1];
|
|
const name = texture[2];
|
|
const extension = texture[3];
|
|
const rename = blocks[name];
|
|
const poggers = `${extractedPath}${type}/`;
|
|
if (type == 'blocks' && rename) {
|
|
try {
|
|
fs.renameSync(`${poggers}${name}.${extension}`, `${poggers}${rename}.${extension}`);
|
|
console.log(`Renamed ${poggers}${name}.${extension} to ${poggers}${rename}.${extension}`);
|
|
}
|
|
catch (err) {
|
|
console.log(err);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}).then(() => {
|
|
fs.renameSync(`${extractedPath}blocks`, `${extractedPath}block`);
|
|
jsonfile.readFile('out/pack.mcmeta', function (err, obj) {
|
|
if (err) console.error(err);
|
|
const oldFormat = obj.pack.pack_format;
|
|
obj.pack.pack_format = 15;
|
|
jsonfile.writeFile('out/pack.mcmeta', obj, { spaces: 2 }, function (err) {
|
|
if (err) console.error(err);
|
|
console.log(`${oldFormat} changed to 15`);
|
|
});
|
|
});
|
|
});
|
|
}
|