add neoforge modpacks support

This commit is contained in:
2026-01-01 17:45:11 +05:00
parent 5dc1744cfd
commit 687e2db51b
2 changed files with 228 additions and 101 deletions

View File

@ -6,15 +6,13 @@ import extract from 'extract-zip';
import { launch, Version, diagnose } from '@xmcl/core';
import { execSync } from 'child_process';
import {
installDependencies,
installFabric,
getFabricLoaders,
getVersionList,
install,
installTask,
installDependenciesTask,
installNeoForged,
} from '@xmcl/installer';
import { Dispatcher, Agent } from 'undici';
import { Agent } from 'undici';
import { spawn } from 'child_process';
import { AuthService } from './auth-service';
import { API_BASE_URL } from '../renderer/api';
@ -546,12 +544,14 @@ export function initMinecraftHandlers() {
username,
memory = 4096,
baseVersion = '1.21.4',
fabricVersion = '0.16.14',
fabricVersion = null,
neoForgeVersion = null,
packName = 'Comfort', // имя сборки (папка с модами)
versionToLaunchOverride = '', // переопределение версии для запуска (например, 1.21.10 для ванили)
serverIp = 'popa-popa.ru',
serverPort,
isVanillaVersion = false,
loaderType = 'fabric',
} = gameConfig || {};
const userDataPath = app.getPath('userData');
@ -590,23 +590,35 @@ export function initMinecraftHandlers() {
// Ваниль — запускаем baseVersion (или override)
versionToLaunch = effectiveBaseVersion;
} else {
// Модпак — запускаем именно fabric-версию
const fabricId = `${effectiveBaseVersion}-fabric${fabricVersion}`;
if (versionsContents.includes(fabricId)) {
versionToLaunch = fabricId;
// Определяем ID версии в зависимости от типа загрузчика
if (loaderType === 'neoforge' && neoForgeVersion) {
const neoForgeId = `neoforge-${neoForgeVersion}`;
if (versionsContents.includes(neoForgeId)) {
versionToLaunch = neoForgeId;
} else {
versionToLaunch = neoForgeId;
}
} else if (fabricVersion) {
const fabricId = `${effectiveBaseVersion}-fabric${fabricVersion}`;
if (versionsContents.includes(fabricId)) {
versionToLaunch = fabricId;
} else {
versionToLaunch = fabricId;
}
} else {
// даже если папки нет — installFabric её создаст
versionToLaunch = fabricId;
versionToLaunch = effectiveBaseVersion;
}
}
}
console.log('isVanillaVersion:', isVanillaVersion);
console.log('baseVersion:', baseVersion);
console.log('effectiveBaseVersion:', effectiveBaseVersion);
console.log('fabricVersion:', fabricVersion);
console.log('versionToLaunch:', versionToLaunch);
console.log('packDir:', packDir);
console.log('Конфигурация:', {
loaderType,
neoForgeVersion,
fabricVersion,
effectiveBaseVersion,
versionToLaunch,
versionsContents,
});
// --- Поиск Java ---
event.sender.send('installation-status', {
@ -705,35 +717,71 @@ export function initMinecraftHandlers() {
}
// --- 2. Установка Fabric (только для модпаков) ---
if (!isVanillaVersion && fabricVersion) {
try {
event.sender.send('installation-status', {
step: 'fabric-install',
message: `Установка Fabric ${fabricVersion}...`,
});
if (!isVanillaVersion) {
if (loaderType === 'neoforge' && neoForgeVersion) {
try {
event.sender.send('installation-status', {
step: 'neoforge-install',
message: `Установка NeoForge ${neoForgeVersion}...`,
});
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 0),
);
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 0), // Используем фазу fabric-install
);
console.log('installFabric:', {
minecraftVersion: effectiveBaseVersion,
fabricVersion,
minecraftDir,
});
console.log('installNeoForged:', {
project: 'neoforge',
version: neoForgeVersion,
minecraftVersion: effectiveBaseVersion,
minecraftDir,
});
await installFabric({
minecraftVersion: effectiveBaseVersion,
version: fabricVersion,
minecraft: minecraftDir,
});
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 1),
);
} catch (error) {
console.log('Ошибка при установке Fabric, продолжаем:', error);
// Установка NeoForge
await installNeoForged('neoforge', neoForgeVersion, minecraftDir, {
minecraft: effectiveBaseVersion,
java: javaPath,
side: 'client',
});
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 1),
);
} catch (error) {
console.log('Ошибка при установке NeoForge, продолжаем:', error);
}
} else if (fabricVersion) {
// Существующий код для Fabric
try {
event.sender.send('installation-status', {
step: 'fabric-install',
message: `Установка Fabric ${fabricVersion}...`,
});
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 0),
);
console.log('installFabric:', {
minecraftVersion: effectiveBaseVersion,
fabricVersion,
minecraftDir,
});
await installFabric({
minecraftVersion: effectiveBaseVersion,
version: fabricVersion,
minecraft: minecraftDir,
});
event.sender.send(
'overall-progress',
getGlobalProgress('fabric-install', 1),
);
} catch (error) {
console.log('Ошибка при установке Fabric, продолжаем:', error);
}
}
}
@ -991,12 +1039,17 @@ export function initMinecraftHandlers() {
const versionPath = path.join(versionsDir, item);
if (!fs.statSync(versionPath).isDirectory()) continue;
// ❗ Прячем технические fabric-версии типа 1.21.10-fabric0.18.1
if (item.includes('-fabric')) {
// ❗ Прячем технические версии загрузчиков
if (item.includes('-fabric') || item.includes('-neoforge')) {
continue;
}
const versionJsonPath = path.join(versionPath, `${item}.json`);
const files = fs.readdirSync(versionPath);
const jsonFile = files.find((f) => f.endsWith('.json'));
if (!jsonFile) continue;
const versionJsonPath = path.join(versionPath, jsonFile);
let versionInfo = {
id: item,
name: item,
@ -1270,7 +1323,9 @@ ipcMain.handle('get-version-config', async (event, { versionId }) => {
memory: 4096,
baseVersion: '1.21.10',
serverIp: 'popa-popa.ru',
fabricVersion: '0.18.1',
fabricVersion: null,
neoForgeVersion: null,
loaderType: 'fabric', // 'fabric', 'neoforge', 'vanilla'
preserveFiles: ['popa-launcher-config.json'],
};
@ -1282,6 +1337,20 @@ ipcMain.handle('get-version-config', async (event, { versionId }) => {
'https://api.github.com/repos/DIKER0K/Comfort/releases/latest';
config.baseVersion = '1.21.10';
config.fabricVersion = '0.18.1';
config.loaderType = 'fabric';
}
// Если это NeoForge сборка, добавьте соответствующие настройки
if (versionId === 'MyNeoForgePack') {
config.downloadUrl =
'https://github.com/YOUR_USERNAME/YOUR_NEOFORGE_PACK/releases/latest/download/MyNeoForgePack.zip';
config.apiReleaseUrl =
'https://api.github.com/repos/YOUR_USERNAME/YOUR_NEOFORGE_PACK/releases/latest';
config.baseVersion = '1.21.1';
config.fabricVersion = null;
config.neoForgeVersion = '20.6.2';
config.loaderType = 'neoforge';
config.memory = 6144; // NeoForge может требовать больше памяти
}
// Если есть конфигурационный файл, загружаем из него