buildscript { repositories { mavenCentral() maven { url = "https://maven.minecraftforge.net/" } } dependencies { classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "5.1.+" } } apply plugin: "java" apply plugin: "net.minecraftforge.gradle" java.toolchain.languageVersion = JavaLanguageVersion.of(8) compileJava { sourceCompatibility = "8" targetCompatibility = "8" } repositories { maven { url = "https://maven.minecraftforge.net/" } mavenCentral() } configurations { sidePatch { transitive = false } } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" // Pre-BUKKIT Side enum used to patch the mapped Forge jar for runs. sidePatch "net.minecraftforge:mergetool:0.2.3.3" } minecraft { mappings channel: mappings_channel, version: mappings_version runs { "client" { workingDirectory file("./run") mods { "${project.name}" { source sourceSets.main } } } "server" { workingDirectory file("./run/server") mods { "${project.name}" { source sourceSets.main } } } } } processResources { inputs.property "version", project.version inputs.property "mcversion", minecraft_version filesMatching("mcmod.info") { expand "version": project.version, "mcversion": minecraft_version } } // Forge 1.12 expects resources next to classes on the classpath. sourceSets.all { it.output.resourcesDir = it.output.classesDirs.getFiles().iterator().next() } // FG5 injects mergetool's Side.BUKKIT into the mapped Forge jar, which makes // NetworkRegistry.newChannel NPE. Patch a project-local copy for run tasks. // https://github.com/MinecraftForge/ForgeGradle/issues/748 def patchedForgeJar = file("${buildDir}/forge-patched/forge-mapped-no-bukkit.jar") tasks.register("patchForgeSide") { dependsOn configurations.minecraft inputs.files(configurations.minecraft, configurations.sidePatch) outputs.file(patchedForgeJar) doLast { def forgeJar = configurations.minecraft.files.find { it.name.contains("forge-") && it.name.contains("_mapped_") && it.name.endsWith(".jar") } if (forgeJar == null) { throw new GradleException("Could not find mapped Forge jar on the minecraft configuration") } def sideSource = configurations.sidePatch.singleFile def work = file("${buildDir}/forge-patched/work") delete(work) delete(patchedForgeJar) work.mkdirs() patchedForgeJar.parentFile.mkdirs() ant.copy(file: forgeJar, tofile: patchedForgeJar, overwrite: true) ant.unzip(src: sideSource, dest: work) { patternset { include(name: "net/minecraftforge/fml/relauncher/Side.class") } } // ant.jar update=true does not reliably replace entries; delete then add. exec { commandLine "zip", "-d", patchedForgeJar.absolutePath, "net/minecraftforge/fml/relauncher/Side.class" ignoreExitValue = true } exec { workingDir work commandLine "zip", "-u", patchedForgeJar.absolutePath, "net/minecraftforge/fml/relauncher/Side.class" } } } tasks.configureEach { task -> if (task.name == "runClient" || task.name == "runServer") { task.dependsOn("patchForgeSide") task.doFirst { def original = classpath.files.find { it.name.contains("forge-") && it.name.contains("_mapped_") && it.name.endsWith(".jar") } if (original == null) { throw new GradleException("Could not find mapped Forge jar on ${task.name} classpath") } classpath = files(classpath.files.collect { it == original ? patchedForgeJar : it }) } } }