mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 12:16:21 +03:00
Forge Support
This commit is contained in:
parent
05daffc033
commit
f9fc29ee67
3 changed files with 47 additions and 22 deletions
|
@ -143,31 +143,45 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath
|
|||
}
|
||||
await new zip(forgeJarPath).extractEntryTo('version.json', path.join(root, 'forge', `${version.id}`), false, true)
|
||||
|
||||
const forgeLibs = require(path.join(root, 'forge', `${version.id}`, 'version.json')).libraries;
|
||||
const marvenUrl = 'http://files.minecraftforge.net/maven/';
|
||||
const forge = require(path.join(root, 'forge', `${version.id}`, 'version.json'));
|
||||
const forgeLibs = forge.libraries;
|
||||
const mavenUrl = 'http://files.minecraftforge.net/maven/';
|
||||
const defaultRepo = 'https://libraries.minecraft.net/';
|
||||
const paths = [];
|
||||
|
||||
const download = forgeLibs.map(async library => {
|
||||
const lib = library.name.split(':');
|
||||
|
||||
if(lib[0] === 'net.minecraftforge' && lib[1].includes('forge')) return;
|
||||
if(!library.url) return;
|
||||
|
||||
const url = `${marvenUrl}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${lib[1]}-${lib[2]}.jar`;
|
||||
let url = mavenUrl;
|
||||
const jarPath = path.join(root, 'libraries', `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`);
|
||||
const name = `${lib[1]}-${lib[2]}.jar`;
|
||||
|
||||
if(fs.existsSync(path.join(jarPath, name))) return;
|
||||
if(!library.url) {
|
||||
if(library.serverreq || library.clientreq) {
|
||||
url = defaultRepo;
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const downloadLink = `${url}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${lib[1]}-${lib[2]}.jar`;
|
||||
|
||||
if(fs.existsSync(path.join(jarPath, name))) {
|
||||
paths.push(`${jarPath}\\${name}`);
|
||||
return;
|
||||
}
|
||||
if(!fs.existsSync(jarPath)) shelljs.mkdir('-p', jarPath);
|
||||
|
||||
await downloadAsync(url, jarPath, name);
|
||||
await downloadAsync(downloadLink, jarPath, name);
|
||||
|
||||
paths.push(`${jarPath}//${name}`);
|
||||
paths.push(`${jarPath}\\${name}`);
|
||||
})
|
||||
|
||||
await Promise.all(download);
|
||||
|
||||
return paths;
|
||||
return {paths, forge};
|
||||
};
|
||||
|
||||
module.exports.getClasses = function (root, version) {
|
||||
|
|
|
@ -22,13 +22,12 @@ module.exports = async function (options) {
|
|||
await handler.getJar(versionFile, options.version.number, directory);
|
||||
}
|
||||
|
||||
const args = [];
|
||||
let forge = null;
|
||||
if(options.forge) {
|
||||
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
|
||||
}
|
||||
|
||||
// CGC
|
||||
args.push('-Xincgc');
|
||||
|
||||
// Memory
|
||||
const memory = [`-Xmx${options.memory.max}M`];
|
||||
const args = []
|
||||
|
||||
// Jvm
|
||||
let jvm = [
|
||||
|
@ -36,24 +35,36 @@ module.exports = async function (options) {
|
|||
'-XX:-OmitStackTraceInFastThrow',
|
||||
'-Dfml.ignorePatchDiscrepancies=true',
|
||||
'-Dfml.ignoreInvalidMinecraftCertificates=true',
|
||||
`-Djava.library.path=${nativePath}`
|
||||
`-Djava.library.path=${nativePath}`,
|
||||
`-Xmx${options.memory.max}M`,
|
||||
'-Xincgc'
|
||||
];
|
||||
jvm.push(await handler.getJVM(versionFile, options));
|
||||
|
||||
const classes = await handler.getClasses(options.root, versionFile);
|
||||
const classPaths = ['-cp'];
|
||||
let mainClass;
|
||||
const classPaths = [];
|
||||
if(forge) {
|
||||
classPaths.push(`${options.forge.path};${forge.paths.join(';')};${classes.join(';')};${mcPath}`);
|
||||
mainClass = forge.forge.mainClass
|
||||
} else {
|
||||
classPaths.push('-cp');
|
||||
classPaths.push(`${mcPath};${classes.join(";")}`);
|
||||
classPaths.push(versionFile.mainClass);
|
||||
}
|
||||
|
||||
// Download version's assets
|
||||
await handler.getAssets(options.root, versionFile);
|
||||
|
||||
// Launch options
|
||||
const launchOptions = await handler.getLaunchOptions(versionFile, options);
|
||||
if(forge) launchOptions.push('--tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker');
|
||||
|
||||
const arguments = args.concat(memory, jvm, classPaths, launchOptions);
|
||||
const minecraft = child.spawn("java", arguments);
|
||||
// NOTE: Hacky way of setting up launch options, will rework this next update.
|
||||
let launchArguments = args.concat(jvm, classPaths, launchOptions);
|
||||
if(forge) launchArguments = `${jvm.join(' ')} -cp ${classPaths} ${mainClass} ${launchOptions.join(' ')}`.split(' ');
|
||||
|
||||
const minecraft = child.spawn(`java`, launchArguments)
|
||||
event.emit('start', null);
|
||||
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
||||
minecraft.stderr.on('data', (data) => event.emit('error', data));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "minecraft-launcher-core",
|
||||
"version": "1.2.1",
|
||||
"description": "Module that downloads Minecraft assets and runs Minecraft.",
|
||||
"version": "2.0.0",
|
||||
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"adm-zip": "^0.4.13",
|
||||
|
|
Loading…
Add table
Reference in a new issue