Skip to content

Commit 4b27325

Browse files
Merge branch 'main' into kotlin
2 parents 1e911f6 + 71fa0f1 commit 4b27325

9 files changed

Lines changed: 114 additions & 122 deletions

File tree

README.md

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# CleanroomModTemplate
22
Mod development template for Cleanroom, uses Unimined
33

4-
## Usage
4+
## DOs and DON'Ts
55
### Choose Branch
66
Choose mixin branch if you want to use Mixin.
77

8-
Use scala and kotlin branch if you want to write in non-Java language.
8+
Use scala and kotlin branch if you want to use those languages.
99

1010
There are 4 branches available:
1111
- main
@@ -15,61 +15,48 @@ There are 4 branches available:
1515

1616
If you want to use non-main branches, after clicked *Create a new repository* under *Use this template*, check the *Include all branches* checkbox.
1717

18-
### gradle.properties
19-
Edit gradle.properties and set your modid, mod version, mod name, package, etc.
20-
21-
If you are writing a coremod, remember to set related settings to true.
22-
23-
### Reference Class
24-
Mostly used to store mod version so you can fill it to `@Mod`.
2518

26-
You should change its location to fit your new package name.
27-
28-
You can find it under `src/main/java-templates`.
29-
30-
### Dependencies
31-
You can find dependency script in `buildSrc/src/main/kotlin/dependencies.gradle.kts`.
19+
### Running Client or Server
20+
If you are using IntelliJ, **DO NOT** use the `Minecraft Client` configure with a blue icon. Just use the `2. Run Client` Gradle task.
3221

33-
No more `rfg.deobf()` or `fg.deobf` for mods, you should use `modImplementation`, `modCompileOnly` and `modRuntimeOnly`.
22+
### Adding Mod Dependencies
23+
You can find dependencies block in `gradle/scripts/dependencies.gradle`.
3424

35-
### Shadow
36-
You can use `shadow` in dependency declaration to shadow libraries.
25+
No more `rfg.deobf()` or `fg.deobf`. You **MUST** add mods by using `modImplementation` or `modRuntimeOnly`, or the game will crash when running.
3726

38-
### Contain
39-
You can use `contain` in dependency declaration to add non-mod libraries to artifact jar.
27+
### Non-Mod Dependencies
28+
Two new configuration types `contain` and `shadow` are available, check more details in `dependencies.gradle`.
4029

41-
They will be extracted and loaded automatically in production.
30+
### gradle.properties
31+
Edit gradle.properties and set your modid, mod version, mod name, package, etc.
4232

43-
### Mixin
44-
MixinBooter API is deprecated in Cleanroom.
33+
If you are writing a coremod, remember to set related settings to true.
4534

46-
Current approach is to set json configs in `MixinConfigs` manifest key, which will be read by Cleanroom.
35+
### Reference Class
36+
There will be a `Reference` class under your top package.
4737

48-
You don't need to set tons of json too. If you aren't mixining into Forge, all you need is two jsons for `DEFAULT` hase and `MOD` Phase.
38+
This is used to store mod version so you can fill it to `@Mod` annotation.
4939

50-
All you need is to put `IEarlyMixinLoader` mixin to `DEFAULT` json, and, mixins from `ILateMixinLoader` to `MOD` json.
40+
You should change its location to fit your new package name.
5141

52-
As for calling `Loader.isModLoaded()`, just fit an `IMixinConfigPlugin` to your json and call in `shouldApply()`
42+
You can find its template under `src/main/java-templates`.
5343

54-
There are some example mixins and a HEI dependency in mixin fork, remove them before writing yours.
44+
### Mixin
45+
1. Rename json config file to include your modid. You will need one json per phase (`PRE_INIT`, `DEFAULT`, `MOD`)
46+
2. Add your mixin classes there.
47+
3. Use `IMixinConfigPlugin` to control if certain mixin should be enabled. You can call `Loader.isModLoaded()` for `MOD` phase mixins.
48+
4. Don't worry about refmap, Unimined will handle it automatically. You can still `disableRefmap()` manually though
5549

5650
### Access Transformer
57-
You MUST write AT file in MCP name. It will be remapped back to SRG name in artifact jar.
51+
You **MUST** write AT file in MCP name. It will be remapped back to SRG name in artifact jar.
5852

59-
Rename AT file name to your modid before using it. There's an example entry in AT file, remove it if you want to use AT.
53+
Rename AT file name to your modid before using it. There's an example entry in AT file, remove it if you want to use AT.
6054

61-
**WARNING**: ATs from dependency won't be applied to vanilla source.
62-
63-
### Source Code with Comments
64-
Run `genSources` task in gradle.
55+
### Vanilla Source Code with Comments
56+
Run `genSources` task in gradle. If it didn't work, run again until a file with `-sources.jar` suffix appeared.
6557

6658
If you want to `find usage` from vanilla like RFG, just change the scope in IntelliJ settings.
6759

68-
### Running Client or Server
69-
You **MUST** add mods by using `modImplementation` or `modRuntimeOnly`, or mapping and ATs will break.
70-
71-
If you are using IntelliJ, **DO NOT** use the `Minecraft Client` configure with a blue icon. Just use the `runClient` Gradle task.
72-
7360
### GitHub Action
7461
This template comes with three workflows.
7562

@@ -81,8 +68,9 @@ This template comes with three workflows.
8168

8269
You need to fill in your project IDs and configure your tokens in GitHub repository first.
8370

84-
By default, you will need to manually trigger the workflow in web page, but you can also enable tag triggering by merging it into `release.yml`.
71+
By default, you will need to manually trigger the workflow in web page, but you can also enable tag triggering by merging the third yml into `release.yml`.
8572

8673
### Credit
8774
Thanks @Karnatour for fixing shadow plugin
75+
8876
Thanks @ghostflyby for making kotlin branch

build.gradle.kts

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
1+
import org.jetbrains.gradle.ext.Gradle
2+
import org.jetbrains.gradle.ext.compiler
3+
import org.jetbrains.gradle.ext.runConfigurations
4+
import org.jetbrains.gradle.ext.settings
25

36
plugins {
47
java
58
`java-library`
69
`maven-publish`
710
kotlin("jvm") version "2.3.10"
8-
id("com.gradleup.shadow") version "9.3.0"
11+
id("com.gradleup.shadow") version "9.3.2"
12+
id("org.jetbrains.gradle.plugin.idea-ext") version "1.4.1"
913
id("xyz.wagyourtail.unimined") version "1.4.10-kappa"
10-
id("net.kyori.blossom") version "2.1.0"
14+
id("net.kyori.blossom") version "2.2.0"
1115
}
1216

1317
// Early Assertions
@@ -45,17 +49,16 @@ java {
4549
}
4650

4751
configurations {
48-
val embed by creating
4952
val contain by creating
50-
implementation {
51-
extendsFrom(embed, contain)
52-
}
53+
implementation { extendsFrom(contain) }
5354
val modCompileOnly by creating
5455
compileOnly { extendsFrom(modCompileOnly) }
5556
val modRuntimeOnly by creating
5657
runtimeOnly { extendsFrom(modRuntimeOnly) }
5758
}
5859

60+
val remapTaskName = if (propertyBool("enable_shadow")) "remapShadowJar" else "remapJar"
61+
5962
unimined.minecraft {
6063
version("1.12.2")
6164

@@ -88,27 +91,21 @@ unimined.minecraft {
8891

8992
defaultRemapJar = false
9093

91-
if (propertyBool("enable_shadow")) {
92-
remap(tasks.shadowJar.get()) {
93-
mixinRemap {
94-
enableBaseMixin()
95-
enableMixinExtra()
96-
disableRefmap()
97-
}
98-
}
99-
} else {
100-
remap(tasks.jar.get()) {
101-
mixinRemap {
102-
enableBaseMixin()
103-
enableMixinExtra()
104-
disableRefmap()
105-
}
94+
val jarTaskName = if (propertyBool("enable_shadow")) "shadowJar" else "jar"
95+
96+
remap(tasks.named(jarTaskName).get()) {
97+
mixinRemap {
98+
enableBaseMixin()
99+
enableMixinExtra()
100+
disableRefmap()
106101
}
107102
}
108103

109104
mods {
110105
val modCompileOnly by configurations.getting
106+
val modRuntimeOnly by configurations.getting
111107
remap(modCompileOnly)
108+
remap(modRuntimeOnly)
112109
}
113110
}
114111

@@ -117,43 +114,14 @@ dependencies {
117114
implementation("com.cleanroommc:assetmover:${propertyString("asset_mover_version")}")
118115
}
119116
if (propertyBool("enable_junit_testing")) {
120-
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
117+
testImplementation("org.junit.jupiter:junit-jupiter:6.0.2")
121118
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
122119
}
123120
}
124121

125122
apply(plugin = "dependencies")
126123

127124
tasks.processResources {
128-
129-
inputs.property("mod_id", propertyString("mod_id"))
130-
inputs.property("mod_name", propertyString("mod_name"))
131-
inputs.property("mod_version", propertyString("mod_version"))
132-
inputs.property("mod_description", propertyString("mod_description"))
133-
inputs.property("mod_authors", propertyStringList("mod_authors", ",").joinToString(", "))
134-
inputs.property("mod_credits", propertyString("mod_credits"))
135-
inputs.property("mod_url", propertyString("mod_url"))
136-
inputs.property("mod_update_json", propertyString("mod_update_json"))
137-
inputs.property("mod_logo_path", propertyString("mod_logo_path"))
138-
139-
val filterList = listOf("mcmod.info", "pack.mcmeta")
140-
141-
filesMatching(filterList) {
142-
expand(
143-
mapOf(
144-
"mod_id" to propertyString("mod_id"),
145-
"mod_name" to propertyString("mod_name"),
146-
"mod_version" to propertyString("mod_version"),
147-
"mod_description" to propertyString("mod_description"),
148-
"mod_authors" to propertyStringList("mod_authors", ",").joinToString(", "),
149-
"mod_credits" to propertyString("mod_credits"),
150-
"mod_url" to propertyString("mod_url"),
151-
"mod_update_json" to propertyString("mod_update_json"),
152-
"mod_logo_path" to propertyString("mod_logo_path"),
153-
),
154-
)
155-
}
156-
157125
rename("(.+_at.cfg)", "META-INF/$1")
158126
}
159127

@@ -168,6 +136,17 @@ sourceSets {
168136
val modId = propertyString("mod_id")
169137
property("package", "$rootPackage.$modId")
170138
}
139+
resources {
140+
property("mod_id", propertyString("mod_id"))
141+
property("mod_name", propertyString("mod_name"))
142+
property("mod_version", propertyString("mod_version"))
143+
property("mod_description", propertyString("mod_description"))
144+
property("mod_authors", "${propertyStringList("mod_authors", ",").joinToString(", ")}")
145+
property("mod_credits", propertyString("mod_credits"))
146+
property("mod_url", propertyString("mod_url"))
147+
property("mod_update_json", propertyString("mod_update_json"))
148+
property("mod_logo_path", propertyString("mod_logo_path"))
149+
}
171150
}
172151
}
173152
}
@@ -176,6 +155,32 @@ if (!propertyBool("enable_shadow")) {
176155
tasks.shadowJar { enabled = false }
177156
}
178157

158+
idea {
159+
module {
160+
inheritOutputDirs = true
161+
}
162+
project {
163+
settings {
164+
runConfigurations {
165+
add(Gradle("1. Build").apply {
166+
setProperty("taskNames", listOf("build"))
167+
})
168+
add(Gradle("2. Run Client").apply {
169+
setProperty("taskNames", listOf("runClient"))
170+
})
171+
add(Gradle("3. Run Server").apply {
172+
setProperty("taskNames", listOf("runServer"))
173+
})
174+
}
175+
compiler.javac {
176+
afterEvaluate {
177+
javacAdditionalOptions = "-encoding utf8"
178+
}
179+
}
180+
}
181+
}
182+
}
183+
179184
tasks.jar {
180185
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
181186
val contain by configurations.getting
@@ -204,19 +209,15 @@ tasks.jar {
204209
attributes(attributeMap)
205210
}
206211
}
207-
if (propertyBool("enable_shadow")) {
208-
finalizedBy(tasks.named("remapShadowJar"))
209-
} else {
210-
finalizedBy(tasks.named("remapJar"))
211-
}
212+
finalizedBy(tasks.named(remapTaskName).get())
212213
}
213214

214215
tasks.shadowJar {
215216
configurations.add(project.configurations.shadow)
216217
archiveClassifier = "shadow"
217218
}
218219

219-
tasks.named<RemapJarTask>("remapJar") {
220+
tasks.named(remapTaskName) {
220221
doFirst {
221222
logging.captureStandardOutput(LogLevel.INFO)
222223
}

buildSrc/src/main/kotlin/dependencies.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies {
4343
// runtimeOnly = runtime dependency
4444
// compileOnly = compile time dependency
4545
// annotationProcessor = annotation processing dependencies
46-
// contain = bundle dependency jars into final artifact, will extract them in mod loading. Please only do this to non-mod dependencies.
46+
// contain = bundle dependency jars into final artifact, will extract them in mod loading. Can be used it as jar-in-jar
4747
// shadow = bundle dependencies into shadow output artifact (relocation configurable in shadowJar task)
4848
// modImplementation = mod dependency available at both compile time and runtime
4949
// modCompileOnly = mod dependency available only at compile time

settings.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
pluginManagement {
22
repositories {
3+
gradlePluginPortal {
4+
content {
5+
excludeGroup("org.apache.logging.log4j")
6+
}
7+
}
38
mavenCentral()
49
maven {
510
setUrl("https://maven.outlands.top/releases")
@@ -19,11 +24,6 @@ pluginManagement {
1924
maven {
2025
setUrl("https://maven.outlands.top/releases")
2126
}
22-
gradlePluginPortal {
23-
content {
24-
excludeGroup("org.apache.logging.log4j")
25-
}
26-
}
2727
}
2828
}
2929

src/main/kotlin/com/example/modid/ExampleMod.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.modid
22

33
import com.example.modid.proxy.IProxy
4+
import net.minecraft.client.Minecraft
45
import net.minecraftforge.fml.common.Mod
56
import net.minecraftforge.fml.common.SidedProxy
67
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
@@ -21,5 +22,7 @@ class ExampleMod {
2122
@Mod.EventHandler
2223
fun preInit(event: FMLPreInitializationEvent?) {
2324
LOGGER.info("Hello From {}!", Reference.MOD_NAME)
25+
LOGGER.info("Proxy is {}", proxy)
26+
LOGGER.info("Language: {}", Minecraft.getMinecraft().languageManager.currentLanguage)
2427
}
2528
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[{
2+
"modid": "{{ mod_id }}",
3+
"name": "{{ mod_name }}",
4+
"version": "{{ mod_version }}",
5+
"mcversion": "1.12.2",
6+
"description": "{{ mod_description }}",
7+
"authorList": ["{{ mod_authors }}"],
8+
"credits": "{{ mod_credits }}",
9+
"url": "{{ mod_url }}",
10+
"updateJSON": "{{ mod_update_json }}",
11+
"logoFile": "{{ mod_logo_path }}"
12+
}]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pack": {
3+
"description": "{{ mod_name }} Resources",
4+
"pack_format": 3
5+
}
6+
}

src/main/resources/mcmod.info

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)