diff --git a/components/handler.js b/components/handler.js index 48b49d8..cd502bd 100644 --- a/components/handler.js +++ b/components/handler.js @@ -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) { diff --git a/components/launcher.js b/components/launcher.js index 3ad4fba..c5e8ad9 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -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']; - classPaths.push(`${mcPath}; ${classes.join(";")}`); - classPaths.push(versionFile.mainClass); + 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)); diff --git a/package.json b/package.json index 11c2867..61bdbb8 100644 --- a/package.json +++ b/package.json @@ -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",