Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
the big unfinished commit
Browse files Browse the repository at this point in the history
  • Loading branch information
homchom committed Jun 30, 2024
1 parent 585705b commit 3606e49
Show file tree
Hide file tree
Showing 372 changed files with 289 additions and 228 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#Gradle
# Gradle
.gradle/
build/
out/
classes/
gradle/wrapper/gradle-wrapper.properties

#IDEA
# IDEA
.idea/
*.iml
*.ipr
*.iws

#vscode
# VSCode
.settings/
.vscode/
bin/
.classpath
.project

#fabric
# Fabric
run/
logs/
*.launch
221 changes: 2 additions & 219 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,225 +1,8 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "2.0.0"
id("fabric-loom") version "1.5-SNAPSHOT"
id("com.modrinth.minotaur") version "2.+"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

val modName: String by project
val modVersion: String by project
val minecraftVersion: String by project
val modVersionWithMeta get() = "$modVersion+$minecraftVersion"
version = "$modVersionWithMeta-LATEST"

val mavenGroup: String by project
group = mavenGroup

val fabricVersion: String by project
val loaderVersion: String by project
val flkVersion: String by project

val requiredDependencyMods = dependencyModsOfType("required")
val optionalDependencyMods = dependencyModsOfType("optional")

base {
archivesName.set(modName)
// removing this causes issues, but we need to remove it to free up the kotlin plugin on the buildscript
//alias(libs.plugins.fabric.loom) apply false
}

repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter { includeGroup("maven.modrinth") }
}

maven {
name = "CottonMC"
url = uri("https://server.bbkr.space/artifactory/libs-release")
}
maven {
url = uri("https://maven.shedaniel.me/")
}
maven {
url = uri("https://maven.terraformersmc.com/")
}
maven {
url = uri("https://jitpack.io")
}
mavenCentral()
}

val shade: Configuration by configurations.creating {
isCanBeResolved = true
// exclude slf4j because it is already provided by Minecraft TODO: can this workaround be removed now?
exclude(group = "org.slf4j")
}

dependencies {
// minecraft
minecraft("com.mojang:minecraft:$minecraftVersion")
mappings(loom.officialMojangMappings())

// fabric
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion")
modImplementation("net.fabricmc:fabric-loader:$loaderVersion")

// kotlin
modImplementation("net.fabricmc:fabric-language-kotlin:$flkVersion")

// mod dependencies listed in gradle.properties
for (mod in requiredDependencyMods) {
include(modImplementation("${mod.artifact}:${mod.version}")!!)
}
for (mod in optionalDependencyMods) {
modCompileOnly("${mod.artifact}:${mod.version}")
}

// Websocket TODO: clean this up
shade(implementation("org.java-websocket:Java-WebSocket:1.5.3")!!)
include(implementation("javax.websocket:javax.websocket-api:1.1")!!)
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present. If you remove this line, sources will not be generated.
withSourcesJar()
}

tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
}

withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
freeCompilerArgs.set(listOf(
"-Xjvm-default=all",
))
}
}

processResources {
// these properties can be used in fabric_mod_json_template.txt in Groovy template syntax
val exposedProperties = arrayOf(
"modName" to modName,
"version" to modVersion,
"minecraftVersion" to minecraftVersion,
"loaderVersion" to loaderVersion,
"fabricVersion" to fabricVersion,
"flkVersion" to flkVersion
)

inputs.properties(*exposedProperties)
inputs.properties(project.properties.filterKeys { it.startsWith("required.") })

// evaluate fabric_mod_json_template.txt as a Groovy template
filesMatching("fabric_mod_json_template.txt") {
val metadataRegex = Regex("""\+.+$""")
expand(
*exposedProperties,
"metadataRegex" to metadataRegex.toPattern(),
"dependencyMods" to requiredDependencyMods.joinToString(", ") { mod ->
val version = mod.version.replace(metadataRegex, "")
"\"${mod.id}\": \"${mod.versionSpec}$version\""
}
)
}
rename("fabric_mod_json_template.txt", "fabric.mod.json")
}

jar {
// disable jar (in favor of shadowJar)
enabled = false
}

shadowJar {
configurations = listOf(shade)
from("LICENSE")

// output shaded jar in the correct destination to be used by remapJar
destinationDirectory.set(file("build/devlibs"))
archiveClassifier.set("dev")

// relocate
isEnableRelocation = true
relocationPrefix = "$mavenGroup.$modName.shaded"
}

remapJar {
// use the shaded jar with remapJar
inputFile.value(shadowJar.get().archiveFile)
}
}

tasks.modrinth.get().dependsOn(tasks.modrinthSyncBody)

modrinth {
// DO NOT PUT THIS IN RECODE'S GRADLE.PROPERTIES. Your modrinth token should remain private to everyone.
token.set(findProperty("privateModrinthToken")?.toString() ?: "")

projectId.set("recode")
versionNumber.set(modVersionWithMeta)

val match = Regex("""-(?<phase>beta|alpha)\.""").find(modVersion)
if (match == null) {
versionName.set(modVersion)
versionType.set("release")
} else {
val phase = match.groups["phase"]!!.value
versionName.set(modVersion.replaceRange(match.range, " $phase "))
versionType.set(phase)
}

// remove "LATEST" classifiers when uploading to modrinth
uploadFile.set(tasks.remapJar.map { task ->
val jarFile = task.archiveFile.get().asFile
val newPath = jarFile.path.replace("-LATEST", "")
jarFile.renameTo(File(newPath))
newPath
})

gameVersions.addAll(minecraftVersion)
dependencies {
required.version("fabric-api", fabricVersion)
}

// TODO: use something other than readText?
syncBodyFrom.set(file("README.md").readText())
changelog.set(file("CHANGELOG.md").readText())
}

data class DependencyMod(
val id: String,
val artifact: String,
val version: String,
val versionSpec: String
) {
constructor(id: String, artifact: Any?, version: Any?, versionSpec: Any?) :
this(id, artifact.toString(), version.toString(), versionSpec.toString())
}

/**
* @return The list of [DependencyMod] values matching [type] in gradle.properties.
*/
fun dependencyModsOfType(type: String): List<DependencyMod> {
val regex = Regex("""$type\.([^\.]+)\.artifact""")
return properties.mapNotNull { (key, value) ->
regex.matchEntire(key)?.let { match ->
val id = match.groupValues[1]
val version = project.properties["$type.$id.version"]
val versionSpec = project.properties.getOrDefault("$type.$id.versionSpec", "^")
DependencyMod(id, value, version, versionSpec)
}
}
}
11 changes: 11 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}

dependencies {
//implementation(libs.kotlin.gradlePlugin)
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/recode.kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
//kotlin("jvm")
}
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ org.gradle.jvmargs = -Xmx1G

# https://fabricmc.net/develop/

modName = recode
mavenGroup = io.github.homchom

# the mod version, without metadata
modVersion = 0.1.0-beta.10

Expand Down Expand Up @@ -34,8 +37,4 @@ optional.modmenu.artifact = com.terraformersmc:modmenu
optional.modmenu.version = 9.0.0

optional.sodium.artifact = maven.modrinth:sodium
optional.sodium.version = mc1.20.4-0.5.8

# mod properties
modName = recode
mavenGroup = io.github.homchom
optional.sodium.version = mc1.20.4-0.5.8
23 changes: 23 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[libraries]

# required; change versions every minecraft update
minecraft = { module = "com.mojang:minecraft", version = "1.20.4" }
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version = "0.96.1+1.20.4" }

adventure-platform-fabric = { module = "net.kyori:adventure-platform-fabric", version = "5.12.0" }
libgui = { module = "io.github.cottonmc:LibGui", version = "9.2.2+1.20.2" }
cloth-config = { module = "me.shedaniel.cloth:cloth-config-fabric", version = "13.0.121" }

# optional; change versions every minecraft update
modmenu = { module = "com.terraformersmc:modmenu", version = "9.0.0" }
sodium = { module = "maven.modrinth:sodium", version = "mc1.20.4-0.5.8" }

# change versions as needed
fabric-loader = { module = "net.fabricmc:fabric-loader", version = "0.15.2" }

kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version = "2.0.0" }
fabric-language-kotlin = { module = "net.fabricmc:fabric-language-kotlin", version = "1.11.0+kotlin.2.0.0" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.0.0" }
fabric-loom = { id = "fabric-loom", version = "1.5-SNAPSHOT" }
Loading

0 comments on commit 3606e49

Please sign in to comment.