Skip to content

Instantly share code, notes, and snippets.

@nea89o
Created January 20, 2023 06:45
Show Gist options
  • Save nea89o/d8c029f2a1443cca77b5cf41c7cdfb8d to your computer and use it in GitHub Desktop.
Save nea89o/d8c029f2a1443cca77b5cf41c7cdfb8d to your computer and use it in GitHub Desktop.

How to use

Copy the other file in this gist into your $GRADLE_USER_HOME/init.d (usually this is: ~/.gradle/init.d/installMinecraft.init.gradle.kts) and replace the installation path with the correct path. From now on, every mod project that uses forgegradle or loom (and a roughly standard project layout) should have the task ./gradlew installToMinecraft available (also available in your IDE), which will install that jar. in projects with multiple subprojects, you might want to use a fully qualified task path: Either ./gradlew :installToMinecraft for installing the root project, or ./gradlew :forge-1.8.9:installToMinecraft to install a subproject (for example for multi-version projects).

Caveats

This does not parse the modid (since the format of mod metadata varies a lot, so archiveBaseName has to be set correctly (or the old file won't be deleted)

allprojects {
this.afterEvaluate {
if (!listOf(
"gg.essential.loom",
"dev.architectury.loom",
"fabric-loom",
"net.minecraftforge.gradle.tweaker-client",
"net.minecraftforge.gradle.forge",
).any { plugins.hasPlugin(it) }
) {
return@afterEvaluate
}
val toInstall = listOf("remapJar", "shadowJar", "jar").mapNotNull {
tasks.findByName(it)
}.filterIsInstance<org.gradle.jvm.tasks.Jar>().firstOrNull()
// Replace this with your own mod folder
val targetDirectory = File("/home/nea/.local/share/PrismLauncher/instances/Skyblock/.minecraft/mods")
if (toInstall != null) {
tasks.create("installToMinecraft") {
dependsOn(toInstall)
doLast {
val modJar = toInstall.archiveFile.get().asFile
targetDirectory.listFiles()
.filter {
it.name.startsWith(toInstall.archiveBaseName.get())
}
.forEach {
it.delete()
}
modJar.copyTo(targetDirectory.resolve(modJar.name))
println("Installed $modJar to $targetDirectory")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment