Update index.js

This commit is contained in:
2vb 2023-11-21 04:00:46 -08:00
parent 9ebc14eabf
commit 08b496942c

View File

@ -16,24 +16,28 @@ jsonfile.readFile(itemRemaps, function (err, obj) {
}); });
/* /*
TODO:
Textures to check in the future: Textures to check in the future:
- Clock - Clock
- Compass - Compass
- Filled Map - Filled Map
- Potion - Potion
Fix "EISDIR" error.
*/ */
extract('1.8'); extract('1.8');
// extract("1.20.1")
function extract(string) { /**
const extractedPath = `out/${string}/assets/minecraft/textures/`; * @param {string} input Name of resource pack zip file
decompress(`test/${string}.zip`, `out/${string}`).then(files => { */
function extract(input) {
const extractedPath = `out/${input}/assets/minecraft/textures/`;
decompress(`test/${input}.zip`, `out/${input}`).then(files => {
files.forEach(element => { files.forEach(element => {
if (!element.path.includes('assets/minecraft/textures/')) { if (!element.path.includes('assets/minecraft/textures/')) {
return; return;
} }
// const texture = element.path.match(/(?:[A-Za-z]*\/)*([A-Za-z]*)\/([A-Za-z_0-9]*)\.(png\.mcmeta|png)/);
const texture = element.path.match(/([A-Za-z]*)\/([A-Za-z]*)\/([A-Za-z_0-9]*)\.(png\.mcmeta|png)/); const texture = element.path.match(/([A-Za-z]*)\/([A-Za-z]*)\/([A-Za-z_0-9]*)\.(png\.mcmeta|png)/);
if (!texture) return; if (!texture) return;
let type = texture[1]; let type = texture[1];
@ -51,38 +55,14 @@ function extract(string) {
rename = blocks[name]; rename = blocks[name];
} }
const path1 = `${extractedPath}${type}/`; const path1 = `${extractedPath}${type}/`;
// if (type == 'items') {
// rename == items;
// }
// if (type == 'blocks') {
// rename == blocks;
// }
if (rename) { if (rename) {
try { try {
fs.renameSync(`${path1}${name}.${extension}`, `${path1}${rename}.${extension}`); fs.renameSync(`${path1}${name}.${extension}`, `${path1}${rename}.${extension}`);
console.log(`Renamed ${path1}${name}.${extension} to ${path1}${rename}.${extension}`); console.log(`Renamed ${path1}${name}.${extension} to ${path1}${rename}.${extension}`);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
// console.log(`(type ${type}\nsubtype ${subtype}\nname ${name}\nextension ${extension})`);
} }
} }
// 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 (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);
// }
// }
// console.log(texture);
}); });
}).then(() => { }).then(() => {
try { try {
@ -97,12 +77,12 @@ function extract(string) {
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
jsonfile.readFile(`out/${string}/pack.mcmeta`, function (err, obj) { jsonfile.readFile(`out/${input}/pack.mcmeta`, function (err, obj) {
if (err) console.error(err); if (err) console.error(err);
const oldFormat = obj.pack.pack_format; const oldFormat = obj.pack.pack_format;
const newFormat = 15; const newFormat = 15;
obj.pack.pack_format = newFormat; obj.pack.pack_format = newFormat;
jsonfile.writeFile(`out/${string}/pack.mcmeta`, obj, { spaces: 2 }, function (err) { jsonfile.writeFile(`out/${input}/pack.mcmeta`, obj, { spaces: 2 }, function (err) {
if (err) console.error(err); if (err) console.error(err);
console.log(`Pack format changed from ${oldFormat} to ${newFormat}`); console.log(`Pack format changed from ${oldFormat} to ${newFormat}`);
}); });