Skip to content

Commit c4b6a44

Browse files
Switch back to blossom, write a LONG readme
1 parent d7e4185 commit c4b6a44

8 files changed

Lines changed: 171 additions & 76 deletions

File tree

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7-
81
name: Build mod jar
92

103
on:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Releases to CurseForge and/or Modrinth
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4.2.2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v4.7.0
19+
with:
20+
java-version: '21'
21+
distribution: 'temurin'
22+
23+
- uses: gradle/actions/setup-gradle@v4.3.1
24+
with:
25+
gradle-version: 9.0.0
26+
name: Set up Gradle
27+
28+
- name: Add permission
29+
run: chmod +x ./gradlew
30+
31+
- name: Execute Gradle build
32+
run: ./gradlew build
33+
34+
- name: Get Changes between Tags
35+
id: changes
36+
uses: simbo/changes-between-tags-action@v1
37+
38+
- uses: Kir-Antipov/mc-publish@v3.3.0
39+
with:
40+
# Only include this section if you wish to publish
41+
# your assets on Modrinth.
42+
modrinth-id: placeholder
43+
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
44+
45+
# Only include this section if you wish to publish
46+
# your assets on CurseForge.
47+
curseforge-id: placeholder
48+
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
49+
50+
files: |
51+
build/libs/!(*-@(dev|sources|javadoc)).jar
52+
build/libs/*-@(dev|sources|javadoc).jar
53+
loaders: forge
54+
game-versions: 1.12.2
55+
java: |
56+
21
57+
22
58+
version: ${{ steps.changes.outputs.tag }}
59+
changelog: ${{ steps.changes.outputs.changes }}

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ gradle-app.setting
2525
# IDEA config
2626
.idea
2727

28-
# Source inject target, change it to your class
29-
src/main/java/com/example/modid/Reference.java

README.md

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,76 @@
22
Mod development template for Cleanroom, uses Unimined
33

44
## Usage
5-
Edit gradle.properties for general settings
6-
If you don't need shadow plugin, remove it from build.gradle
7-
If you want to change artifact file name, also change it in build.gradle
8-
Mixin in Cleanroom only need 1~3 configs, MixinBooter API is deprecated, check mixin branch for more detail
5+
### Choose Branch
6+
Choose mixin branch if you want to use Mixin.
97

10-
**WARNING**: These features are missing:
11-
- Inheriting ATs from dependencies. AT in runs works well though.
8+
Use scala and kotlin branch if you want to write in non-Java language.
129

13-
## Branches
14-
There are 3 branches available:
10+
There are 4 branches available:
1511
- main
1612
- mixin
1713
- scala
14+
- kotlin
1815

19-
If you want to use non-main branches, after clicked *Create a new repository* under *Use this template*, check the *Include all branches* checkbox
16+
If you want to use non-main branches, after clicked *Create a new repository* under *Use this template*, check the *Include all branches* checkbox.
17+
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`.
25+
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 `gradle/scripts/dependencies.gradle`.
32+
33+
No more `rfg.deobf()` or `fg.deobf` for mods, you should use `modImplementation`, `modCompileOnly` and `modRuntimeOnly`.
34+
35+
### Shadow
36+
You can use `shadow` in dependency declaration to shadow libraries.
37+
38+
### Contain
39+
You can use `contain` in dependency declaration to add non-mod libraries to artifact jar.
40+
41+
They will be extracted and loaded automatically in production.
42+
43+
### Mixin
44+
MixinBooter API is deprecated in Cleanroom.
45+
46+
Current approach is to set json configs in `MixinConfigs` manifest key, which will be read by Cleanroom.
47+
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.
49+
50+
All you need is to put `IEarlyMixinLoader` mixin to `DEFAULT` json, and, mixins from `ILateMixinLoader` to `MOD` json.
51+
52+
As for calling `Loader.isModLoaded()`, just fit an `IMixinConfigPlugin` to your json and call in `shouldApply()`
53+
54+
There are some example mixins and a HEI dependency in mixin fork, remove them before writing yours.
55+
56+
### Access Transformer
57+
You MUST write AT file in MCP name. It will be remapped back to SRG name in artifact jar.
58+
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.
60+
61+
**WARNING**: ATs from dependency won't be applied to vanilla source.
62+
63+
### Running Client or Server
64+
You MUST add mods by using `modImplementation` or `modRuntimeOnly`, or mapping and ATs will break.
65+
66+
### GitHub Action
67+
This template comes with three workflows.
68+
69+
`build.yml` will build and upload artifact for every commit. Useful when you want to provide test builds for debugging.
70+
71+
`release.yml` will make a GitHub release if you pushed a git tag.
72+
73+
`release-to-cf-mr` can publish your mod to CurseForge and/or Modrinth.
74+
75+
You need to fill in your project IDs and configure your tokens in GitHub repository first.
76+
77+
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`.

build.gradle

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import org.jetbrains.changelog.Changelog
2-
31
plugins {
42
id 'java'
53
id 'java-library'
64
id 'maven-publish'
7-
id 'com.gradleup.shadow' version '9.0.0-rc3' // Remove this line and shadowJar task if you don't need shadow
8-
id 'org.jetbrains.changelog' version '2.2.1'
5+
id 'com.gradleup.shadow' version '9.0.2'
96
id 'xyz.wagyourtail.unimined' version '1.4.1'
7+
id 'net.kyori.blossom' version '2.1.0'
108
}
119

1210
apply from: 'gradle/scripts/helpers.gradle'
@@ -17,10 +15,6 @@ assertProperty 'root_package'
1715
assertProperty 'mod_id'
1816
assertProperty 'mod_name'
1917

20-
if (propertyBool('generate_reference_class')) {
21-
generateReferenceClass()
22-
}
23-
2418
assertSubProperties 'use_access_transformer', 'access_transformer_locations'
2519
assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name'
2620
assertSubProperties 'use_asset_mover', 'asset_mover_version'
@@ -56,7 +50,9 @@ configurations {
5650
implementation.extendsFrom(embed)
5751
implementation.extendsFrom(contain)
5852
modCompileOnly
59-
compileOnly.extendsFrom modCompileOnly
53+
compileOnly.extendsFrom(modCompileOnly)
54+
modRuntimeOnly
55+
runtimeOnly.extendsFrom(modRuntimeOnly)
6056
}
6157

6258
unimined.minecraft {
@@ -154,6 +150,23 @@ processResources {
154150
rename '(.+_at.cfg)', 'META-INF/$1'
155151
}
156152

153+
sourceSets {
154+
main {
155+
blossom {
156+
javaSources {
157+
property('mod_id', propertyString('mod_id'))
158+
property('mod_name', propertyString('mod_name'))
159+
property('mod_version', propertyString('mod_version'))
160+
property('package', "${root_package}.${mod_id}")
161+
}
162+
}
163+
}
164+
}
165+
166+
if (!propertyBool('enable_shadow')) {
167+
shadowJar.enabled = false
168+
}
169+
157170
jar {
158171
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
159172
if (configurations.contain.size() > 0) {
@@ -194,6 +207,15 @@ shadowJar {
194207
archiveClassifier = "shadow"
195208
}
196209

210+
remapJar {
211+
doFirst {
212+
logging.captureStandardOutput LogLevel.INFO
213+
}
214+
doLast {
215+
logging.captureStandardOutput LogLevel.QUIET
216+
}
217+
}
218+
197219
compileTestJava {
198220
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21
199221
}
@@ -210,31 +232,6 @@ test {
210232
}
211233
}
212234

213-
String parserChangelog() {
214-
if (!file('CHANGELOG.md').exists()) {
215-
throw new GradleException('publish_with_changelog is true, but CHANGELOG.md does not exist in the workspace!')
216-
}
217-
String parsedChangelog = changelog.renderItem(
218-
changelog.get(propertyString('mod_version')).withHeader(false).withEmptySections(false),
219-
Changelog.OutputType.MARKDOWN)
220-
if (parsedChangelog.isEmpty()) {
221-
throw new GradleException('publish_with_changelog is true, but the changelog for the latest version is empty!')
222-
}
223-
return parsedChangelog
224-
}
225-
226-
def generateReferenceClass() {
227-
var target = new File("${rootProject.projectDir}/src/main/java/${root_package.replace('.', '/')}/${mod_id}/Reference.java")
228-
var template = new File("${rootProject.projectDir}/template/Reference.java")
229-
var replaceMap = [$package : "${root_package}.${mod_id}", $mod_id : mod_id, $mod_name : mod_name, $mod_version : mod_version]
230-
target.withWriter { var writer ->
231-
template.eachLine { var line ->
232-
replaceMap.each {if (line.contains(it.key)) line = line.replace(it.key, it.value)}
233-
writer.write(line + "\n");
234-
}
235-
}
236-
}
237-
238235
tasks.withType(JavaCompile).configureEach {
239236
options.encoding = 'UTF-8'
240237
}

gradle.properties

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,8 @@ publish_to_local_maven = false
4747
maven_name = ${mod_name}
4848
maven_url =
4949

50-
# Publishing
51-
# release_type can only be: release, beta or alpha (applies to CurseForge / Modrinth)
52-
release_type = release
53-
publish_with_changelog = ${{ it.file('CHANGELOG.md').exists() }}
54-
5550
# If any properties changes below this line, refresh gradle again to ensure everything is working correctly.
56-
57-
# Generate Reference Class
58-
# There's a method in build script that generates a reference class with certain fields inside.
59-
# Normally it will contain modid, mod name and mod version.
60-
# You can check the template class in template/Reference.java
61-
# You should change the ignore target in .gitignore if you changed modid or package name
62-
generate_reference_class = true
51+
# ----------------------------------------------------------------------------------------------------------------------
6352

6453
# Access Transformers
6554
# A way to change visibility of Minecraft's classes, methods and fields
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package {{ package }};
2+
3+
/**
4+
* Tags storage class, you can change at will
5+
*/
6+
public class Reference {
7+
private Reference() {}
8+
9+
public static final String MOD_ID = "{{ mod_id }}";
10+
public static final String MOD_NAME = "{{ mod_name }}";
11+
public static final String VERSION = "{{ mod_version }}";
12+
13+
}

template/Reference.java

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

0 commit comments

Comments
 (0)