Skip to content

Commit 81f2f0c

Browse files
committed
Bring up to speed with OneConfig example mod
1 parent d601e12 commit 81f2f0c

File tree

4 files changed

+101
-48
lines changed

4 files changed

+101
-48
lines changed

.github/workflows/build.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Build Workflow
2+
3+
name: Build with Gradle
4+
5+
on:
6+
pull_request:
7+
workflow_dispatch:
8+
push:
9+
10+
concurrency:
11+
group: ${{ github.head_ref || format('{0}-{1}', github.ref, github.run_number) }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
name: Build
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 10
25+
26+
- name: Set up JDK 17
27+
uses: actions/setup-java@v4
28+
with:
29+
java-version: 21
30+
distribution: temurin
31+
32+
- uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.gradle/caches
36+
~/.gradle/wrapper
37+
**/loom-cache
38+
**/prebundled-jars
39+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
40+
restore-keys: |
41+
${{ runner.os }}-gradle-
42+
43+
- name: Chmod Gradle
44+
run: chmod +x ./gradlew
45+
46+
- name: Build
47+
run: ./gradlew build --no-daemon

build.gradle.kts

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,59 @@
11
@file:Suppress("UnstableApiUsage", "PropertyName")
22

33
import dev.deftu.gradle.utils.GameSide
4+
import dev.deftu.gradle.utils.MinecraftVersion
45

56
plugins {
67
java
78
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")
14-
}
15-
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)
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.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).
15+
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
16+
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.
1917
}
2018

2119
toolkitLoomHelper {
22-
// Adds OneConfig to our project
23-
useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.43", mcData, "commands", "config-impl", "events", "hud", "internal", "ui")
24-
useDevAuth()
20+
useOneConfig {
21+
version = "1.0.0-alpha.49"
22+
loaderVersion = "1.1.0-alpha.35"
23+
24+
usePolyMixin = true
25+
polyMixinVersion = "0.8.4+build.2"
26+
27+
applyLoaderTweaker = true
28+
29+
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
30+
+module
31+
}
32+
}
2533

26-
// Removes the server configs from IntelliJ IDEA, leaving only client runs.
27-
// If you're developing a server-side mod, you can remove this line.
34+
// Turns off the server-side run configs, as we're building a client-sided mod.
2835
disableRunConfigs(GameSide.SERVER)
2936

30-
// Sets up our Mixin refmap naming
37+
// Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes.
3138
if (!mcData.isNeoForge) {
3239
useMixinRefMap(modData.id)
3340
}
3441

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-
useTweaker("org.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker", GameSide.CLIENT)
38-
useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
42+
if (mcData.isForge) {
43+
// Configures the Mixin tweaker if we are building for Forge.
44+
useForgeMixin(modData.id)
3945
}
4046
}
4147

42-
// Configures the output directory for when building from the `src/resources` directory.
43-
sourceSets {
44-
val dummy by creating
45-
main {
46-
dummy.compileClasspath += compileClasspath
47-
compileClasspath += dummy.output
48-
output.setResourcesDir(java.classesDirectory)
49-
}
50-
}
51-
52-
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
53-
repositories {
54-
maven("https://repo.polyfrost.org/releases")
55-
}
56-
57-
// Configures the libraries/dependencies for your mod.
5848
dependencies {
59-
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
60-
if (mcData.isLegacyForge) {
61-
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
62-
} else if (mcData.isFabric) {
49+
// Add Fabric Language Kotlin and (Legacy) Fabric API as dependencies (these are both optional but are particularly useful).
50+
if (mcData.isFabric) {
6351
if (mcData.isLegacyFabric) {
52+
// 1.8.9 - 1.13
6453
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}")
54+
} else {
55+
// 1.16.5+
56+
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}")
6557
}
66-
67-
modImplementation("net.fabricmc:fabric-language-kotlin:${mcData.dependencies.fabric.fabricLanguageKotlinVersion}")
6858
}
6959
}

root.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ plugins {
2121
}
2222

2323
preprocess {
24+
// Adding new versions/loaders can be done like so:
25+
// For each version, we add a new wrapper around the last from highest to lowest.
26+
// Each mod loader needs to link up to the previous version's mod loader so that the mappings can be processed from the previous version.
27+
// "1.12.2-forge"(11202, "srg") {
28+
// "1.8.9-forge"(10809, "srg")
29+
// }
30+
2431
"1.12.2-forge"(11202, "srg") {
2532
"1.12.2-fabric"(11202, "yarn") {
2633
"1.8.9-fabric"(10809, "yarn") {
2734
"1.8.9-forge"(10809, "srg")
2835
}
2936
}
3037
}
38+
39+
strictExtraMappings.set(true)
3140
}

settings.gradle.kts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
@file:Suppress("PropertyName")
2+
13
import groovy.lang.MissingPropertyException
24

35
pluginManagement {
46
repositories {
5-
// Repositories
7+
// Releases
68
maven("https://maven.deftu.dev/releases")
79
maven("https://maven.fabricmc.net")
810
maven("https://maven.architectury.dev/")
@@ -15,32 +17,37 @@ pluginManagement {
1517
maven("https://maven.deftu.dev/snapshots")
1618
mavenLocal()
1719

18-
// Default repositories
20+
// Default
1921
gradlePluginPortal()
2022
mavenCentral()
2123
}
2224

2325
plugins {
2426
kotlin("jvm") version("2.0.0")
25-
id("dev.deftu.gradle.multiversion-root") version("2.13.0")
27+
id("dev.deftu.gradle.multiversion-root") version("2.18.1")
2628
}
2729
}
2830

2931
val projectName: String = extra["mod.name"]?.toString()
3032
?: throw MissingPropertyException("mod.name has not been set.")
33+
34+
// Configures the root project Gradle name based on the value in `gradle.properties`
3135
rootProject.name = projectName
3236
rootProject.buildFileName = "root.gradle.kts"
3337

3438
// Adds all of our build target versions to the classpath if we need to add version-specific code.
39+
// Update this list if you want to remove/add a version and/or mod loader.
40+
// The format is: version-modloader (f.ex: 1.8.9-forge, 1.17.1-fabric, etc)
41+
// **REMEMBER TO ALSO UPDATE THE `root.gradle.kts` AND `build.gradle.kts` FILES WITH THE NEW VERSION(S).
3542
listOf(
3643
"1.8.9-forge",
3744
"1.8.9-fabric",
38-
"1.12.2-forge",
3945
"1.12.2-fabric",
46+
"1.12.2-forge",
4047
).forEach { version ->
4148
include(":$version")
4249
project(":$version").apply {
4350
projectDir = file("versions/$version")
4451
buildFileName = "../../build.gradle.kts"
4552
}
46-
}
53+
}

0 commit comments

Comments
 (0)