|
1 | 1 | @file:Suppress("UnstableApiUsage", "PropertyName") |
2 | 2 |
|
3 | | -import org.polyfrost.gradle.util.noServerRunConfigs |
4 | | -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 3 | +import dev.deftu.gradle.utils.GameSide |
| 4 | +import dev.deftu.gradle.utils.MinecraftVersion |
5 | 5 |
|
6 | | -// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit |
7 | | -// which we use to prepare the environment. |
8 | 6 | plugins { |
9 | | - kotlin("jvm") |
10 | | - id("org.polyfrost.multi-version") |
11 | | - id("org.polyfrost.defaults.repo") |
12 | | - id("org.polyfrost.defaults.java") |
13 | | - id("org.polyfrost.defaults.loom") |
14 | | - id("com.github.johnrengelman.shadow") |
15 | | - id("net.kyori.blossom") version "1.3.2" |
16 | | - id("signing") |
17 | 7 | java |
| 8 | + kotlin("jvm") |
| 9 | + id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders. |
| 10 | + id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. |
| 11 | + id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. |
| 12 | + 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. |
| 13 | + 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! |
| 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. |
18 | 16 | } |
19 | 17 |
|
20 | | -// Gets the mod name, version and id from the `gradle.properties` file. |
21 | | -val mod_name: String by project |
22 | | -val mod_version: String by project |
23 | | -val mod_id: String by project |
24 | | -val mod_archives_name: String by project |
25 | | - |
26 | | -// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`. |
27 | | -blossom { |
28 | | - replaceToken("@VER@", mod_version) |
29 | | - replaceToken("@NAME@", mod_name) |
30 | | - replaceToken("@ID@", mod_id) |
31 | | -} |
32 | | - |
33 | | -// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver! |
34 | | -version = mod_version |
35 | | -// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username. |
36 | | -// e.g. com.github.<your username> or com.<your domain> |
37 | | -group = "org.polyfrost" |
38 | | - |
39 | | -// Sets the name of the output jar (the one you put in your mods folder and send to other people) |
40 | | -// It outputs all versions of the mod into the `versions/{mcVersion}/build` directory. |
41 | | -base { |
42 | | - archivesName.set("$mod_archives_name-$platform") |
43 | | -} |
44 | | - |
45 | | -// Configures Polyfrost Loom, our plugin fork to easily set up the programming environment. |
46 | | -loom { |
47 | | - // Removes the server configs from IntelliJ IDEA, leaving only client runs. |
48 | | - noServerRunConfigs() |
49 | | - |
50 | | - // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) |
51 | | - if (project.platform.isLegacyForge) { |
52 | | - runConfigs { |
53 | | - "client" { |
54 | | - programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") |
55 | | - property("mixin.debug.export", "true") // Outputs all mixin changes to `versions/{mcVersion}/run/.mixin.out/class` |
56 | | - } |
57 | | - } |
58 | | - } |
59 | | - // Configures the mixins if we are building for forge |
60 | | - if (project.platform.isForge) { |
61 | | - forge { |
62 | | - mixinConfig("mixins.${mod_id}.json") |
63 | | - } |
64 | | - } |
65 | | - // Configures the name of the mixin "refmap" |
66 | | - mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json") |
67 | | -} |
68 | | - |
69 | | -// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately. |
70 | | -val shade: Configuration by configurations.creating { |
71 | | - configurations.implementation.get().extendsFrom(this) |
72 | | -} |
73 | | -val modShade: Configuration by configurations.creating { |
74 | | - configurations.modImplementation.get().extendsFrom(this) |
75 | | -} |
76 | | - |
77 | | -// Configures the output directory for when building from the `src/resources` directory. |
78 | | -sourceSets { |
79 | | - main { |
80 | | - output.setResourcesDir(java.classesDirectory) |
81 | | - } |
82 | | -} |
83 | | - |
84 | | -// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. |
85 | | -repositories { |
86 | | - maven("https://repo.polyfrost.org/releases") |
87 | | -} |
| 18 | +toolkitLoomHelper { |
| 19 | + useOneConfig { |
| 20 | + version = "1.0.0-alpha.47" |
| 21 | + loaderVersion = "1.1.0-alpha.34" |
88 | 22 |
|
89 | | -// Configures the libraries/dependencies for your mod. |
90 | | -dependencies { |
91 | | - // Adds the OneConfig library, so we can develop with it. |
92 | | - modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+") |
| 23 | + usePolyMixin = true |
| 24 | + polyMixinVersion = "0.8.4+build.2" |
93 | 25 |
|
94 | | - // Adds DevAuth, which we can use to log in to Minecraft in development. |
95 | | - modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0") |
| 26 | + applyLoaderTweaker = true |
96 | 27 |
|
97 | | - // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier, as well as mixin 0.7.11 |
98 | | - if (platform.isLegacyForge) { |
99 | | - compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") |
100 | | - shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17") |
101 | | - } |
102 | | -} |
103 | | - |
104 | | -tasks { |
105 | | - // Processes the `src/resources/mcmod.info`, `fabric.mod.json`, or `mixins.${mod_id}.json` and replaces |
106 | | - // the mod id, name and version with the ones in `gradle.properties` |
107 | | - processResources { |
108 | | - inputs.property("id", mod_id) |
109 | | - inputs.property("name", mod_name) |
110 | | - val java = if (project.platform.mcMinor >= 18) { |
111 | | - 17 // If we are playing on version 1.18, set the java version to 17 |
112 | | - } else { |
113 | | - // Else if we are playing on version 1.17, use java 16. |
114 | | - if (project.platform.mcMinor == 17) |
115 | | - 16 |
116 | | - else |
117 | | - 8 // For all previous versions, we **need** java 8 (for Forge support). |
118 | | - } |
119 | | - val compatLevel = "JAVA_${java}" |
120 | | - inputs.property("java", java) |
121 | | - inputs.property("java_level", compatLevel) |
122 | | - inputs.property("version", mod_version) |
123 | | - inputs.property("mcVersionStr", project.platform.mcVersionStr) |
124 | | - filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) { |
125 | | - expand( |
126 | | - mapOf( |
127 | | - "id" to mod_id, |
128 | | - "name" to mod_name, |
129 | | - "java" to java, |
130 | | - "java_level" to compatLevel, |
131 | | - "version" to mod_version, |
132 | | - "mcVersionStr" to project.platform.mcVersionStr |
133 | | - ) |
134 | | - ) |
135 | | - } |
136 | | - filesMatching("fabric.mod.json") { |
137 | | - expand( |
138 | | - mapOf( |
139 | | - "id" to mod_id, |
140 | | - "name" to mod_name, |
141 | | - "java" to java, |
142 | | - "java_level" to compatLevel, |
143 | | - "version" to mod_version, |
144 | | - "mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x" |
145 | | - ) |
146 | | - ) |
| 28 | + for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { |
| 29 | + +module |
147 | 30 | } |
148 | 31 | } |
149 | 32 |
|
150 | | - // Configures the resources to include if we are building for forge or fabric. |
151 | | - withType(Jar::class.java) { |
152 | | - if (project.platform.isFabric) { |
153 | | - exclude("mcmod.info", "mods.toml") |
154 | | - } else { |
155 | | - exclude("fabric.mod.json") |
156 | | - if (project.platform.isLegacyForge) { |
157 | | - exclude("mods.toml") |
158 | | - } else { |
159 | | - exclude("mcmod.info") |
160 | | - } |
161 | | - } |
162 | | - } |
| 33 | + // Turns off the server-side run configs, as we're building a client-sided mod. |
| 34 | + disableRunConfigs(GameSide.SERVER) |
163 | 35 |
|
164 | | - // Configures our shadow/shade configuration, so we can |
165 | | - // include some dependencies within our mod jar file. |
166 | | - named<ShadowJar>("shadowJar") { |
167 | | - archiveClassifier.set("dev") |
168 | | - configurations = listOf(shade, modShade) |
169 | | - duplicatesStrategy = DuplicatesStrategy.EXCLUDE |
| 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) |
170 | 39 | } |
171 | 40 |
|
172 | | - remapJar { |
173 | | - inputFile.set(shadowJar.get().archiveFile) |
174 | | - archiveClassifier.set("") |
| 41 | + if (mcData.isForge) { |
| 42 | + // Configures the Mixin tweaker if we are building for Forge. |
| 43 | + useForgeMixin(modData.id) |
175 | 44 | } |
176 | 45 |
|
177 | | - jar { |
178 | | - // Sets the jar manifest attributes. |
179 | | - if (platform.isLegacyForge) { |
180 | | - manifest.attributes += mapOf( |
181 | | - "ModSide" to "CLIENT", // We aren't developing a server-side mod |
182 | | - "ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so. |
183 | | - "TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible. |
184 | | - "MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. |
185 | | - "TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper. |
186 | | - ) |
187 | | - } |
188 | | - dependsOn(shadowJar) |
189 | | - archiveClassifier.set("") |
190 | | - enabled = false |
| 46 | + // Sets up the KotlinForForge library for Forge 1.16.5+ and NeoForge. |
| 47 | + if (mcData.isForgeLike && mcData.version >= MinecraftVersion.VERSION_1_16_5) { |
| 48 | + useKotlinForForge() |
191 | 49 | } |
192 | 50 | } |
0 commit comments