From 86123bba089f825e1c68424cbb7e771cae8f0739 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 13:04:19 +0100 Subject: [PATCH] 1.20.5 support --- cli/commands/init.ts | 3 ++- scripts/src/lib/Template.svelte | 5 ++--- scripts/src/lib/template/java.ts | 22 ++++++++++++++++++- scripts/src/lib/template/minecraft.ts | 12 +++++++++- scripts/src/lib/template/modjson.ts | 6 ++++- scripts/src/lib/template/template.ts | 9 +++++++- .../lib/template/templates/git/workflow.yml | 1 - 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/cli/commands/init.ts b/cli/commands/init.ts index e4909098..51166e63 100644 --- a/cli/commands/init.ts +++ b/cli/commands/init.ts @@ -237,6 +237,7 @@ async function promptUser( minecraftVersion = await Select.prompt({ message: "Select the minecraft version", options: minecraftVersions.map((v) => v.version), + default: minecraftVersions.find((v) => v.stable)?.version, }); } @@ -297,7 +298,7 @@ async function defaultOptions( startingName: string, ): Promise { const minecraftVersions = await generator.getTemplateGameVersions(); - const minecraftVersion = minecraftVersions[0]!.version; + const minecraftVersion = minecraftVersions.find((v) => v.stable)!.version; return { modid: generator.nameToModId(startingName), diff --git a/scripts/src/lib/Template.svelte b/scripts/src/lib/Template.svelte index a257570e..de99dd92 100644 --- a/scripts/src/lib/Template.svelte +++ b/scripts/src/lib/Template.svelte @@ -21,10 +21,9 @@ $: modid = nameToModId(projectName); const versions = Promise.all([getTemplateGameVersions()]).then(([gameVersions]) => { - const game = gameVersions; - minecraftVersion = game[0].version; + minecraftVersion = gameVersions.find((version) => version.stable)!.version; return { - game, + game: gameVersions, }; }); diff --git a/scripts/src/lib/template/java.ts b/scripts/src/lib/template/java.ts index b65489fc..ed2a3848 100644 --- a/scripts/src/lib/template/java.ts +++ b/scripts/src/lib/template/java.ts @@ -1,4 +1,4 @@ -import { getMinorMinecraftVersion } from "./minecraft"; +import { getMinorMinecraftVersion, getPathMinecraftVersion } from "./minecraft"; export interface JavaVersion { compatibility: string, @@ -28,15 +28,35 @@ const JAVA_17 : JavaVersion = { kotlinRelease: "17" } +const JAVA_21 : JavaVersion = { + compatibility: "VERSION_21", + mixin: "JAVA_21", + release: 21, + kotlinRelease: "21" +} + export function getJavaVersion(minecraftVersion: string): JavaVersion { const minor = getMinorMinecraftVersion(minecraftVersion); if (minor <= 16) { + // Minecraft 1.16 and below use Java 8 return JAVA_8; } else if (minor == 17) { + // Minecraft 1.17 uses Java 16 return JAVA_16; + } else if (minor <= 19) { + // Minecraft 1.18 and 1.19 use all Java 17 + return JAVA_17; + } else if (minor == 20) { + const patch = getPathMinecraftVersion(minecraftVersion); + + if (patch <= 4) { + // Minecraft 1.20.0 -> 1.20.4 use Java 17 + return JAVA_17; + } } + // Minecraft 1.20.5 and above use Java 21 return JAVA_17; } diff --git a/scripts/src/lib/template/minecraft.ts b/scripts/src/lib/template/minecraft.ts index 6ebeb864..0a5f4d25 100644 --- a/scripts/src/lib/template/minecraft.ts +++ b/scripts/src/lib/template/minecraft.ts @@ -7,7 +7,17 @@ export function minecraftSupportsSplitSources(minecraftVersion: string): boolean } export function getMinorMinecraftVersion(minecraftVersion: string): number { - return Number(minecraftVersion.split(".")[1]); + return getVersionParts(minecraftVersion)[1]; +} + +export function getPathMinecraftVersion(minecraftVersion: string): number { + return getVersionParts(minecraftVersion)[2]; +} + +function getVersionParts(minecraftVersion: String): number[] { + // Remove any snapshot or pre-release suffix + const targetVersion = minecraftVersion.split("-")[0]; + return targetVersion.split(".").map((v) => parseInt(v)); } export function sharedModIdChecks(id: string, isId: boolean): string[] | undefined { diff --git a/scripts/src/lib/template/modjson.ts b/scripts/src/lib/template/modjson.ts index 2f2b88cf..ce830716 100644 --- a/scripts/src/lib/template/modjson.ts +++ b/scripts/src/lib/template/modjson.ts @@ -15,6 +15,10 @@ export async function addModJson(writer: TemplateWriter, canvas: CanvasAdaptorFa ...(config.splitSources ? await generateClientMixin(writer, config) : []) ]; + // Format the minecraft version with any pre3, or rc1, etc. suffixes + const index = config.minecraftVersion.indexOf("-"); + const minecraftVersion = config.minecraftVersion.substring(0, index === -1 ? config.minecraftVersion.length : index + 1); + const fabricModJson : any = { "schemaVersion": 1, "id": config.modid, @@ -35,7 +39,7 @@ export async function addModJson(writer: TemplateWriter, canvas: CanvasAdaptorFa "mixins": mixins, "depends": { "fabricloader": ">=" + config.loaderVersion, - "minecraft": "~" + config.minecraftVersion, + "minecraft": "~" + minecraftVersion, "java": ">=" + getJavaVersion(config.minecraftVersion).release }, "suggests": { diff --git a/scripts/src/lib/template/template.ts b/scripts/src/lib/template/template.ts index dcbecba3..4286963b 100644 --- a/scripts/src/lib/template/template.ts +++ b/scripts/src/lib/template/template.ts @@ -84,7 +84,7 @@ export async function generateTemplate(options: Options) { export async function getTemplateGameVersions(): Promise { let versions = await getGameVersions() - return versions.filter((v) => v.stable).filter((v) => { + return versions.filter((v) => { const version = v.version; if (version.startsWith("1.14") && version != "1.14.4") { @@ -92,6 +92,13 @@ export async function getTemplateGameVersions(): Promise { return false; } + if (!v.stable) { + // Hide unstable versions, other than the latest -pre or -rc version. + const isLatest = versions[0].version == version; + const isPre = version.includes("-pre") || version.includes("-rc"); + return isLatest && isPre; + } + return true; }); } diff --git a/scripts/src/lib/template/templates/git/workflow.yml b/scripts/src/lib/template/templates/git/workflow.yml index 94d2e664..b01da52c 100644 --- a/scripts/src/lib/template/templates/git/workflow.yml +++ b/scripts/src/lib/template/templates/git/workflow.yml @@ -12,7 +12,6 @@ jobs: matrix: # Use these Java versions java: [ - 17, # Current Java LTS & minimum supported by Minecraft 21, # Current Java LTS ] runs-on: ubuntu-22.04