Fix mod loading for 1.7.10.

The launcher was never intended for use with 1.7.10, however since people
do use it for this version I generated a 1.7.10 distribution with Nebula
and tested it out. Several bugs were identified and fixed.

* Don't prefix modList paths with absolute on 1.7.10.
* Allow library overrides.

Forge 1.7.10 updates mojang's guava version. As such the library
resolver now supports overriding mojang libraries through the
distribution.json.

Fixes #45.
This commit is contained in:
Daniel Scalzi 2020-01-18 12:02:00 -05:00
parent 1110119df0
commit 96db607912
No known key found for this signature in database
GPG Key ID: D18EA3FB4B142A57

View File

@ -184,12 +184,19 @@ class ProcessBuilder {
}
}
_isBelowOneDotSeven() {
return Number(this.forgeData.id.split('-')[0].split('.')[1]) <= 7
}
/**
* Test to see if this version of forge requires the absolute: prefix
* on the modListFile repository field.
*/
_requiresAbsolute(){
try {
if(this._isBelowOneDotSeven()) {
return false
}
const ver = this.forgeData.id.split('-')[2]
const pts = ver.split('.')
const min = [14, 23, 3, 2655]
@ -542,7 +549,12 @@ class ProcessBuilder {
// Mod List File Argument
mcArgs.push('--modListFile')
mcArgs.push('absolute:' + this.fmlDir)
if(this._isBelowOneDotSeven()) {
mcArgs.push(path.basename(this.fmlDir))
} else {
mcArgs.push('absolute:' + this.fmlDir)
}
// LiteLoader
if(this.usingLiteLoader){
@ -579,11 +591,15 @@ class ProcessBuilder {
// Resolve the Mojang declared libraries.
const mojangLibs = this._resolveMojangLibraries(tempNativePath)
cpArgs = cpArgs.concat(mojangLibs)
// Resolve the server declared libraries.
const servLibs = this._resolveServerLibraries(mods)
cpArgs = cpArgs.concat(servLibs)
// Merge libraries, server libs with the same
// maven identifier will override the mojang ones.
// Ex. 1.7.10 forge overrides mojang's guava with newer version.
const finalLibs = {...mojangLibs, ...servLibs}
cpArgs = cpArgs.concat(Object.values(finalLibs))
return cpArgs
}
@ -595,10 +611,10 @@ class ProcessBuilder {
* TODO - clean up function
*
* @param {string} tempNativePath The path to store the native libraries.
* @returns {Array.<string>} An array containing the paths of each library mojang declares.
* @returns {{[id: string]: string}} An object containing the paths of each library mojang declares.
*/
_resolveMojangLibraries(tempNativePath){
const libs = []
const libs = {}
const libArr = this.versionData.libraries
fs.ensureDirSync(tempNativePath)
@ -609,7 +625,8 @@ class ProcessBuilder {
const dlInfo = lib.downloads
const artifact = dlInfo.artifact
const to = path.join(this.libPath, artifact.path)
libs.push(to)
const versionIndependentId = lib.name.substring(0, lib.name.lastIndexOf(':'))
libs[versionIndependentId] = to
} else {
// Extract the native library.
const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/']
@ -657,21 +674,21 @@ class ProcessBuilder {
* declare libraries.
*
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
* @returns {Array.<string>} An array containing the paths of each library this server requires.
* @returns {{[id: string]: string}} An object containing the paths of each library this server requires.
*/
_resolveServerLibraries(mods){
const mdls = this.server.getModules()
let libs = []
let libs = {}
// Locate Forge/Libraries
for(let mdl of mdls){
const type = mdl.getType()
if(type === DistroManager.Types.ForgeHosted || type === DistroManager.Types.Library){
libs.push(mdl.getArtifact().getPath())
libs[mdl.getVersionlessID()] = mdl.getArtifact().getPath()
if(mdl.hasSubModules()){
const res = this._resolveModuleLibraries(mdl)
if(res.length > 0){
libs = libs.concat(res)
libs = {...libs, ...res}
}
}
}
@ -682,7 +699,7 @@ class ProcessBuilder {
if(mods.sub_modules != null){
const res = this._resolveModuleLibraries(mods[i])
if(res.length > 0){
libs = libs.concat(res)
libs = {...libs, ...res}
}
}
}