From 9d3fba6072fe081fb354698a9e89235c704c2622 Mon Sep 17 00:00:00 2001 From: 2vb <2vb@protonmail.com> Date: Tue, 21 Nov 2023 03:19:54 -0800 Subject: [PATCH] i am immortal nothing can stop me --- .eslintrc.json | 1 - index.js | 121 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 84 insertions(+), 38 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8a27f7c..66bba94 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,6 @@ }, "rules": { "arrow-spacing": ["warn", { "before": true, "after": true }], - "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "comma-dangle": ["error", "always-multiline"], "comma-spacing": "error", "comma-style": "error", diff --git a/index.js b/index.js index 578bed1..dd9a54e 100644 --- a/index.js +++ b/index.js @@ -1,63 +1,110 @@ const decompress = require('decompress'); const fs = require('fs'); const jsonfile = require('jsonfile'); -const file = 'blocks.json'; +// const file = 'blocks.json'; +const blockRemaps = 'blocks.json'; let blocks; -jsonfile.readFile(file, function (err, obj) { +jsonfile.readFile(blockRemaps, function (err, obj) { if (err) console.error(err); blocks = obj; }); +const itemRemaps = 'items.json'; +let items; +jsonfile.readFile(itemRemaps, function (err, obj) { + if (err) console.error(err); + items = obj; +}); +/* +Textures to check in the future: +- Clock +- Compass +- Filled Map +- Potion +*/ 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 => { + const extractedPath = `out/${string}/assets/minecraft/textures/`; + decompress(`test/${string}.zip`, `out/${string}`).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); - } + // 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]; + const subtype = texture[2]; + const name = texture[3]; + const extension = texture[4]; + let rename; + if (type == 'textures') { + type = subtype; + } + if (type == 'items') { + rename = items[name]; + } + if (type == 'blocks') { + 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(() => { - fs.renameSync(`${extractedPath}blocks`, `${extractedPath}block`); - jsonfile.readFile('out/pack.mcmeta', function (err, obj) { + try { + fs.renameSync(`${extractedPath}blocks`, `${extractedPath}block`); + console.log(`Renamed ${extractedPath}blocks to ${extractedPath}block`); + } catch (error) { + console.log(error); + } + try { + fs.renameSync(`${extractedPath}items`, `${extractedPath}item`); + console.log(`Renamed ${extractedPath}items to ${extractedPath}item`); + } catch (error) { + console.log(error); + } + jsonfile.readFile(`out/${string}/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) { + const newFormat = 15; + obj.pack.pack_format = newFormat; + jsonfile.writeFile(`out/${string}/pack.mcmeta`, obj, { spaces: 2 }, function (err) { if (err) console.error(err); - console.log(`${oldFormat} changed to 15`); + console.log(`Pack format changed from ${oldFormat} to ${newFormat}`); }); }); });