Created
November 7, 2025 16:36
-
-
Save zlataovce/1b9ae2939eb295d9dc78c61e00e13e3a to your computer and use it in GitHub Desktop.
A slicer script for importing Minecraft JARs easily.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const MANIFEST_URL = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"; | |
| const categorizeVersion = (version) => { | |
| const v = version.id; | |
| if (v.startsWith("c") || v.startsWith("rd-")) return "classic"; | |
| if (v.startsWith("inf-") || v.startsWith("in-")) return "infdev_indev"; | |
| if (v.startsWith("a")) return "alpha"; | |
| if (v.startsWith("b")) return "beta"; | |
| if (/^\d{2}w\d{2}[a-z]/.test(v) || /^\d{4}/.test(v)) return "snapshots"; | |
| const match = v.match(/^(\d+)\.(\d+)/); | |
| if (match) { | |
| const major = parseInt(match[1]); | |
| const minor = parseInt(match[2]); | |
| if (major === 1) { | |
| if (minor >= 0 && minor <= 6) return "1.0-1.6"; | |
| if (minor >= 7 && minor <= 12) return "1.7-1.12"; | |
| if (minor >= 13 && minor <= 16) return "1.13-1.16"; | |
| if (minor >= 17 && minor <= 20) return "1.17-1.20"; | |
| if (minor >= 21) return "1.21+"; | |
| } | |
| } | |
| return "other"; | |
| }; | |
| const downloadMinecraftJar = async (versionId, context, client) => { | |
| try { | |
| const manifestResponse = await fetch(MANIFEST_URL); | |
| const manifest = await manifestResponse.json(); | |
| const versionEntry = manifest.versions.find((v) => v.id === versionId); | |
| if (!versionEntry) { | |
| console.error(`version ${versionId} not found`); | |
| return; | |
| } | |
| const versionResponse = await fetch(versionEntry.url); | |
| const versionData = await versionResponse.json(); | |
| const jarUrl = client | |
| ? versionData.downloads?.client?.url | |
| : versionData.downloads?.server?.url; | |
| if (!jarUrl) { | |
| console.error(`JAR not found for ${versionId}`); | |
| return; | |
| } | |
| console.log(`downloading Minecraft ${versionId}...`); | |
| const jarResponse = await fetch(jarUrl); | |
| const jarData = await jarResponse.arrayBuffer(); | |
| const entryName = `minecraft-${client ? "client" : "server"}-${versionId}.jar`; | |
| await context.workspace.add(entryName, new Uint8Array(jarData)); | |
| } catch (error) { | |
| console.error(`error downloading Minecraft ${versionId}:`, error); | |
| } | |
| }; | |
| const createVersionButtons = async () => { | |
| try { | |
| const response = await fetch(MANIFEST_URL); | |
| const manifest = await response.json(); | |
| const categories = { | |
| "1.21+": [], | |
| "1.17-1.20": [], | |
| "1.13-1.16": [], | |
| "1.7-1.12": [], | |
| "1.0-1.6": [], | |
| "beta": [], | |
| "alpha": [], | |
| "infdev_indev": [], | |
| "classic": [], | |
| "snapshots": [], | |
| "other": [] | |
| }; | |
| manifest.versions.forEach((version) => { | |
| const category = categorizeVersion(version); | |
| categories[category].push(version.id); | |
| }); | |
| const options = []; | |
| const categoryLabels = { | |
| "1.21+": "1.21+", | |
| "1.17-1.20": "1.17 - 1.20", | |
| "1.13-1.16": "1.13 - 1.16", | |
| "1.7-1.12": "1.7 - 1.12", | |
| "1.0-1.6": "1.0 - 1.6", | |
| "beta": "Beta", | |
| "alpha": "Alpha", | |
| "infdev_indev": "Infdev/Indev", | |
| "classic": "Classic", | |
| "snapshots": "Snapshots", | |
| "other": "Other" | |
| }; | |
| for (const [category, versions] of Object.entries(categories)) { | |
| if (versions.length === 0) continue; | |
| const buttons = versions.map((versionId) => ({ | |
| type: "group", | |
| id: `minecraft_group_${category}_${versionId}`, | |
| label: versionId, | |
| options: [ | |
| { type: "button", id: `minecraft_${versionId}_client`, label: "Client" }, | |
| { type: "button", id: `minecraft_${versionId}_server`, label: "Server" } | |
| ] | |
| })); | |
| options.push({ | |
| type: "group", | |
| id: `minecraft_group_${category}`, | |
| label: categoryLabels[category], | |
| options: buttons | |
| }); | |
| } | |
| return options; | |
| } catch (error) { | |
| console.error("error fetching Minecraft versions:", error); | |
| return []; | |
| } | |
| }; | |
| export default { | |
| name: "Minecraft", | |
| description: "Import Minecraft JARs directly into the workspace.", | |
| version: "1.0.0", | |
| options: [], | |
| async load(context) { | |
| const versionOptions = await createVersionButtons(); | |
| context.script.options = versionOptions; | |
| context.addEventListener("option_change", async (event) => { | |
| const option = event.option; | |
| if (option.type === "button" && option.id.startsWith("minecraft_")) { | |
| const versionId = option.id.substring(10, option.id.length - 7); | |
| await downloadMinecraftJar(versionId, context, option.id.endsWith("_client")); | |
| } | |
| }); | |
| }, | |
| unload(context) { | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment