Skip to content

Commit

Permalink
support forge and neoforge
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Sep 9, 2024
1 parent 013fe11 commit 7c87452
Show file tree
Hide file tree
Showing 23 changed files with 655 additions and 148 deletions.
161 changes: 98 additions & 63 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
@file:Suppress("SpellCheckingInspection", "UnstableApiUsage")
@file:Suppress("SpellCheckingInspection", "UnstableApiUsage", "RedundantNullableReturnType")

import net.fabricmc.loom.util.ModPlatform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "2.0.0"
kotlin("plugin.serialization") version "2.0.0"
id("fabric-loom") version "1.7-SNAPSHOT"

id("me.modmuss50.mod-publish-plugin") version "0.5.+"
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.architectury.loom)
alias(libs.plugins.mod.publish)

`maven-publish`
signing
}

val beta: Int? = null // Pattern is '1.0.0-beta1-1.20.6-pre.2'
val featureVersion = "2.2.0${if (beta != null) "-beta$beta" else ""}"
val mcVersion = property("mcVersion")!!.toString()
val mcVersionRange = property("mcVersionRange")!!.toString()
version = "$featureVersion-$mcVersion"
val loader = loom.platform.get()
val isFabric = loader == ModPlatform.FABRIC

val beta: Int = property("mod.beta").toString().toInt()
val majorVersion: String = property("mod.major-version").toString()
val mcVersion = property("vers.mcVersion").toString() // Pattern is '1.0.0-beta1-1.20.6-pre.2+fabric'
version = "$majorVersion${if (beta != 0) "-beta$beta" else ""}-$mcVersion+${loader.name.lowercase()}"

group = "dev.nyon"
val authors = listOf("btwonion")
val githubRepo = "btwonion/better-boat-movement"
group = property("mod.group").toString()
val githubRepo = property("mod.repo").toString()

base {
archivesName.set(rootProject.name)
Expand All @@ -37,57 +37,92 @@ loom {
}

mixin { useLegacyMixinAp = false }
silentMojangMappingsLicense()
}

repositories {
mavenCentral()
maven("https://maven.terraformersmc.com")
maven("https://maven.parchmentmc.org")
maven("https://maven.quiltmc.org/repository/release/")
maven("https://repo.nyon.dev/releases")
maven("https://maven.isxander.dev/releases")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://thedarkcolour.github.io/KotlinForForge/")
maven("https://maven.neoforged.net/releases/")
}

val yaclVersion = property("vers.deps.yacl").toString()
val flk: String = "${libs.versions.fabric.language.kotlin.orNull}${libs.versions.kotlin.orNull}"
val fapi: String by lazy { property("vers.deps.fapi").toString() }
val modmenu: String by lazy { property("vers.deps.modMenu").toString() }
dependencies {
minecraft("com.mojang:minecraft:$mcVersion")
mappings(loom.layered {
val parchment: String = property("deps.parchment").toString()
if (parchment.isNotEmpty()) parchment("org.parchmentmc.data:parchment-$parchment@zip")
val quiltMappings: String = property("vers.deps.quiltmappings").toString()
if (quiltMappings.isNotEmpty()) mappings("org.quiltmc:quilt-mappings:$quiltMappings:intermediary-v2")
officialMojangMappings()
})

implementation("org.vineflower:vineflower:1.10.1")
modImplementation("net.fabricmc:fabric-loader:0.16.0")
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")!!}")
modImplementation("net.fabricmc:fabric-language-kotlin:1.11.0+kotlin.2.0.0")
implementation(libs.vineflower)

if (isFabric) {
implementation(libs.fabric.loader)
modImplementation("net.fabricmc.fabric-api:fabric-api:$fapi")
modImplementation("net.fabricmc:fabric-language-kotlin:$flk")
modImplementation("com.terraformersmc:modmenu:$modmenu")
} else {
if (loader == ModPlatform.FORGE) {
"forge"("net.minecraftforge:forge:$mcVersion-${property("vers.deps.fml")}")
compileOnly(libs.mixinextras.common)
annotationProcessor(libs.mixinextras.common)
include(libs.mixinextras.forge)
implementation(libs.mixinextras.forge)
} else
"neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}")
implementation("thedarkcolour:kotlinforforge${if (loader == ModPlatform.NEOFORGE) "-neoforge" else ""}:${property("vers.deps.kff")}")
}

modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}")
modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}")
modImplementation("dev.isxander:yet-another-config-lib:$yaclVersion")

include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!)
modImplementation(libs.konfig)
include(libs.konfig)
}

val javaVersion = property("javaVer")!!.toString()
val javaVersion = property("vers.javaVer").toString()
val modId = property("mod.id").toString()
val modName = property("mod.name").toString()
val modDescription = property("mod.description").toString()
val mcVersionRange = property("vers.mcVersionRange").toString()
val icon = property("mod.icon").toString()
val mixinsFile = property("mod.mixins").toString()
val slug = property("mod.slug").toString()
tasks {
processResources {
val modId = "better-boat-movement"
val modName = "BetterBoatMovement"
val modDescription = "Increases boat step height to move up water and blocks"

val props =
mapOf(
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version,
"github" to githubRepo,
"mc" to mcVersionRange
)
val props: Map<String, String?> = mapOf(
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version.toString(),
"github" to githubRepo,
"mc" to mcVersionRange,
"flk" to if (!isFabric) null else flk,
"fapi" to if (!isFabric) null else fapi,
"yacl" to yaclVersion,
"modmenu" to if (!isFabric) null else modmenu,
"repo" to githubRepo,
"icon" to icon,
"mixins" to mixinsFile,
"slug" to slug
).filterNot { it.value == null }

props.forEach(inputs::property)

filesMatching("fabric.mod.json") {
expand(props)
(if (isFabric) listOf("fabric.mod.json") else listOf(
"META-INF/mods.toml",
"META-INF/neoforge.mods.toml"
)).forEach { filesMatching(it) { expand(props) } }

filesMatching("pack.mcmeta") {
if (isFabric) exclude()
}
}

Expand All @@ -111,33 +146,45 @@ tasks {

val changelogText = buildString {
append("# v${project.version}\n")
rootProject.file("changelog.md").readText().also(::append)
if (beta != 0) appendLine("### As this is still a beta version, this version can contain bugs. Feel free to report ANY misbehaviours and errors!")
rootDir.resolve("changelog.md").readText().also(::append)
}

val supportedMcVersions: List<String> = property("supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty)
val supportedMcVersions: List<String> =
property("vers.supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty)

publishMods {
displayName = "v${project.version}"
file = tasks.remapJar.get().archiveFile
changelog = changelogText
type = if (beta != null) BETA else STABLE
modLoaders.addAll("fabric", "quilt")
type = if (beta != 0) BETA else STABLE
when (loader) {
ModPlatform.FABRIC -> modLoaders.addAll("fabric", "quilt")
ModPlatform.FORGE -> modLoaders.addAll("forge")
ModPlatform.NEOFORGE -> modLoaders.addAll("neoforge")
else -> {}
}

modrinth {
projectId = "wTfH1dkt"
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
minecraftVersions.addAll(supportedMcVersions)

requires { slug = "fabric-api" }
if (isFabric) {
requires { slug = "fabric-api" }
requires { slug = "fabric-language-kotlin" }
optional { slug = "modmenu" }
} else {
requires { slug = "kotlin-for-forge" }
}

requires { slug = "yacl" }
requires { slug = "fabric-language-kotlin" }
optional { slug = "modmenu" }
}

github {
repository = githubRepo
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = "master"
commitish = property("mod.main-branch").toString()
}
}

Expand All @@ -155,7 +202,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "dev.nyon"
artifactId = "better-boat-movement"
artifactId = modName
version = project.version.toString()
from(components["java"])
}
Expand All @@ -170,15 +217,3 @@ java {
targetCompatibility = it
}
}

/*
signing {
val signingKey: String? by project
val signingPassword: String? by project
useGpgCmd()
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(publishing.publications)
}
*/
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- add traditional chinese translation
- add forge and neoforge support
- change modid from better-boat-movement to bbm
18 changes: 17 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
org.gradle.jvmargs=-Xmx2G
kotlin.code.style=official
org.gradle.jvmargs=-Xmx4096M

mod.main-branch=master
mod.color=109249364
mod.icon=assets/bbm/icon/icon.png
mod.icon-url=https://github.com/btwonion/better-boat-movement/blob/master/src/main/resources/assets/bbm/icon/icon.png
mod.group=dev.nyon
mod.repo=btwonion/better-boat-movement
mod.slug=better-boat-movement
mod.id=bbm
mod.name=BetterBoatMovement
mod.description=Increases boat step height to move up water and blocks
mod.beta=0
mod.major-version=2.2.1
mod.mixins=bbm.mixins.json
mod.supported-loaders=fabric,quilt,neoforge,forge
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[versions]
kotlin = "2.0.20"
mod-publish = "0.5.+"
architectury-loom = "1.7-SNAPSHOT"
fabric-loader = "0.16.4"
fabric-language-kotlin = "1.12.1+kotlin."
vineflower = "1.10.1"
konfig = "2.0.2-1.20.4"
mixinextras = "0.4.1"

[libraries]
vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower" }
konfig = { module = "dev.nyon:konfig", version.ref = "konfig" }
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
mixinextras-common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" }
mixinextras-forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixinextras" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
architectury-loom = { id = "dev.architectury.loom", version.ref = "architectury-loom" }
mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
19 changes: 14 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,37 @@ pluginManagement {
mavenCentral()
gradlePluginPortal()
maven("https://maven.fabricmc.net/")
maven("https://server.bbkr.space/artifactory/libs-release/")
maven("https://maven.architectury.dev")
maven("https://maven.minecraftforge.net")
maven("https://maven.neoforged.net/releases/")
maven("https://maven.kikugie.dev/releases")
}
}

plugins {
id("dev.kikugie.stonecutter") version "0.4"
id("dev.kikugie.stonecutter") version "0.4.+"
}

buildscript {
repositories { mavenCentral() }
dependencies {
classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0-RC")
classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
}
}

extensions.configure<StonecutterSettings> {
kotlinController = true
centralScript = "build.gradle.kts"
shared {
versions("1.20.1", "1.20.4", "1.20.6", "1.21")
vcsVersion = "1.21"
vers("1.20.1-forge", "1.20.1")
vers("1.20.1-fabric", "1.20.1")
vers("1.20.4-neoforge", "1.20.4")
vers("1.20.4-fabric", "1.20.4")
vers("1.20.6-neoforge", "1.20.6")
vers("1.20.6-fabric", "1.20.6")
vers("1.21-neoforge", "1.21")
vers("1.21-fabric", "1.21")
vcsVersion = "1.21-fabric"
}
create(rootProject)
}
4 changes: 2 additions & 2 deletions src/main/java/dev/nyon/bbm/asm/MinecraftMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.nyon.bbm.asm;

import dev.nyon.bbm.BetterBoatMovement;
import dev.nyon.bbm.config.ConfigKt;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,6 +15,6 @@ public class MinecraftMixin {
at = @At("TAIL")
)
private void saveConfig(CallbackInfo ci) {
BetterBoatMovement.INSTANCE.saveConfig();
ConfigKt.saveConfig();
}
}
Loading

0 comments on commit 7c87452

Please sign in to comment.