Skip to content

Commit

Permalink
Fix mod loading for 1.7.10.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dscalzi committed Jan 18, 2020
1 parent 1110119 commit 96db607
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions app/assets/js/processbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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/']
Expand Down Expand Up @@ -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}
}
}
}
Expand All @@ -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}
}
}
}
Expand Down

0 comments on commit 96db607

Please sign in to comment.