11@file:Suppress(" UnstableApiUsage" , " PropertyName" )
22
3- import org.polyfrost.gradle.util.noServerRunConfigs
4- import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
3+ import dev.deftu.gradle.utils.GameSide
54
6- // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
7- // which we use to prepare the environment.
85plugins {
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" )
176 java
7+ kotlin(" jvm" )
8+ id(" dev.deftu.gradle.multiversion" )
9+ id(" dev.deftu.gradle.tools" )
10+ id(" dev.deftu.gradle.tools.resources" )
11+ id(" dev.deftu.gradle.tools.bloom" )
12+ id(" dev.deftu.gradle.tools.shadow" )
13+ id(" dev.deftu.gradle.tools.minecraft.loom" )
1814}
1915
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)
16+ // Sets up the variables for when we preprocess to other Minecraft versions.
17+ preprocess {
18+ vars.put(" MODERN" , if (mcData.version.minor >= 16 ) 1 else 0 )
3119}
3220
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"
21+ toolkitLoomHelper {
22+ // Adds OneConfig to our project
23+ useOneConfig(mcData.version, mcData.loader, " commands" , " config-impl" , " events" , " hud" , " internal" , " ui" )
24+ useDevAuth()
3825
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 {
4726 // Removes the server configs from IntelliJ IDEA, leaving only client runs.
48- noServerRunConfigs()
27+ // If you're developing a server-side mod, you can remove this line.
28+ disableRunConfigs(GameSide .SERVER )
4929
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" , " org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker" )
55- programArgs(" --tweakClass" , " org.spongepowered.asm.launch.MixinTweaker" )
56- property(" mixin.debug.export" , " true" ) // Outputs all mixin changes to `versions/{mcVersion}/run/.mixin.out/class`
57- }
58- }
30+ // Sets up our Mixin refmap naming
31+ if (! mcData.isNeoForge) {
32+ useMixinRefMap(modData.id)
5933 }
60- // Configures the mixins if we are building for forge
61- if (project.platform.isForge) {
62- forge {
63- mixinConfig(" mixins.${mod_id} .json" )
64- }
65- }
66- // Configures the name of the mixin "refmap"
67- mixin.defaultRefmapName.set(" mixins.${mod_id} .refmap.json" )
68- }
6934
70- // Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately.
71- val shade : Configuration by configurations.creating {
72- configurations.implementation.get().extendsFrom( this )
73- }
74- val modShade : Configuration by configurations.creating {
75- configurations.modImplementation.get().extendsFrom( this )
35+ // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org)
36+ if (mcData.isLegacyForge) {
37+ useCoreMod( " org.polyfrost.craftycrashes.plugin.LegacyCraftyCrashesLoadingPlugin " )
38+ useTweaker( " org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker " , GameSide . CLIENT )
39+ useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
40+ }
7641}
7742
7843// Configures the output directory for when building from the `src/resources` directory.
7944sourceSets {
8045 val dummy by creating
8146 main {
47+ dummy.compileClasspath + = compileClasspath
8248 compileClasspath + = dummy.output
8349 output.setResourcesDir(java.classesDirectory)
8450 }
@@ -87,116 +53,12 @@ sourceSets {
8753// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
8854repositories {
8955 maven(" https://repo.polyfrost.org/releases" )
90- maven(" https://repo.polyfrost.org/snapshots" )
9156}
9257
9358// Configures the libraries/dependencies for your mod.
9459dependencies {
95- // Adds the OneConfig library, so we can develop with it.
96- val oneconfig = " 1.0.0-alpha.19"
97- implementation(" org.polyfrost.oneconfig:config-impl:$oneconfig " )
98- implementation(" org.polyfrost.oneconfig:commands:$oneconfig " )
99- implementation(" org.polyfrost.oneconfig:events:$oneconfig " )
100- implementation(" org.polyfrost.oneconfig:ui:$oneconfig " )
101- implementation(" org.polyfrost.oneconfig:internal:$oneconfig " )
102- modImplementation(" org.polyfrost.oneconfig:$platform :$oneconfig " )
103-
104- // Adds DevAuth, which we can use to log in to Minecraft in development.
105- modRuntimeOnly(" me.djtheredstoner:DevAuth-${if (platform.isFabric) " fabric" else if (platform.isLegacyForge) " forge-legacy" else " forge-latest" } :1.2.0" )
106-
107- // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier, as well as mixin 0.7.11
108- if (platform.isLegacyForge) {
60+ // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
61+ if (mcData.isLegacyForge) {
10962 compileOnly(" org.spongepowered:mixin:0.7.11-SNAPSHOT" )
110- // shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+")
111- }
112- }
113-
114- tasks {
115- // Processes the `src/resources/mcmod.info`, `fabric.mod.json`, or `mixins.${mod_id}.json` and replaces
116- // the mod id, name and version with the ones in `gradle.properties`
117- processResources {
118- inputs.property(" id" , mod_id)
119- inputs.property(" name" , mod_name)
120- val java = if (project.platform.mcMinor >= 18 ) {
121- 17 // If we are playing on version 1.18, set the java version to 17
122- } else {
123- // Else if we are playing on version 1.17, use java 16.
124- if (project.platform.mcMinor == 17 )
125- 16
126- else
127- 8 // For all previous versions, we **need** java 8 (for Forge support).
128- }
129- val compatLevel = " JAVA_${java} "
130- inputs.property(" java" , java)
131- inputs.property(" java_level" , compatLevel)
132- inputs.property(" version" , mod_version)
133- inputs.property(" mcVersionStr" , project.platform.mcVersionStr)
134- filesMatching(listOf (" mcmod.info" , " mixins.${mod_id} .json" , " mods.toml" )) {
135- expand(
136- mapOf (
137- " id" to mod_id,
138- " name" to mod_name,
139- " java" to java,
140- " java_level" to compatLevel,
141- " version" to mod_version,
142- " mcVersionStr" to project.platform.mcVersionStr
143- )
144- )
145- }
146- filesMatching(" fabric.mod.json" ) {
147- expand(
148- mapOf (
149- " id" to mod_id,
150- " name" to mod_name,
151- " java" to java,
152- " java_level" to compatLevel,
153- " version" to mod_version,
154- " mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(" ." ) + " .x"
155- )
156- )
157- }
158- }
159-
160- // Configures the resources to include if we are building for forge or fabric.
161- withType(Jar ::class .java) {
162- if (project.platform.isFabric) {
163- exclude(" mcmod.info" , " mods.toml" )
164- } else {
165- exclude(" fabric.mod.json" )
166- if (project.platform.isLegacyForge) {
167- exclude(" mods.toml" )
168- } else {
169- exclude(" mcmod.info" )
170- }
171- }
172- }
173-
174- // Configures our shadow/shade configuration, so we can
175- // include some dependencies within our mod jar file.
176- named<ShadowJar >(" shadowJar" ) {
177- archiveClassifier.set(" dev" )
178- configurations = listOf (shade, modShade)
179- duplicatesStrategy = DuplicatesStrategy .EXCLUDE
180- }
181-
182- remapJar {
183- inputFile.set(shadowJar.get().archiveFile)
184- archiveClassifier.set(" " )
185- }
186-
187- jar {
188- // Sets the jar manifest attributes.
189- if (platform.isLegacyForge) {
190- manifest.attributes + = mapOf (
191- " ModSide" to " CLIENT" , // We aren't developing a server-side mod
192- " ForceLoadAsMod" to true , // We want to load this jar as a mod, so we force Forge to do so.
193- " TweakOrder" to " 0" , // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
194- " MixinConfigs" to " mixins.${mod_id} .json" , // We want to use our mixin configuration, so we specify it here.
195- " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
196- )
197- }
198- dependsOn(shadowJar)
199- archiveClassifier.set(" " )
200- enabled = false
20163 }
20264}
0 commit comments