From 86123bba089f825e1c68424cbb7e771cae8f0739 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 13:04:19 +0100 Subject: [PATCH 1/5] 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 From bb3311f8a1a664a484b589ce2fbdcbfffc117bdd Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 13:13:35 +0100 Subject: [PATCH 2/5] Maybe fix tests --- .github/workflows/generator-test.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/generator-test.yml b/.github/workflows/generator-test.yml index d900c4f0..da0d07f7 100644 --- a/.github/workflows/generator-test.yml +++ b/.github/workflows/generator-test.yml @@ -6,11 +6,18 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: devcontainers/ci@v0.3 + - uses: actions/setup-node@v3 with: - runCmd: | - cd cli - make run test + node-version: 18 + - uses: denoland/setup-deno@v1 + with: + deno-version: "1.34.0" + - uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'microsoft' + - run: make run test + working-directory: ./cli - uses: actions/upload-artifact@v4 with: path: From 062cebd92d94ee71898af847515bcc645385dbee Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 13:22:05 +0100 Subject: [PATCH 3/5] Actually use Java 21 --- scripts/src/lib/template/java.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/src/lib/template/java.ts b/scripts/src/lib/template/java.ts index ed2a3848..446b407f 100644 --- a/scripts/src/lib/template/java.ts +++ b/scripts/src/lib/template/java.ts @@ -57,7 +57,7 @@ export function getJavaVersion(minecraftVersion: string): JavaVersion { } // Minecraft 1.20.5 and above use Java 21 - return JAVA_17; + return JAVA_21; } const JAVA_PACKAGE_REGEX = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/; From 4b1a51d7edd092e263e9ad0c7267a83940929e58 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 12:58:22 +0000 Subject: [PATCH 4/5] Install java in devcontainer --- .github/workflows/generator-test.yml | 15 ++++----------- Dockerfile | 6 +++++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/generator-test.yml b/.github/workflows/generator-test.yml index da0d07f7..d900c4f0 100644 --- a/.github/workflows/generator-test.yml +++ b/.github/workflows/generator-test.yml @@ -6,18 +6,11 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: devcontainers/ci@v0.3 with: - node-version: 18 - - uses: denoland/setup-deno@v1 - with: - deno-version: "1.34.0" - - uses: actions/setup-java@v4 - with: - java-version: 21 - distribution: 'microsoft' - - run: make run test - working-directory: ./cli + runCmd: | + cd cli + make run test - uses: actions/upload-artifact@v4 with: path: diff --git a/Dockerfile b/Dockerfile index 0796163b..899ec75c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,4 +14,8 @@ RUN gem install jekyll bundler ENV DENO_INSTALL="$HOME/.deno" ENV DENO_INSTALL_ROOT="$HOME/.deno" RUN curl -fsSL https://deno.land/x/install/install.sh | sh -ENV PATH="${PATH}:$HOME/.deno/bin" \ No newline at end of file +ENV PATH="${PATH}:$HOME/.deno/bin" + +ENV JAVA_HOME=/opt/java/openjdk +COPY --from=eclipse-temurin:21 $JAVA_HOME $JAVA_HOME +ENV PATH="${JAVA_HOME}/bin:${PATH}" \ No newline at end of file From 8641aabd16e0863781faafb927fcbd6e5343ce85 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 21 Apr 2024 14:05:10 +0100 Subject: [PATCH 5/5] Fix test --- cli/test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/test.ts b/cli/test.ts index 92d56cff..44be5a22 100644 --- a/cli/test.ts +++ b/cli/test.ts @@ -2,6 +2,7 @@ import { generateTemplate, getTemplateGameVersions, + minecraftSupportsSplitSources, } from "../scripts/dist/fabric-template-generator.js"; import { getGeneratorOptions } from "./commands/init.ts"; import { assert } from "https://deno.land/std@0.221.0/assert/mod.ts"; @@ -36,7 +37,7 @@ for (const { version } of minecraftVersions) { projectName: "test", packageName: "net.fabricmc.generator.test", dataGeneration: false, - splitSources: true, + splitSources: minecraftSupportsSplitSources(version), uniqueModIcon: true, minecraftVersion: version,