|
| 1 | +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 2 | +import net.fabricmc.loom.task.RemapJarTask |
| 3 | + |
| 4 | +plugins { |
| 5 | + id("dev.architectury.loom") version "1.9-SNAPSHOT" |
| 6 | + id("com.gradleup.shadow") |
| 7 | +} |
| 8 | + |
| 9 | +val loaderName = project.properties["loaderName"] as? String ?: "fabric" |
| 10 | +val isForge = loaderName.endsWith("forge") |
| 11 | +val isNeo = loaderName.endsWith("neoforge") |
| 12 | +val isFabric = loaderName.endsWith("fabric") |
| 13 | +val mcVersionStr = project.properties["mcVer"] as? String ?: "" |
| 14 | +val (major, minor, patch) = mcVersionStr |
| 15 | + .split(".") |
| 16 | + .toMutableList() |
| 17 | + .apply { if (this.size < 3) this.add("") } |
| 18 | +val mcVersion: Int = "${major}${minor.padStart(2, '0')}${patch.padStart(2, '0')}".toInt() |
| 19 | +// TODO: addingVersion - Add "-" suffix to support snapshots |
| 20 | +val supportedVersionRange: List<String?> = mapOf( |
| 21 | + 11605 to listOf(null, "1.16.5"), |
| 22 | + 11802 to listOf(null, "1.18.2"), |
| 23 | + 11902 to listOf("1.19-", "1.19.2"), |
| 24 | + 11904 to listOf("1.19.3-", "1.19.4"), |
| 25 | + 12001 to listOf("1.20-", "1.20.1"), |
| 26 | + 12002 to listOf("1.20.2-", if (!isNeo) "1.20.4" else "1.20.3"), |
| 27 | + 12004 to listOf(null, "1.20.4"), // for Neo |
| 28 | + 12006 to listOf("1.20.5-", "1.20.6"), |
| 29 | + 12101 to listOf("1.21-", "1.21.1"), |
| 30 | + 12103 to listOf("1.21.2-", null), |
| 31 | +)[mcVersion] ?: listOf() |
| 32 | + |
| 33 | +group = project.properties["maven_group"] as String |
| 34 | + |
| 35 | +loom { |
| 36 | + silentMojangMappingsLicense() |
| 37 | + |
| 38 | + runConfigs { |
| 39 | + named("client") { |
| 40 | + runDir = "../../run/client" |
| 41 | + ideConfigGenerated(true) |
| 42 | + } |
| 43 | + named("server") { |
| 44 | + runDir = "../../run/server" |
| 45 | + ideConfigGenerated(true) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + if (!isFabric && !isNeo) { |
| 50 | + forge { |
| 51 | + mixinConfigs = listOf( |
| 52 | + "cobblegen.mixins.json" |
| 53 | + ) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +val shade: Configuration by configurations.creating { |
| 59 | + configurations.modImplementation.get().extendsFrom(this) |
| 60 | +} |
| 61 | + |
| 62 | +dependencies { |
| 63 | + // TODO(addingVersion): For snapshots |
| 64 | + val mc: Map<Int, String> = mapOf( |
| 65 | + ) |
| 66 | + minecraft("com.mojang:minecraft:${mc[mcVersion] ?: mcVersionStr}") |
| 67 | + |
| 68 | + mappings(loom.officialMojangMappings()) |
| 69 | + |
| 70 | + if (isFabric) { |
| 71 | + if (mcVersion <= 11902 && project.properties["recipe_viewer"] == "rei") |
| 72 | + modImplementation("net.fabricmc:fabric-loader:0.14.14") // I don't get it, REI hate 0.14.21 in 1.19.2 or lower, wtf? |
| 73 | + else if (mcVersion <= 12001) |
| 74 | + modImplementation("net.fabricmc:fabric-loader:0.14.21") |
| 75 | + else |
| 76 | + modImplementation("net.fabricmc:fabric-loader:0.16.7") |
| 77 | + |
| 78 | + // For testing |
| 79 | + if (project.properties["recipe_viewer"] != "none" && mcVersion > 11605) |
| 80 | + // TODO: addingVersion |
| 81 | + modLocalRuntime("net.fabricmc.fabric-api:fabric-api:" + mapOf( |
| 82 | + 11605 to "0.42.0+1.16", |
| 83 | + 11802 to "0.76.0+1.18.2", |
| 84 | + 11902 to "0.76.0+1.19.2", |
| 85 | + 11904 to "0.83.0+1.19.4", |
| 86 | + 12001 to "0.83.1+1.20.1", |
| 87 | + 12002 to "0.89.0+1.20.2", |
| 88 | + 12006 to "0.100.8+1.20.6", |
| 89 | + 12101 to "0.106.0+1.21.1", |
| 90 | + 12103 to "0.106.1+1.21.3", |
| 91 | + )[mcVersion]) |
| 92 | + } else { |
| 93 | + if (!isNeo) { |
| 94 | + "forge"("net.minecraftforge:forge:${mcVersionStr}-" + mapOf( |
| 95 | + 11605 to "36.2.41", |
| 96 | + 11802 to "40.2.9", |
| 97 | + 11902 to "43.2.14", |
| 98 | + 11904 to "45.1.0", |
| 99 | + 12001 to "47.0.3", |
| 100 | + 12002 to "48.0.13", |
| 101 | + // LexForge is no longer supported |
| 102 | + )[mcVersion]) |
| 103 | + } else { |
| 104 | + // TODO: addingVersion |
| 105 | + // snapshot version format: |
| 106 | + // "20.5.0-alpha.${mc[mcVersion]}.+" |
| 107 | + "neoForge"("net.neoforged:neoforge:" + mapOf( |
| 108 | + 12002 to "20.2.86", |
| 109 | + 12004 to "20.4.237", |
| 110 | + 12006 to "20.6.121", |
| 111 | + 12101 to "21.1.72", |
| 112 | + 12103 to "21.3.1-beta", |
| 113 | + )[mcVersion]) |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + shade("blue.endless:jankson:${project.properties["jankson_version"]}") |
| 118 | + if (!isFabric) |
| 119 | + "forgeRuntimeLibrary"("blue.endless:jankson:${project.properties["jankson_version"]}") |
| 120 | + |
| 121 | + val manifoldVersion = project.properties["manifold_version"] as? String ?: "" |
| 122 | + shade("systems.manifold:manifold-ext-rt:${manifoldVersion}") |
| 123 | + if (!isFabric) |
| 124 | + "forgeRuntimeLibrary"("systems.manifold:manifold-ext-rt:${manifoldVersion}") |
| 125 | + annotationProcessor("systems.manifold:manifold-ext:${manifoldVersion}") |
| 126 | + testAnnotationProcessor("systems.manifold:manifold-ext:${manifoldVersion}") |
| 127 | + annotationProcessor("systems.manifold:manifold-preprocessor:${manifoldVersion}") |
| 128 | + testAnnotationProcessor("systems.manifold:manifold-preprocessor:${manifoldVersion}") |
| 129 | + |
| 130 | + // Don't wanna deal with these atm |
| 131 | + if (mcVersion > 11605) { |
| 132 | + // These act like a dummy, technically only here to provide their modules/packages |
| 133 | + if (isFabric) { |
| 134 | + modCompileOnly("io.github.fabricators_of_create:Porting-Lib:${project.properties["port_lib_version_1_18_2"]}") |
| 135 | + modCompileOnly("com.simibubi.create:create-fabric-${project.properties["minecraft_version_1_18_2"]}:${project.properties["create_version_1_18_2"]}") |
| 136 | + } else { |
| 137 | + modCompileOnly("com.simibubi.create:create-1.18.2:0.5.1.e-318:slim") { isTransitive = false } |
| 138 | + } |
| 139 | + |
| 140 | + // <- EMI |
| 141 | + if (mcVersion <= 11802 && isFabric) { |
| 142 | + modCompileOnly("dev.emi:emi:0.7.3+${mcVersionStr}:api") |
| 143 | + if (project.properties["recipe_viewer"] == "emi") |
| 144 | + modLocalRuntime("dev.emi:emi:0.7.3+${mcVersionStr}") |
| 145 | + } else { |
| 146 | + // TODO: addingVersion - EMI. They didn't break API on MC version upgrade so mismatch should be fine |
| 147 | + val suffix = mapOf( |
| 148 | + 11902 to "1.19.2", |
| 149 | + 11904 to "1.19.4", |
| 150 | + 12001 to "1.20.1", |
| 151 | + 12002 to "1.20.2", |
| 152 | + 12004 to "1.20.2", // For Neo, the same 1.20.2 |
| 153 | + 12006 to "1.20.6", |
| 154 | + 12101 to "1.21.1", |
| 155 | + 12103 to "1.21.1", // FIXME: . |
| 156 | + ) |
| 157 | + val emiVersion = "1.1.18+${suffix[mcVersion] ?: "1.20.2"}" |
| 158 | + // EMI support multiple platform since 1.0.0 |
| 159 | + // EMI seems to also skip 1.19 and 1.19.1 |
| 160 | + modCompileOnly("dev.emi:emi-${if (isFabric) "fabric" else (if (mcVersion >= 12006) "neoforge" else "forge")}:$emiVersion:api") |
| 161 | + if (project.properties["recipe_viewer"] == "emi" && suffix[mcVersion] != null) |
| 162 | + modLocalRuntime("dev.emi:emi-${if (isFabric) "fabric" else (if (mcVersion >= 12006) "neoforge" else "forge")}:$emiVersion") |
| 163 | + } |
| 164 | + // EMI -> |
| 165 | + |
| 166 | + // <- REI |
| 167 | + // TODO: addingVersion - REI |
| 168 | + val reiVersions = mapOf( |
| 169 | + 11802 to "8.3.618", |
| 170 | + 11902 to "9.1.619", |
| 171 | + 11904 to "11.0.621", |
| 172 | + 12001 to "12.0.625", |
| 173 | + 12002 to "13.0.685", |
| 174 | + 12004 to "13.0.685", // for Neo |
| 175 | + 12006 to "15.0.787", |
| 176 | + 12101 to "16.0.788", |
| 177 | + 12103 to "17.0.789", |
| 178 | + ) |
| 179 | + val reiFallback = "17.0.789" |
| 180 | + // Use the full package instead of 'api-' for (neo)forge, since the 'api-' didn't include @REIPlugin* |
| 181 | + modCompileOnly("me.shedaniel:RoughlyEnoughItems-${if (isFabric) "api-fabric" else if (!isNeo) "forge" else "neoforge"}:${reiVersions[mcVersion] ?: reiFallback}") |
| 182 | + if (mcVersion >= 12002) { // FIXME: Not sure why it's not included |
| 183 | + modCompileOnly("me.shedaniel.cloth:basic-math:0.6.1") |
| 184 | + modCompileOnly("dev.architectury:architectury:11.1.13") |
| 185 | + } |
| 186 | + if (project.properties["recipe_viewer"] == "rei" && reiVersions[mcVersion] != null) { |
| 187 | + if (mcVersion == 11902) // REI's stupid dep bug |
| 188 | + modLocalRuntime("dev.architectury:architectury-fabric:6.5.77") |
| 189 | + modLocalRuntime("me.shedaniel:RoughlyEnoughItems-${if (isFabric) "fabric" else "forge"}:${reiVersions[mcVersion]}") |
| 190 | + } |
| 191 | + // REI -> |
| 192 | + |
| 193 | + // <- JEI |
| 194 | + // TODO: addingVersion - JEI |
| 195 | + val jeiVersions = mapOf( |
| 196 | + 11802 to "10.2.1.1004", |
| 197 | + 11902 to "11.6.0.1015", |
| 198 | + 11904 to "13.1.0.13", |
| 199 | + 12001 to "15.0.0.12", |
| 200 | + 12002 to "16.0.0.28", |
| 201 | + 12004 to "16.0.0.28", // for Neo |
| 202 | + 12006 to "18.0.0.62", |
| 203 | + 12101 to "19.21.0.246", |
| 204 | + 12103 to null, |
| 205 | + ) |
| 206 | + val jeiVersion = jeiVersions[mcVersion] |
| 207 | + // <- fallback - should be the latest version |
| 208 | + val fallbackJeiVer = "19.21.0.246" |
| 209 | + val fallbackJeiMcVer = "1.21.1" |
| 210 | + // fallback -> |
| 211 | + val jeiMc = mapOf( |
| 212 | + 12004 to "1.20.2", // for Neo |
| 213 | + 12103 to fallbackJeiMcVer, |
| 214 | + ) |
| 215 | + modCompileOnly("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-common-api:${jeiVersion ?: fallbackJeiVer}") |
| 216 | + modCompileOnly("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-${if (isFabric) "fabric" else "forge"}-api:${jeiVersion ?: fallbackJeiVer}") |
| 217 | + if (project.properties["recipe_viewer"] == "jei" && jeiVersion != null) |
| 218 | + modLocalRuntime("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-${if (isFabric) "fabric" else "forge"}:${jeiVersion}") |
| 219 | + // JEI -> |
| 220 | + |
| 221 | + /* FIXME: Broken, somehow |
| 222 | + if (mcVersion == 11802 && isFabric) { |
| 223 | + modLocalRuntime("com.tterrag.registrate_fabric:Registrate:MC1.18.2-1.1.7") |
| 224 | + modLocalRuntime("io.github.fabricators_of_create:Porting-Lib:${project.port_lib_version_1_18_2}") |
| 225 | + modLocalRuntime("com.simibubi.create:create-fabric-${project.minecraft_version_1_18_2}:${project.create_version_1_18_2}") |
| 226 | + } |
| 227 | + */ |
| 228 | + } else { |
| 229 | + // slf4j is not included by MC in 1.16.5 |
| 230 | + shade("org.slf4j:slf4j-api:1.7.36") |
| 231 | + shade("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") |
| 232 | + if (!isFabric) { |
| 233 | + "forgeRuntimeLibrary"("org.slf4j:slf4j-api:1.7.36") |
| 234 | + "forgeRuntimeLibrary"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") |
| 235 | + } |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +val shadowJar by tasks.getting(ShadowJar::class) { |
| 240 | + isZip64 = true |
| 241 | + relocate("blue.endless.jankson", "io.github.null2264.shadowed.jankson") |
| 242 | + if (mcVersion <= 11605) { |
| 243 | + relocate("org.slf4j", "io.github.null2264.shadowed.slf4j") |
| 244 | + relocate("org.apache.logging", "io.github.null2264.shadowed.log4j") |
| 245 | + } |
| 246 | + relocate("manifold", "io.github.null2264.shadowed.manifold") |
| 247 | + if (isFabric) { |
| 248 | + exclude("META-INF/mods.toml") |
| 249 | + exclude("META-INF/neoforge.mods.toml") |
| 250 | + } else if (isForge) { |
| 251 | + exclude("fabric.mod.json") |
| 252 | + exclude(if (isNeo && mcVersion >= 12006) "META-INF/mods.toml" else "META-INF/neoforge.mods.toml") |
| 253 | + } |
| 254 | + exclude("architectury.common.json") |
| 255 | + |
| 256 | + configurations = listOf(shade) |
| 257 | + archiveClassifier.set("dev-shade") |
| 258 | +} |
| 259 | + |
| 260 | +artifacts.add("archives", shadowJar) |
| 261 | + |
| 262 | +val remapJar by tasks.getting(RemapJarTask::class) { |
| 263 | + dependsOn(shadowJar) |
| 264 | + inputFile.set(shadowJar.archiveFile) |
| 265 | +} |
| 266 | + |
| 267 | +// FIXME: Can no longer preprocess resources |
| 268 | +val processResources by tasks.getting(ProcessResources::class) { |
| 269 | + val metadataVersion = "${project.properties["mod_version"]}-${project.properties["version_stage"]}" |
| 270 | + val metadataMCVersion = |
| 271 | + if (supportedVersionRange[0] != null) ( |
| 272 | + (if (isFabric) ">=" else "[") + |
| 273 | + supportedVersionRange[0] + |
| 274 | + (if (supportedVersionRange[1] == null) |
| 275 | + (if (isFabric) "" else ",)") |
| 276 | + else ((if (isFabric) " <=" else ",") + supportedVersionRange[1] + (if (isFabric) "" else "]"))) |
| 277 | + ) else (if (isFabric) supportedVersionRange[1] else "[${supportedVersionRange[1]}]") |
| 278 | + val properties = mapOf( |
| 279 | + "version" to metadataVersion, |
| 280 | + "mcversion" to metadataMCVersion, |
| 281 | + "forge" to (if (isNeo) "neoforge" else "forge"), |
| 282 | + ) |
| 283 | + inputs.properties(properties) |
| 284 | + filteringCharset = Charsets.UTF_8.name() |
| 285 | + |
| 286 | + val metadataFilename = |
| 287 | + if (isFabric) { |
| 288 | + "fabric.mod.json" |
| 289 | + } else { |
| 290 | + if (isNeo && mcVersion >= 12006) "META-INF/neoforge.mods.toml" else "META-INF/mods.toml" |
| 291 | + } |
| 292 | + |
| 293 | + filesMatching(metadataFilename) { |
| 294 | + filter { line -> if (line.trim().startsWith("//")) "" else line } // strip comments |
| 295 | + expand(properties) |
| 296 | + } |
| 297 | +} |
| 298 | + |
| 299 | +val targetJavaVersion = if (mcVersion >= 12006) 21 else (if (mcVersion >= 11700) 17 else 8) |
| 300 | +tasks.withType<JavaCompile>().configureEach { |
| 301 | + // ensure that the encoding is set to UTF-8, no matter what the system default is |
| 302 | + // this fixes some edge cases with special characters not displaying correctly |
| 303 | + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html |
| 304 | + // If Javadoc is generated, this must be specified in that task too. |
| 305 | + options.encoding = "UTF-8" |
| 306 | + if (targetJavaVersion > 8) { |
| 307 | + options.release = targetJavaVersion |
| 308 | + } |
| 309 | +} |
| 310 | + |
| 311 | +java { |
| 312 | + val javaVersion = JavaVersion.toVersion(targetJavaVersion) |
| 313 | + if (JavaVersion.current() != javaVersion) { |
| 314 | + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) |
| 315 | + } |
| 316 | + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task |
| 317 | + // if it is present. |
| 318 | + // If you remove this line, sources will not be generated. |
| 319 | + withSourcesJar() |
| 320 | +} |
| 321 | + |
| 322 | +tasks.jar { |
| 323 | + from("LICENSE") { |
| 324 | + rename { "${it}_${base.archivesName.get()}" } |
| 325 | + } |
| 326 | +} |
| 327 | + |
| 328 | +if (JavaVersion.current() != JavaVersion.VERSION_1_8 && |
| 329 | + sourceSets.main.get().allJava.files.any {it.name == "module-info.java"}) { |
| 330 | + tasks.withType<JavaCompile>() { |
| 331 | + // if you DO define a module-info.java file: |
| 332 | + options.compilerArgs.addAll(listOf("-Xplugin:Manifold", "--module-path", classpath.asPath)) |
| 333 | + } |
| 334 | +} else { |
| 335 | + tasks.withType<JavaCompile>() { |
| 336 | + // If you DO NOT define a module-info.java file: |
| 337 | + options.compilerArgs.addAll(listOf("-Xplugin:Manifold")) |
| 338 | + } |
| 339 | +} |
0 commit comments