Add constants to buildscript to allow easier setup

Refactor to create constants for common values to be replaced

Signed-off-by: Walker Selby <git@walkerselby.com>
This commit is contained in:
Walker Selby 2023-05-12 11:32:40 -07:00 committed by nea
parent cc5c1a8d1c
commit 7e8fa83e5a
No known key found for this signature in database
GPG key ID: AA563E93EB628D91
4 changed files with 51 additions and 26 deletions

View file

@ -2,10 +2,14 @@
**For other templates, do check out the [other branches of this repository](https://github.com/romangraef/Forge1.8.9Template/branches/all)** **For other templates, do check out the [other branches of this repository](https://github.com/romangraef/Forge1.8.9Template/branches/all)**
To get started, clone this repository and replace all references to `examplemod` or `com.example` with your own names. To get started, clone this repository.
In `build.gradle.kts`, replace the values of `baseGroup` and `group` with your own names.
In `settings.gradle.kts` change `rootProject.name` to your desired mod id.
The `com.example` package needs to be renamed to match the value of `baseGroup`.
If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from
the `build.gradle.kts`, delete the `mixins.examplemod.json` and the `com.example.mixin` package. the `build.gradle.kts` at the lines specified with comments and the `com.example.mixin` package.
This project uses [DevAuth](https://github.com/DJtheRedstoner/DevAuth) per default, so you can log in using your real This project uses [DevAuth](https://github.com/DJtheRedstoner/DevAuth) per default, so you can log in using your real
minecraft account. If you don't need that, you can remove it from the buildscript. minecraft account. If you don't need that, you can remove it from the buildscript.
@ -15,7 +19,7 @@ from [here](https://adoptium.net/temurin/releases) (or use your own downloads).
When you import your project into IntelliJ, you need to set the gradle jvm to the Java 17 JDK in the gradle tab, and the When you import your project into IntelliJ, you need to set the gradle jvm to the Java 17 JDK in the gradle tab, and the
Project SDK to the Java 1.8 JDK. Then click on the sync button in IntelliJ, and it should create a run task Project SDK to the Java 1.8 JDK. Then click on the sync button in IntelliJ, and it should create a run task
called `Minecraft Client`. If it doesn't then try relaunching your IntelliJ. **Warning for Mac users**: You might have to remove the `-XStartOnFirstThread` vm argument from your run configuration. In the future, that should be handled by the plugin, but for now you'll probably have to do that manually. called `Minecraft Client`. If it doesn't then try relaunching your IntelliJ. **Warning for Mac users**: You might have to remove the `-XStartOnFirstThread` vm argument from your run configuration. In the future, that should be handled by the plugin, but for now you'll probably have to do that manually.
To export your project, run the `gradle build` task, and give other people the To export your project, run the `gradle build` task, and give other people the
file `build/libs/<modid>-<version>.jar`. Ignore the jars in the `build/badjars` folder. Those are intermediary jars that file `build/libs/<modid>-<version>.jar`. Ignore the jars in the `build/badjars` folder. Those are intermediary jars that

View file

@ -6,8 +6,13 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2" id("com.github.johnrengelman.shadow") version "7.1.2"
} }
group = "com.example.archloomtemplate" //Constants:
version = "1.0.0"
val baseGroup: String by project
val mcVersion: String by project
val version: String by project
val mixinGroup = "$baseGroup.mixin"
val modid = rootProject.name
// Toolchains: // Toolchains:
java { java {
@ -23,17 +28,17 @@ loom {
property("mixin.debug", "true") property("mixin.debug", "true")
property("asmhelper.verbose", "true") property("asmhelper.verbose", "true")
arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") arg("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
arg("--mixin", "mixins.examplemod.json") arg("--mixin", "mixins.$modid.json")
} }
} }
forge { forge {
pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter())
// If you don't want mixins, remove this lines // If you don't want mixins, remove this lines
mixinConfig("mixins.examplemod.json") mixinConfig("mixins.$modid.json")
} }
// If you don't want mixins, remove these lines // If you don't want mixins, remove these lines
mixin { mixin {
defaultRefmapName.set("mixins.examplemod.refmap.json") defaultRefmapName.set("mixins.$modid.refmap.json")
} }
} }
@ -77,17 +82,30 @@ tasks.withType(JavaCompile::class) {
} }
tasks.withType(Jar::class) { tasks.withType(Jar::class) {
archiveBaseName.set("examplemod") archiveBaseName.set(modid)
manifest.attributes.run { manifest.attributes.run {
this["FMLCorePluginContainsFMLMod"] = "true" this["FMLCorePluginContainsFMLMod"] = "true"
this["ForceLoadAsMod"] = "true" this["ForceLoadAsMod"] = "true"
// If you don't want mixins, remove these lines // If you don't want mixins, remove these lines
this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker" this["TweakClass"] = "org.spongepowered.asm.launch.MixinTweaker"
this["MixinConfigs"] = "mixins.examplemod.json" this["MixinConfigs"] = "mixins.$modid.json"
} }
} }
tasks.processResources {
inputs.property("version", project.version)
inputs.property("mcversion", mcVersion)
inputs.property("modid", modid)
inputs.property("mixinGroup", mixinGroup)
filesMatching(listOf("mcmod.info", "mixins.$modid.json")) {
expand(inputs.properties)
}
rename("(.+_at.cfg)", "META-INF/$1")
}
val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") { val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") {
archiveClassifier.set("") archiveClassifier.set("")
@ -111,7 +129,7 @@ tasks.shadowJar {
} }
// If you want to include other dependencies and shadow them, you can relocate them in here // If you want to include other dependencies and shadow them, you can relocate them in here
fun relocate(name: String) = relocate(name, "com.examplemod.deps.$name") fun relocate(name: String) = relocate(name, "$baseGroup.deps.$name")
} }
tasks.assemble.get().dependsOn(tasks.remapJar) tasks.assemble.get().dependsOn(tasks.remapJar)

View file

@ -1,2 +1,5 @@
loom.platform=forge loom.platform=forge
org.gradle.jvmargs=-Xmx2g org.gradle.jvmargs=-Xmx2g
baseGroup = com.example
mcVersion = 1.8.9
version = 1.0.0

View file

@ -1,18 +1,18 @@
[ [
{ {
"modid": "examplemod", "modid": "${modid}",
"name": "Xample Mod", "name": "Xample Mod",
"description": "A mod that is used as an example.", "description": "A mod that is used as an example.",
"version": "1.0.0", "version": "${version}",
"mcversion": "1.8.9", "mcversion": "1.8.9",
"url": "https://github.com/romangraef/Forge1.8.9Template/", "url": "https://github.com/romangraef/Forge1.8.9Template/",
"updateUrl": "", "updateUrl": "",
"authorList": [ "authorList": [
"You" "You"
], ],
"credits": "", "credits": "",
"logoFile": "", "logoFile": "",
"screenshots": [], "screenshots": [],
"dependencies": [] "dependencies": []
} }
] ]