Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.5 support #85

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/generator-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: devcontainers/[email protected]
modmuss50 marked this conversation as resolved.
Show resolved Hide resolved
- 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:
Expand Down
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
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
Loading