Skip to content

Commit

Permalink
Update to NeoForge 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 23, 2024
1 parent 2f0bbc5 commit bec55a8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 30 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Before you can execute this phase, you need a `modpack.json` file with contents
}
```

*The "forge" entry may be replaced by "neoforge".*

To start this phase, simply run `generate-mod-metadata modpack.json generate`.

Optionally, you can delete the resulting server files afterwards using `generate-mod-metadata modpack.json clean`.
Expand Down
2 changes: 1 addition & 1 deletion bin/generate-mod-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run(command: string, configPath: string) {
const modLoader = new ModLoader({
mods: config.mods,
path: join(process.cwd(), 'server'),
versionForge: config.forge,
loader: 'forge' in config ? { versionForge: config.forge } : { versionNeoForge: config.neoforge },
versionMinecraft: config.minecraft,
});

Expand Down
2 changes: 1 addition & 1 deletion lib/infobook/IItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface IItem {
item: string;
count?: number;
nbt?: string;
components?: string;
}
71 changes: 51 additions & 20 deletions lib/modloader/ModLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export class ModLoader {

private readonly mods: IMod[];
private readonly path: string;
private readonly versionForge: string;
private readonly loader: ILoader;
private readonly versionMinecraft: string;

constructor(args: IModLoaderArgs) {
this.mods = args.mods;
this.path = args.path;
this.versionForge = args.versionForge;
this.loader = args.loader;
this.versionMinecraft = args.versionMinecraft;
}

Expand All @@ -42,25 +42,45 @@ export class ModLoader {
await fs.promises.mkdir(this.path);
}

// Download Forge installer
process.stdout.write('Downloading Forge...\n');
const forgeInstaller: string = `https://files.minecraftforge.net/maven/net/minecraftforge/forge/${
this.versionMinecraft}-${this.versionForge}/forge-${this.versionMinecraft}-${this.versionForge}-installer.jar`;
const res = await fetch(forgeInstaller);
if (!res.ok) {
throw new Error(`Failed to fetch (${res.statusText}): ${forgeInstaller}`);
let installerFile: string;
if ('versionForge' in this.loader) {
// Download Forge installer
process.stdout.write('Downloading Forge...\n');
const forgeInstaller: string = `https://files.minecraftforge.net/maven/net/minecraftforge/forge/${
this.versionMinecraft}-${this.loader.versionForge}/forge-${this.versionMinecraft}-${this.loader.versionForge}-installer.jar`;
const res = await fetch(forgeInstaller);
if (!res.ok) {
throw new Error(`Failed to fetch (${res.statusText}): ${forgeInstaller}`);
}
installerFile = join(this.path, 'forge-installer.jar');
await new Promise<void>(async (resolve, reject) => fs.writeFile(installerFile,
await res.buffer(), (err) => err ? reject(err) : resolve()));

// Install Forge
process.stdout.write('Installing Forge...\n');
await new Promise((resolve, reject) => exec(
`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));
} else {
// Download NeoForge installer
process.stdout.write('Downloading NeoForge...\n');
const installer: string = `https://maven.neoforged.net/releases/net/neoforged/neoforge/${
this.loader.versionNeoForge}/neoforge-${this.loader.versionNeoForge}-installer.jar`;
const res = await fetch(installer);
if (!res.ok) {
throw new Error(`Failed to fetch (${res.statusText}): ${installer}`);
}
installerFile = join(this.path, 'neoforge-installer.jar');
await new Promise<void>(async (resolve, reject) => fs.writeFile(installerFile,
await res.buffer(), (err) => err ? reject(err) : resolve()));

// Install Forge
process.stdout.write('Installing NeoForge...\n');
await new Promise((resolve, reject) => exec(
`cd ${this.path} && java -jar neoforge-installer.jar --installServer`).on('exit', resolve));
}
const installerFile = join(this.path, 'forge-installer.jar');
await new Promise<void>(async (resolve, reject) => fs.writeFile(installerFile,
await res.buffer(), (err) => err ? reject(err) : resolve()));

// Install Forge
process.stdout.write('Installing Forge...\n');
await new Promise((resolve, reject) => exec(
`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));

// Wait a bit, because otherwise some files don't exist yet (while they should...)
process.stdout.write('Wait a bit after Forge installation...\n');
process.stdout.write('Wait a bit after mod loader installation...\n');
await new Promise((resolve) => setTimeout(resolve, 10000));

// Cleanup
Expand Down Expand Up @@ -102,7 +122,11 @@ export class ModLoader {
await this.downloadFile(url, fileName, modsDir);
} else if (mod.type === 'maven') {
process.stdout.write(` - ${mod.artifact} from ${mod.repo}...\n`);
await download(mod.artifact, modsDir, mod.repo);
const name = await download(mod.artifact, modsDir, mod.repo);
// Rename file if needed
if ('name' in mod) {
fs.renameSync(name, join(modsDir, mod.name));
}
} else if (mod.type === 'raw') {
process.stdout.write(` - ${mod.name} from ${mod.url}...\n`);
await this.downloadFile(mod.url, mod.name, modsDir);
Expand Down Expand Up @@ -315,16 +339,23 @@ export class ModLoader {
export interface IModLoaderArgs {
mods: IMod[];
path: string;
versionForge: string;
loader: ILoader;
versionMinecraft: string;
}

export type ILoader = {
versionForge: string;
} | {
versionNeoForge: string;
}

export type IMod = IModMaven | IModCurseforge | IModRaw;

export interface IModMaven {
type: 'maven';
artifact: string;
repo: string;
name?: string;
}

export interface IModCurseforge {
Expand Down
4 changes: 2 additions & 2 deletions lib/resource/ResourceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class ResourceHandler {
*/
public addItemTranslationKey(item: IItem, translationKey: string) {
const { namespace, path } = ResourceHandler.splitItemId(item.item);
ResourceHandler.addItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.nbt, translationKey);
ResourceHandler.addItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.components, translationKey);
}

/**
Expand All @@ -207,7 +207,7 @@ export class ResourceHandler {
*/
public getItemTranslationKey(item: IItem): string {
const { namespace, path } = ResourceHandler.splitItemId(item.item);
return ResourceHandler.getItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.nbt);
return ResourceHandler.getItemKeyedRegistryEntry(this.itemTranslationKeys, namespace, path, item.components);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/resource/ResourceLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ResourceLoader {
}

// Handle advancements
const advancementsDir = join(fullPath, 'advancements');
const advancementsDir = join(fullPath, 'advancement');
try {
if ((await fs.stat(langDir)).isDirectory()) {
await this.loadAssetsAdvancements(modid, advancementsDir, '');
Expand Down
2 changes: 1 addition & 1 deletion lib/serialize/HtmlInfoBookSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class HtmlInfoBookSerializer {
return slot ? '<div class="item item-slot">&nbsp;</div>' : '<div class="item">&nbsp;</div>';
}

const icon = resourceHandler.getItemIconFile(item.item, item.nbt);
const icon = resourceHandler.getItemIconFile(item.item, item.components);
if (!icon) {
throw new Error(`Could not find an icon for item ${JSON.stringify(item)}`);
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@
"rimraf": "^3.0.0",
"xml2js": "^0.4.19",
"yauzl": "^2.10.0"
},
"resolutions": {
"@types/istanbul-reports": "3.0.0"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,10 @@
dependencies:
"@types/istanbul-lib-coverage" "*"

"@types/istanbul-reports@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz#9153fe98bba2bd565a63add9436d6f0d7f8468ff"
integrity sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==
"@types/istanbul-reports@3.0.0", "@types/istanbul-reports@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.0.tgz#508b13aa344fa4976234e75dddcc34925737d821"
integrity sha512-nwKNbvnwJ2/mndE9ItP/zc2TCzw6uuodnF4EHYWD+gCQDVBuRQL5UzbZD0/ezy1iKsFU2ZQiDqg4M9dN4+wZgA==
dependencies:
"@types/istanbul-lib-report" "*"

Expand Down

0 comments on commit bec55a8

Please sign in to comment.