|
| 1 | +import org.apache.commons.lang3.SystemUtils |
| 2 | + |
| 3 | +plugins { |
| 4 | + idea |
| 5 | + java |
| 6 | + id("gg.essential.loom") version "0.10.0.+" |
| 7 | + id("dev.architectury.architectury-pack200") version "0.1.3" |
| 8 | + id("com.github.johnrengelman.shadow") version "8.1.1" |
| 9 | +} |
| 10 | + |
| 11 | +//Constants: |
| 12 | + |
| 13 | +val baseGroup: String by project |
| 14 | +val mcVersion: String by project |
| 15 | +val version: String by project |
| 16 | +val mixinGroup = "$baseGroup.mixin" |
| 17 | +val modid: String by project |
| 18 | +val transformerFile = file("src/main/resources/accesstransformer.cfg") |
| 19 | + |
| 20 | +// Toolchains: |
| 21 | +java { |
| 22 | + toolchain.languageVersion.set(JavaLanguageVersion.of(8)) |
| 23 | +} |
| 24 | + |
| 25 | +// Minecraft configuration: |
| 26 | +loom { |
| 27 | + log4jConfigs.from(file("log4j2.xml")) |
| 28 | + launchConfigs { |
| 29 | + "client" { |
| 30 | + // If you don't want mixins, remove these lines |
| 31 | + property("mixin.debug", "true") |
| 32 | + arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") |
| 33 | + } |
| 34 | + } |
| 35 | + runConfigs { |
| 36 | + "client" { |
| 37 | + if (SystemUtils.IS_OS_MAC_OSX) { |
| 38 | + // This argument causes a crash on macOS |
| 39 | + vmArgs.remove("-XstartOnFirstThread") |
| 40 | + } |
| 41 | + } |
| 42 | + remove(getByName("server")) |
| 43 | + } |
| 44 | + forge { |
| 45 | + pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) |
| 46 | + // If you don't want mixins, remove this lines |
| 47 | + mixinConfig("mixins.$modid.json") |
| 48 | + if (transformerFile.exists()) { |
| 49 | + println("Installing access transformer") |
| 50 | + accessTransformer(transformerFile) |
| 51 | + } |
| 52 | + } |
| 53 | + // If you don't want mixins, remove these lines |
| 54 | + mixin { |
| 55 | + defaultRefmapName.set("mixins.$modid.refmap.json") |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +sourceSets.main { |
| 60 | + output.setResourcesDir(sourceSets.main.flatMap { it.java.classesDirectory }) |
| 61 | +} |
| 62 | + |
| 63 | +// Dependencies: |
| 64 | + |
| 65 | +repositories { |
| 66 | + mavenCentral() |
| 67 | + maven("https://repo.spongepowered.org/maven/") |
| 68 | + // If you don't want to log in with your real minecraft account, remove this line |
| 69 | + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") |
| 70 | +} |
| 71 | + |
| 72 | +val shadowImpl: Configuration by configurations.creating { |
| 73 | + configurations.implementation.get().extendsFrom(this) |
| 74 | +} |
| 75 | + |
| 76 | +dependencies { |
| 77 | + minecraft("com.mojang:minecraft:1.8.9") |
| 78 | + mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") |
| 79 | + forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") |
| 80 | + |
| 81 | + // If you don't want mixins, remove these lines |
| 82 | + shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { |
| 83 | + isTransitive = false |
| 84 | + } |
| 85 | + annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") |
| 86 | + |
| 87 | + // If you don't want to log in with your real minecraft account, remove this line |
| 88 | + runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.2.1") |
| 89 | + |
| 90 | +} |
| 91 | + |
| 92 | +// Tasks: |
| 93 | + |
| 94 | +tasks.withType(JavaCompile::class) { |
| 95 | + options.encoding = "UTF-8" |
| 96 | +} |
| 97 | + |
| 98 | +tasks.withType(org.gradle.jvm.tasks.Jar::class) { |
| 99 | + archiveBaseName.set(modid) |
| 100 | + manifest.attributes.run { |
| 101 | + this["FMLCorePluginContainsFMLMod"] = "true" |
| 102 | + this["ForceLoadAsMod"] = "true" |
| 103 | + |
| 104 | + // If you don't want mixins, remove these lines |
| 105 | + this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker" |
| 106 | + this["MixinConfigs"] = "mixins.$modid.json" |
| 107 | + if (transformerFile.exists()) |
| 108 | + this["FMLAT"] = "${modid}_at.cfg" |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +tasks.processResources { |
| 113 | + inputs.property("version", project.version) |
| 114 | + inputs.property("mcversion", mcVersion) |
| 115 | + inputs.property("modid", modid) |
| 116 | + inputs.property("basePackage", baseGroup) |
| 117 | + |
| 118 | + filesMatching(listOf("mcmod.info", "mixins.$modid.json")) { |
| 119 | + expand(inputs.properties) |
| 120 | + } |
| 121 | + |
| 122 | + rename("accesstransformer.cfg", "META-INF/${modid}_at.cfg") |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") { |
| 127 | + archiveClassifier.set("") |
| 128 | + from(tasks.shadowJar) |
| 129 | + input.set(tasks.shadowJar.get().archiveFile) |
| 130 | +} |
| 131 | + |
| 132 | +tasks.jar { |
| 133 | + archiveClassifier.set("without-deps") |
| 134 | + destinationDirectory.set(layout.buildDirectory.dir("intermediates")) |
| 135 | +} |
| 136 | + |
| 137 | +tasks.shadowJar { |
| 138 | + destinationDirectory.set(layout.buildDirectory.dir("intermediates")) |
| 139 | + archiveClassifier.set("non-obfuscated-with-deps") |
| 140 | + configurations = listOf(shadowImpl) |
| 141 | + doLast { |
| 142 | + configurations.forEach { |
| 143 | + println("Copying dependencies into mod: ${it.files}") |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + // If you want to include other dependencies and shadow them, you can relocate them in here |
| 148 | + fun relocate(name: String) = relocate(name, "$baseGroup.deps.$name") |
| 149 | +} |
| 150 | + |
| 151 | +tasks.assemble.get().dependsOn(tasks.remapJar) |
| 152 | + |
0 commit comments