generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OneConfig example mod ify everything
- Loading branch information
Showing
5 changed files
with
156 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Build Workflow | ||
|
||
name: Build with Gradle | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
push: | ||
|
||
concurrency: | ||
group: ${{ github.head_ref || format('{0}-{1}', github.ref, github.run_number) }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 10 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 21 | ||
distribution: temurin | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
**/loom-cache | ||
**/prebundled-jars | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Chmod Gradle | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build | ||
run: ./gradlew build --no-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,198 +1,60 @@ | ||
@file:Suppress("UnstableApiUsage", "PropertyName") | ||
|
||
import org.polyfrost.gradle.util.noServerRunConfigs | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
import dev.deftu.gradle.utils.GameSide | ||
import dev.deftu.gradle.utils.MinecraftVersion | ||
|
||
// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit | ||
// which we use to prepare the environment. | ||
plugins { | ||
kotlin("jvm") | ||
id("org.polyfrost.multi-version") | ||
id("org.polyfrost.defaults.repo") | ||
id("org.polyfrost.defaults.java") | ||
id("org.polyfrost.defaults.loom") | ||
id("com.github.johnrengelman.shadow") | ||
id("net.kyori.blossom") version "1.3.2" | ||
id("signing") | ||
java | ||
kotlin("jvm") | ||
id("dev.deftu.gradle.multiversion") // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders. | ||
id("dev.deftu.gradle.tools") // Applies several configurations to things such as the Java version, project name/version, etc. | ||
id("dev.deftu.gradle.tools.resources") // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources. | ||
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. | ||
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! | ||
id("dev.deftu.gradle.tools.minecraft.loom") // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you. | ||
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. | ||
} | ||
|
||
// Gets the mod name, version and id from the `gradle.properties` file. | ||
val mod_name: String by project | ||
val mod_version: String by project | ||
val mod_id: String by project | ||
val mod_archives_name: String by project | ||
|
||
blossom { | ||
replaceToken("@VER@", mod_version) | ||
replaceToken("@NAME@", mod_name) | ||
replaceToken("@ID@", mod_id) | ||
} | ||
|
||
// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver! | ||
version = mod_version | ||
// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username. | ||
// e.g. com.github.<your username> or com.<your domain> | ||
group = "org.polyfrost" | ||
toolkitLoomHelper { | ||
useOneConfig { | ||
version = "1.0.0-alpha.49" | ||
loaderVersion = "1.1.0-alpha.35" | ||
|
||
// Sets the name of the output jar (the one you put in your mods folder and send to other people) | ||
// It outputs all versions of the mod into the `versions/{mcVersion}/build` directory. | ||
base { | ||
archivesName.set("$mod_archives_name-$platform") | ||
} | ||
usePolyMixin = true | ||
polyMixinVersion = "0.8.4+build.2" | ||
|
||
// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment. | ||
loom { | ||
// Removes the server configs from IntelliJ IDEA, leaving only client runs. | ||
// If you're developing a server-side mod, you can remove this line. | ||
noServerRunConfigs() | ||
applyLoaderTweaker = true | ||
|
||
// Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) | ||
if (project.platform.isLegacyForge) { | ||
runConfigs { | ||
"client" { | ||
programArgs("--tweakClass", "org.polyfrost.oneconfig.internal.legacy.OneConfigTweaker") | ||
programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") | ||
property("mixin.debug.export", "true") | ||
} | ||
} | ||
} | ||
// Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects. | ||
if (project.platform.isForge) { | ||
forge { | ||
mixinConfig("mixins.${mod_id}.json") | ||
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) { | ||
+module | ||
} | ||
} | ||
// Configures the name of the mixin "refmap" using an experimental loom api. | ||
mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json") | ||
} | ||
|
||
// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately. | ||
val shade: Configuration by configurations.creating { | ||
configurations.implementation.get().extendsFrom(this) | ||
} | ||
// Turns off the server-side run configs, as we're building a client-sided mod. | ||
disableRunConfigs(GameSide.SERVER) | ||
|
||
// Configures the output directory for when building from the `src/resources` directory. | ||
sourceSets { | ||
main { | ||
output.setResourcesDir(java.classesDirectory) | ||
// Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes. | ||
if (!mcData.isNeoForge) { | ||
useMixinRefMap(modData.id) | ||
} | ||
} | ||
|
||
// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. | ||
repositories { | ||
maven("https://repo.polyfrost.org/releases") | ||
maven("https://repo.polyfrost.org/snapshots") | ||
} | ||
|
||
// Configures the libraries/dependencies for your mod. | ||
dependencies { | ||
// Adds the OneConfig library, so we can develop with it. | ||
val oneconfig = "1.0.0-alpha.19" | ||
implementation("org.polyfrost.oneconfig:config-impl:$oneconfig") | ||
implementation("org.polyfrost.oneconfig:commands:$oneconfig") | ||
implementation("org.polyfrost.oneconfig:events:$oneconfig") | ||
implementation("org.polyfrost.oneconfig:ui:$oneconfig") | ||
implementation("org.polyfrost.oneconfig:internal:$oneconfig") | ||
modImplementation("org.polyfrost.oneconfig:$platform:$oneconfig") | ||
|
||
shade("org.shredzone.commons:commons-suncalc:3.5") | ||
|
||
modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0") | ||
|
||
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. | ||
if (platform.isLegacyForge) { | ||
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") | ||
// shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17") | ||
if (mcData.isForge) { | ||
// Configures the Mixin tweaker if we are building for Forge. | ||
useForgeMixin(modData.id) | ||
} | ||
} | ||
|
||
tasks { | ||
// Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces | ||
// the mod id, name and version with the ones in `gradle.properties` | ||
processResources { | ||
inputs.property("id", mod_id) | ||
inputs.property("name", mod_name) | ||
val java = if (project.platform.mcMinor >= 18) { | ||
17 // If we are playing on version 1.18, set the java version to 17 | ||
} else { | ||
// Else if we are playing on version 1.17, use java 16. | ||
if (project.platform.mcMinor == 17) | ||
16 | ||
else | ||
8 // For all previous versions, we **need** java 8 (for Forge support). | ||
} | ||
val compatLevel = "JAVA_${java}" | ||
inputs.property("java", java) | ||
inputs.property("java_level", compatLevel) | ||
inputs.property("version", mod_version) | ||
inputs.property("mcVersionStr", project.platform.mcVersionStr) | ||
filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) { | ||
expand( | ||
mapOf( | ||
"id" to mod_id, | ||
"name" to mod_name, | ||
"java" to java, | ||
"java_level" to compatLevel, | ||
"version" to mod_version, | ||
"mcVersionStr" to project.platform.mcVersionStr | ||
) | ||
) | ||
} | ||
filesMatching("fabric.mod.json") { | ||
expand( | ||
mapOf( | ||
"id" to mod_id, | ||
"name" to mod_name, | ||
"java" to java, | ||
"java_level" to compatLevel, | ||
"version" to mod_version, | ||
"mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x" | ||
) | ||
) | ||
} | ||
} | ||
dependencies { | ||
implementation(shade("org.shredzone.commons:commons-suncalc:3.5")!!) | ||
|
||
// Configures the resources to include if we are building for forge or fabric. | ||
withType(Jar::class.java) { | ||
if (project.platform.isFabric) { | ||
exclude("mcmod.info", "mods.toml") | ||
// Add Fabric Language Kotlin and (Legacy) Fabric API as dependencies (these are both optional but are particularly useful). | ||
if (mcData.isFabric) { | ||
if (mcData.isLegacyFabric) { | ||
// 1.8.9 - 1.13 | ||
modImplementation("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${mcData.dependencies.legacyFabric.legacyFabricApiVersion}") | ||
} else { | ||
exclude("fabric.mod.json") | ||
if (project.platform.isLegacyForge) { | ||
exclude("mods.toml") | ||
} else { | ||
exclude("mcmod.info") | ||
} | ||
} | ||
} | ||
|
||
// Configures our shadow/shade configuration, so we can | ||
// include some dependencies within our mod jar file. | ||
named<ShadowJar>("shadowJar") { | ||
archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix. | ||
configurations = listOf(shade) | ||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE | ||
} | ||
|
||
remapJar { | ||
inputFile.set(shadowJar.get().archiveFile) | ||
archiveClassifier.set("") | ||
} | ||
|
||
jar { | ||
// Sets the jar manifest attributes. | ||
if (platform.isLegacyForge) { | ||
manifest.attributes += mapOf( | ||
"ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine. | ||
"ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so. | ||
"TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible. | ||
"MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. | ||
"TweakClass" to "org.spongepowered.asm.launch.MixinTweaker" | ||
) | ||
// 1.16.5+ | ||
modImplementation("net.fabricmc.fabric-api:fabric-api:${mcData.dependencies.fabric.fabricApiVersion}") | ||
} | ||
dependsOn(shadowJar) | ||
archiveClassifier.set("") | ||
enabled = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
mod_name = PolyTime | ||
mod_id = polytime | ||
mod_version = 1.0.2 | ||
mod_archives_name = PolyTime | ||
|
||
polyfrost.defaults.loom=4 | ||
polyfrost.defaults.loom.mappings=official-like | ||
|
||
org.gradle.daemon=true | ||
org.gradle.parallel=true | ||
org.gradle.configureoncommand=true | ||
org.gradle.parallel.threads=4 | ||
org.gradle.jvmargs=-Xmx2G | ||
org.gradle.jvmargs=-Xmx2G | ||
|
||
mod.name=PolyTime | ||
mod.id=polytime | ||
mod.version=1.0.2 | ||
mod.group=org.polyfrost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,42 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.10" apply false | ||
id("org.polyfrost.multi-version.root") | ||
id("com.github.johnrengelman.shadow") version "8.1.1" apply false | ||
id("dev.deftu.gradle.multiversion-root") | ||
} | ||
|
||
preprocess { | ||
strictExtraMappings.set(true) | ||
val fabric10809 = createNode("1.8.9-fabric", 10809, "yarn") | ||
val fabric11202 = createNode("1.12.2-fabric", 11202, "yarn") | ||
val fabric11605 = createNode("1.16.5-fabric", 11605, "yarn") | ||
val fabric11701 = createNode("1.17.1-fabric", 11701, "yarn") | ||
val fabric11801 = createNode("1.18.1-fabric", 11801, "yarn") | ||
val fabric11904 = createNode("1.19.4-fabric", 11904, "yarn") | ||
val fabric12004 = createNode("1.20.4-fabric", 12004, "yarn") | ||
|
||
val forge10809 = createNode("1.8.9-forge", 10809, "srg") | ||
val forge11202 = createNode("1.12.2-forge", 11202, "srg") | ||
val forge11605 = createNode("1.16.5-forge", 11605, "srg") | ||
val forge11701 = createNode("1.17.1-forge", 11701, "srg") | ||
val forge11801 = createNode("1.18.1-forge", 11801, "srg") | ||
val forge11904 = createNode("1.19.4-forge", 11904, "srg") | ||
val forge12004 = createNode("1.20.4-forge", 12004, "srg") | ||
// Adding new versions/loaders can be done like so: | ||
// For each version, we add a new wrapper around the last from highest to lowest. | ||
// 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. | ||
// "1.12.2-forge"(11202, "srg") { | ||
// "1.8.9-forge"(10809, "srg") | ||
// } | ||
|
||
fabric10809.link(forge10809) | ||
fabric11202.link(fabric10809) | ||
fabric11605.link(fabric11202) | ||
fabric11701.link(fabric11605) | ||
fabric11801.link(fabric11701) | ||
fabric11904.link(fabric11801) | ||
fabric12004.link(fabric11904) | ||
"1.20.4-forge"(12004, "srg") { | ||
"1.20.4-fabric"(12004, "yarn") { | ||
"1.19.4-fabric"(11904, "yarn") { | ||
"1.19.4-forge"(11904, "srg") { | ||
"1.18.2-forge"(11802, "srg") { | ||
"1.18.2-fabric"(11802, "yarn") { | ||
"1.17.1-fabric"(11701, "yarn") { | ||
"1.17.1-forge"(11701, "srg") { | ||
"1.16.5-forge"(11605, "srg") { | ||
"1.16.5-fabric"(11605, "yarn") { | ||
"1.12.2-fabric"(11202, "yarn") { | ||
"1.12.2-forge"(11202, "srg") { | ||
"1.8.9-forge"(10809, "srg") { | ||
"1.8.9-fabric"(10809, "yarn") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
forge11202.link(fabric11202) | ||
forge11605.link(fabric11605) | ||
forge11701.link(fabric11701) | ||
forge11801.link(fabric11801) | ||
forge11904.link(fabric11904) | ||
forge12004.link(fabric12004) | ||
} | ||
strictExtraMappings.set(true) | ||
} |
Oops, something went wrong.