Skip to content

Commit 93240fe

Browse files
committed
downloading mods
1 parent 4c24d57 commit 93240fe

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/minecraft.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function downloadLibraries(versionMeta) {
6868
async function downloadAssets(versionMeta) {
6969
const assetsDir = join(getMinecraftDir(), 'assets')
7070
const indexesDir = join(assetsDir, 'indexes')
71-
if (!existsSync(indexesDir)) mkdirSync(indexesDir)
71+
if (!existsSync(indexesDir)) mkdirSync(indexesDir, {recursive: true})
7272
const indexFile = join(indexesDir, `${versionMeta.assetIndex.id}.json`)
7373
if (!existsSync(indexFile)) {
7474
log(`Downloading ${versionMeta.assetIndex.id}.json...`)
@@ -89,6 +89,19 @@ async function downloadAssets(versionMeta) {
8989
}
9090
}
9191

92+
async function downloadMods(version) {
93+
const dir = join(getDirectory(), 'versions', version.id, 'mods')
94+
if (!existsSync(dir)) mkdirSync(dir, {recursive: true})
95+
version.mods.forEach(mod => {
96+
const fileName = mod.split('/')[mod.split('/').length - 1]
97+
if (!existsSync(join(dir, fileName))) {
98+
log(`Downloading mod ${fileName}...`)
99+
spawnSync('curl', ['-L', mod, '-o', join(dir, fileName)])
100+
log(`Successfully downloaded mod ${fileName}...`)
101+
}
102+
})
103+
}
104+
92105
async function downloadVersion(version, dir, statusCallback) {
93106
statusCallback('download_starting')
94107
if (!existsSync(dir)) mkdirSync(dir, {recursive: true})
@@ -147,6 +160,9 @@ async function downloadVersion(version, dir, statusCallback) {
147160
statusCallback('downloading_assets_starting')
148161
await downloadAssets(minecraftVersionMeta)
149162
statusCallback('downloading_assets_done')
163+
statusCallback('downloading_mods_starting')
164+
await downloadMods(version)
165+
statusCallback('downloading_mods_done')
150166
statusCallback('download_done')
151167
}
152168

@@ -205,7 +221,11 @@ const launch = async (version, account, statusCallback) => {
205221
}
206222
var jvmArguments = [
207223
`-Xmx${memory}M`,
208-
'-Dlog4j2.formatMsgNoLookups=true'
224+
'-Dlog4j2.formatMsgNoLookups=true',
225+
'-Dfabric.addMods=' + version.mods.map(mod => {
226+
const fileName = mod.split('/')[mod.split('/').length - 1]
227+
return join(dir, 'mods', fileName)
228+
}).join(separator)
209229
]
210230
jvmArguments = jvmArguments.concat(meta.arguments.jvm.filter(arg => !arg.rules || arg.rules.every(checkRule)).map(arg => arg.value || arg))
211231
var arguments = []

0 commit comments

Comments
 (0)