Skip to content

Instantly share code, notes, and snippets.

@NotNite
Created June 11, 2023 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NotNite/2fffd7fe32e1ec41077d4d48ada83e10 to your computer and use it in GitHub Desktop.
Save NotNite/2fffd7fe32e1ec41077d4d48ada83e10 to your computer and use it in GitHub Desktop.
packwiz-generator.js
// packwiz-generator - make a multimc instance zip for packwiz
// node index.js <URL to pack.toml>
// (c) notnite 2023, MIT license
const fs = require("fs");
const AdmZip = require("adm-zip");
const TOML = require("@iarna/toml");
const packUrl = process.argv[2];
const boostrapUrl =
"https://github.com/packwiz/packwiz-installer-bootstrap/releases/latest/download/packwiz-installer-bootstrap.jar";
const bootstrapOut = "./tmp/.minecraft/packwiz-installer-bootstrap.jar";
const instanceCfgOut = "./tmp/instance.cfg";
const mmcPackOut = "./tmp/mmc-pack.json";
async function main() {
console.log("making directories...");
if (!fs.existsSync("./out/")) fs.mkdirSync("./out/");
if (fs.existsSync("./tmp")) fs.rmSync("./tmp", { recursive: true });
fs.mkdirSync("./tmp");
fs.mkdirSync("./tmp/.minecraft");
console.log("downloading bootstrap...");
const bootstrap = await fetch(boostrapUrl).then((res) => res.arrayBuffer());
fs.writeFileSync(bootstrapOut, Buffer.from(bootstrap));
console.log("fetching pack...");
const pack = await fetch(packUrl)
.then((res) => res.text())
.then(TOML.parse);
const packName = pack.name;
console.log("writing instance.cfg...");
const instanceCfg = `
[General]
name=${packName}
OverrideCommands=true
PreLaunchCommand=$INST_JAVA -jar packwiz-installer-bootstrap.jar ${packUrl}
`.trim();
fs.writeFileSync(instanceCfg, instanceCfg);
// https://github.com/packwiz/packwiz-installer/blob/7b6daaf7e552f44888d68dcd8235822dd1c2956e/src/main/kotlin/link/infra/packwiz/installer/LauncherUtils.kt#LL48C2-L48C2
const nameMappings = {
minecraft: "net.minecraft",
forge: "net.minecraftforge",
fabric: "net.fabricmc.fabric-loader",
quilt: "org.quiltmc.quilt-loader",
liteloader: "com.mumfrey.liteloader"
};
const components = Object.entries(pack.versions).map(([name, version]) => ({
uid: nameMappings[name],
version: version
}));
const mmcPack = {
formatVersion: 1,
components
};
console.log("writing mmc-pack.json...");
fs.writeFileSync(mmcPackOut, JSON.stringify(mmcPack));
console.log("compressing...");
const zip = new AdmZip();
zip.addLocalFolder("./tmp");
zip.writeZip(`./out/${packName}.zip`);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment