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