|
1 | | -@file:Suppress("UnstableApiUsage", "PropertyName") |
2 | | - |
3 | | -import dev.deftu.gradle.utils.GameSide |
| 1 | +import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
| 2 | +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
4 | 3 |
|
5 | 4 | plugins { |
6 | | - java |
7 | | - kotlin("jvm") |
8 | | - id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders. |
9 | | - id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. |
10 | | - id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. |
11 | | - id("dev.deftu.gradle.tools.bloom") // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files. |
12 | | - id("dev.deftu.gradle.tools.shadow") // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those! |
13 | | - id("dev.deftu.gradle.tools.ducks") // Creates a ducks source set, which allows us to use theoretical classes which may not exist at runtime (such as things which are in other mods). |
14 | | - id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. |
15 | | - id("dev.deftu.gradle.tools.minecraft.releases") // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth. |
16 | | -} |
17 | | - |
18 | | -toolkitLoomHelper { |
19 | | - useOneConfig { |
20 | | - version = "1.0.0-alpha.177" |
21 | | - loaderVersion = "1.1.0-alpha.53" |
22 | | - |
23 | | - usePolyMixin = true |
24 | | - polyMixinVersion = "0.8.4+build.7" |
25 | | - |
26 | | - applyLoaderTweaker = true |
27 | | - |
28 | | - for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { |
29 | | - +module |
30 | | - } |
31 | | - } |
| 5 | + id("net.fabricmc.fabric-loom-remap") version "1.14-SNAPSHOT" |
| 6 | + id("org.jetbrains.kotlin.jvm") version "2.3.0" |
| 7 | + id("dev.deftu.gradle.bloom") version "0.2.0" |
| 8 | +} |
32 | 9 |
|
33 | | - // Turns off the server-side run configs, as we're building a client-sided mod. |
34 | | - disableRunConfigs(GameSide.SERVER) |
| 10 | +val modid = property("mod.id") |
| 11 | +val modname = property("mod.name") |
| 12 | +val modversion = property("mod.version") |
| 13 | +val mcversion = property("minecraft_version") |
35 | 14 |
|
36 | | - // Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes. |
37 | | - if (!mcData.isNeoForge) { |
38 | | - useMixinRefMap(modData.id) |
39 | | - } |
| 15 | +base { |
| 16 | + archivesName.set(property("mod.id") as String) |
| 17 | +} |
| 18 | + |
| 19 | +repositories { |
| 20 | + maven("https://maven.parchmentmc.org") |
| 21 | + maven("https://repo.polyfrost.org/releases") |
| 22 | + maven("https://repo.polyfrost.org/snapshots") |
| 23 | + maven("https://maven.gegy.dev/releases") |
| 24 | +} |
40 | 25 |
|
41 | | - if (mcData.isForge) { |
42 | | - // Configures the Mixin tweaker if we are building for Forge. |
43 | | - useForgeMixin(modData.id) |
| 26 | +loom { |
| 27 | + runConfigs.all { |
| 28 | + ideConfigGenerated(stonecutter.current.isActive) |
| 29 | + runDir = "../../run" // This sets the run folder for all mc versions to the same folder. Remove this line if you want individual run folders. |
44 | 30 | } |
| 31 | + |
| 32 | + runConfigs.remove(runConfigs["server"]) // Removes server run configs |
45 | 33 | } |
46 | 34 |
|
47 | 35 | dependencies { |
48 | | - // Add Fabric Language Kotlin and (Legacy) Fabric API as dependencies (these are both optional but are particularly useful). |
49 | | - if (mcData.isFabric) { |
50 | | - if (mcData.isLegacyFabric) { |
51 | | - // 1.8.9 - 1.13 |
52 | | - modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}") |
53 | | - } else { |
54 | | - // 1.16.5+ |
55 | | - modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}") |
| 36 | + minecraft("com.mojang:minecraft:${property("minecraft_version")}") |
| 37 | + @Suppress("UnstableApiUsage") |
| 38 | + mappings(loom.layered { |
| 39 | + officialMojangMappings() |
| 40 | + optionalProp("${property("parchment_version")}") { |
| 41 | + parchment("org.parchmentmc.data:parchment-${property("minecraft_version")}:$it@zip") |
56 | 42 | } |
| 43 | + optionalProp("${property("yalmm_version")}") { |
| 44 | + mappings("dev.lambdaurora:yalmm-mojbackward:${property("minecraft_version")}+build.$it") |
| 45 | + } |
| 46 | + }) |
| 47 | + modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}") |
| 48 | + modImplementation("org.polyfrost.oneconfig:${property("minecraft_version")}-fabric:1.0.0-alpha.181") |
| 49 | + modImplementation("org.polyfrost.oneconfig:commands:1.0.0-alpha.181") |
| 50 | + modImplementation("org.polyfrost.oneconfig:config:1.0.0-alpha.181") |
| 51 | + modImplementation("org.polyfrost.oneconfig:config-impl:1.0.0-alpha.181") |
| 52 | + modImplementation("org.polyfrost.oneconfig:events:1.0.0-alpha.181") |
| 53 | + modImplementation("org.polyfrost.oneconfig:internal:1.0.0-alpha.181") |
| 54 | + modImplementation("org.polyfrost.oneconfig:ui:1.0.0-alpha.181") |
| 55 | + modImplementation("org.polyfrost.oneconfig:utils:1.0.0-alpha.181") |
| 56 | + modImplementation("org.polyfrost.oneconfig:hud:1.0.0-alpha.181") |
| 57 | + |
| 58 | + modImplementation("net.fabricmc:fabric-language-kotlin:${property("fabric_kotlin_version")}") |
| 59 | +} |
| 60 | + |
| 61 | +bloom { |
| 62 | + replacement("@MOD_ID@", modid!!) |
| 63 | + replacement("@MOD_NAME@", modname!!) |
| 64 | + replacement("@MOD_VERSION@", modversion!!) |
| 65 | +} |
| 66 | + |
| 67 | +tasks.processResources { |
| 68 | + val props = mapOf( |
| 69 | + "mod_id" to modid, |
| 70 | + "mod_name" to modname, |
| 71 | + "mod_version" to modversion, |
| 72 | + "mc_version" to mcversion, |
| 73 | + "loader_version" to providers.gradleProperty("loader_version").get() |
| 74 | + ) |
| 75 | + |
| 76 | + inputs.properties(props) |
| 77 | + |
| 78 | + filesMatching("fabric.mod.json") { |
| 79 | + expand(props) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +tasks.withType<JavaCompile>().configureEach { |
| 84 | + options.release.set(21) |
| 85 | +} |
| 86 | + |
| 87 | +tasks.withType<KotlinCompile>().configureEach { |
| 88 | + compilerOptions.jvmTarget.set(JvmTarget.JVM_21) |
| 89 | +} |
| 90 | + |
| 91 | +java { |
| 92 | + withSourcesJar() |
| 93 | + sourceCompatibility = JavaVersion.VERSION_21 |
| 94 | + targetCompatibility = JavaVersion.VERSION_21 |
| 95 | +} |
| 96 | + |
| 97 | +tasks.jar { |
| 98 | + inputs.property("archivesName", base.archivesName) |
| 99 | + |
| 100 | + from("LICENSE") { |
| 101 | + rename { "${it}_${inputs.properties["archivesName"]}" } |
57 | 102 | } |
58 | 103 | } |
| 104 | + |
| 105 | +fun <T> optionalProp(property: String, block: (String) -> T?): T? = |
| 106 | + findProperty(property)?.toString()?.takeUnless { it.isBlank() }?.let(block) |
0 commit comments