Skip to content

Commit

Permalink
1.20.5 support (#85)
Browse files Browse the repository at this point in the history
* 1.20.5 support

* Maybe fix tests

* Actually use Java 21

* Install java in devcontainer

* Fix test
  • Loading branch information
modmuss50 authored Apr 21, 2024
1 parent 2a0c101 commit 38328bb
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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}"
3 changes: 2 additions & 1 deletion cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -297,7 +298,7 @@ async function defaultOptions(
startingName: string,
): Promise<generator.Configuration> {
const minecraftVersions = await generator.getTemplateGameVersions();
const minecraftVersion = minecraftVersions[0]!.version;
const minecraftVersion = minecraftVersions.find((v) => v.stable)!.version;

return {
modid: generator.nameToModId(startingName),
Expand Down
3 changes: 2 additions & 1 deletion cli/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/assert/mod.ts";
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions scripts/src/lib/Template.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
});
Expand Down
24 changes: 22 additions & 2 deletions scripts/src/lib/template/java.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMinorMinecraftVersion } from "./minecraft";
import { getMinorMinecraftVersion, getPathMinecraftVersion } from "./minecraft";

export interface JavaVersion {
compatibility: string,
Expand Down Expand Up @@ -28,16 +28,36 @@ 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;
}
}

return JAVA_17;
// Minecraft 1.20.5 and above use Java 21
return JAVA_21;
}

const JAVA_PACKAGE_REGEX = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/;
Expand Down
12 changes: 11 additions & 1 deletion scripts/src/lib/template/minecraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion scripts/src/lib/template/modjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion scripts/src/lib/template/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ export async function generateTemplate(options: Options) {

export async function getTemplateGameVersions(): Promise<GameVersion[]> {
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") {
// Hide pre 1.14.4 MC versions as they require using V1 yarn.
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;
});
}
Expand Down
1 change: 0 additions & 1 deletion scripts/src/lib/template/templates/git/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38328bb

Please sign in to comment.