Skip to content

Commit

Permalink
1.20.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Apr 21, 2024
1 parent 2a0c101 commit 86123bb
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
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
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
22 changes: 21 additions & 1 deletion 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,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;
}

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 86123bb

Please sign in to comment.