Skip to content

Commit

Permalink
update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Jun 18, 2024
1 parent e0a4a26 commit a9c1e75
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 51 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ name: build-commit
on:
push:
paths-ignore:
- "readme.md"
- "README.md"
- "LICENSE"
- ".gitignore"
- "changelog.md"
- ".editorconfig"
- "src/*/resources/lang/*"
pull_request:
paths-ignore:
- "readme.md"
- "README.md"
- "LICENSE"
- ".gitignore"
- "changelog.md"
Expand All @@ -38,9 +38,17 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle
uses: Wandalen/wretry.action@master
with:
command: ./gradlew buildAllVersions --stacktrace
run: ./gradlew buildAllVersions --stacktrace
- uses: actions/upload-artifact@v4
with:
path: versions/**/build/libs/*.jar

modrinth-description:
runs-on: ubuntu-latest
name: Sync Modrinth description
steps:
- uses: actions/checkout@v4
- uses: funnyboy-roks/modrinth-auto-desc@v1.6
with:
auth-token: ${{ secrets.MODRINTH_API_KEY }}
slug: 'autodrop'
14 changes: 11 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Release with Gradle
uses: Wandalen/wretry.action@master
with:
command: ./gradlew releaseAllVersions --stacktrace
run: ./gradlew releaseAllVersions postUpdate --stacktrace
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MODRINTH_API_KEY: ${{ secrets.MODRINTH_API_KEY }}
Expand All @@ -33,3 +31,13 @@ jobs:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SECRET_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SECRET_KEY_PASSWORD }}
GPG_SECRET_KEY_ID: ${{ secrets.GPG_SECRET_KEY_ID }}

modrinth-description:
runs-on: ubuntu-latest
name: Sync Modrinth description
steps:
- uses: actions/checkout@v4
- uses: funnyboy-roks/modrinth-auto-desc@v1.6
with:
auth-token: ${{ secrets.MODRINTH_API_KEY }}
slug: 'autodrop'
51 changes: 22 additions & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
@file:Suppress("SpellCheckingInspection")
@file:Suppress("SpellCheckingInspection", "UnstableApiUsage")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
id("fabric-loom") version "1.6-SNAPSHOT"
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.+"

`maven-publish`
signing
}

val featureVersion = "1.6.2"
val beta: Int? = null // Pattern is '1.0.0-beta1-1.20.6-pre.2'
val featureVersion = "1.7.0${if (beta != null) "-beta$beta" else ""}"
val mcVersion = property("mcVersion")!!.toString()
val mcVersionRange = property("mcVersionRange")!!.toString()
version = "$featureVersion-$mcVersion"
Expand All @@ -22,18 +24,16 @@ group = "dev.nyon"
val authors = listOf("btwonion")
val githubRepo = "btwonion/autodrop"

base {
archivesName.set(rootProject.name)
}

loom {
if (stonecutter.current.isActive) {
runConfigs.all {
ideConfigGenerated(true)
runDir("../../run")
}

rootProject.tasks.register("runActive") {
group = "mod"

dependsOn(tasks.named("runClient"))
}
}

mixin { useLegacyMixinAp = false }
Expand All @@ -50,14 +50,15 @@ repositories {
dependencies {
minecraft("com.mojang:minecraft:$mcVersion")
mappings(loom.layered {
parchment("org.parchmentmc.data:parchment-${property("deps.parchment")}@zip")
val parchment: String = property("deps.parchment").toString()
if (parchment.isNotEmpty()) parchment("org.parchmentmc.data:parchment-$parchment@zip")
officialMojangMappings()
})

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

modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}")
modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}")
Expand Down Expand Up @@ -100,13 +101,15 @@ tasks {
}

withType<KotlinCompile> {
kotlinOptions.jvmTarget = javaVersion
compilerOptions {
jvmTarget = JvmTarget.fromTarget(javaVersion)
}
}
}

val changelogText = buildString {
append("# v${project.version}\n")
file("../../changelog.md").readText().also { append(it) }
file("../../changelog.md").readText().also(::append)
}

val supportedMcVersions: List<String> =
Expand All @@ -116,7 +119,7 @@ publishMods {
displayName = "v${project.version}"
file = tasks.remapJar.get().archiveFile
changelog = changelogText
type = STABLE
type = if (beta != null) BETA else STABLE
modLoaders.addAll("fabric", "quilt")

modrinth {
Expand All @@ -135,12 +138,6 @@ publishMods {
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = "main"
}

discord {
webhookUrl = providers.environmentVariable("DISCORD_WEBHOOK")
username = "Release Notifier"
content = "# A new version of autodrop released!\n$changelogText\n\n"
}
}

publishing {
Expand Down Expand Up @@ -168,13 +165,9 @@ java {
withSourcesJar()

javaVersion.toInt().let { JavaVersion.values()[it - 1] }.let {
sourceCompatibility = it
targetCompatibility = it
}
}

kotlin {
jvmToolchain(javaVersion.toInt())
sourceCompatibility = it
targetCompatibility = it
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- support 1.20.1, 1.20.4, 1.20.6
- remove migrator for old config
- add support for 1.21
- fix archive name being only the version
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 12 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dev.kikugie.stonecutter.gradle.StonecutterSettings
import dev.kikugie.stonecutter.StonecutterSettings

rootProject.name = "autodrop"

Expand All @@ -12,15 +12,23 @@ pluginManagement {
}

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


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

extensions.configure<StonecutterSettings> {
kotlinController = true
centralScript = "build.gradle.kts"
shared {
versions("1.20.1", "1.20.4", "1.20.6")
vcsVersion = "1.20.6"
versions("1.20.1", "1.20.4", "1.20.6", "1.21")
vcsVersion = "1.21"
}
create(rootProject)
}
4 changes: 1 addition & 3 deletions src/main/kotlin/dev/nyon/autodrop/config/ConfigHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ internal fun migrate(
return@map Archive(
archiveObject["name"]?.jsonPrimitive?.content ?: return null,
archiveObject["items"]?.jsonArray?.map secMap@{ content ->
return@secMap ResourceLocation(
content.jsonPrimitive.contentOrNull ?: return null
)
return@secMap /*? if >=1.21 {*/ /*ResourceLocation.parse(content.jsonPrimitive.contentOrNull ?: return null) *//*?} else {*/ ResourceLocation(content.jsonPrimitive.contentOrNull ?: return null) /*?}*/
}?.toMutableList() ?: return null,
archiveObject["lockedSlots"]?.jsonArray?.map secMap@{ content ->
content.jsonPrimitive.content.toIntOrNull() ?: return null
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private fun ConfigCategory.Builder.appendLockedSlotsOptions(): ConfigCategory.Bu
group(
ListOption.createBuilder<Int>().name(Component.literal(archiveName)).description(
OptionDescription.createBuilder().text(Component.translatable("menu.autodrop.lockedslots.description"))
.image(ResourceLocation("autodrop", "image/inventory-slots.png"), 352, 331).build()
.image(/*? if >=1.21 {*/ /*ResourceLocation.parse("autodrop:image/inventory-slots.png") *//*?} else {*/ ResourceLocation("autodrop", "image/inventory-slots.png") /*?}*/, 352, 331).build()
).binding(mutableListOf(), { settings.archives.first { it.name == archiveName }.lockedSlots }, {
settings.archives.first { archive -> archive.name == archiveName }.lockedSlots = it.toMutableList()
reloadArchiveProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ object IdentifierSerializer : KSerializer<ResourceLocation> {
}

override fun deserialize(decoder: Decoder): ResourceLocation {
return ResourceLocation(decoder.decodeString())
return /*? if >=1.21 {*/ /*ResourceLocation.parse(decoder.decodeString()) *//*?} else {*/ ResourceLocation(decoder.decodeString()) /*?}*/
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": "${version}",
"environment": "client",
"depends": {
"fabric-language-kotlin": ">=1.10.20+kotlin.1.9.24",
"fabric-language-kotlin": ">=1.11.0+kotlin.2.0.0",
"fabric-api": "*",
"yet_another_config_lib_v3": "*",
"minecraft": "${mc}"
Expand Down
96 changes: 95 additions & 1 deletion stonecutter.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.*
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.time.Instant

plugins {
id("dev.kikugie.stonecutter")
}
stonecutter active "1.20.4" /* [SC] DO NOT EDIT */
stonecutter active "1.20.1" /* [SC] DO NOT EDIT */

stonecutter registerChiseled tasks.register("buildAllVersions", stonecutter.chiseled) {
group = "mod"
Expand All @@ -12,3 +21,88 @@ stonecutter registerChiseled tasks.register("releaseAllVersions", stonecutter.ch
group = "mod"
ofTask("releaseMod")
}

private data class Field(val name: String, val value: String, val inline: Boolean)

private data class Embed(
val title: String, val description: String, val timestamp: String, val color: Int, val fields: List<Field>
)

private data class DiscordWebhook(
val username: String, val avatarUrl: String, val embeds: List<Embed>
)

tasks.register("postUpdate") {
group = "mod"

val version = project(stonecutter.versions.first().project).version.toString()
val hyphenCount = version.count { it == '-' }
val featureVersion = when (hyphenCount) {
1 -> version.split("-").first()
2 -> {
val split = version.split("-")
if (split.last().contains("rc") || split.last().contains("pre")) split.first()
else "${split.first()}-${split[1]}"
}
3 -> {
val split = version.split("-")
"${split.first()}-${split[1]}"
}
else -> return@register
}

val url = providers.environmentVariable("DISCORD_WEBHOOK").orNull ?: return@register
val changelogText = rootProject.file("changelog.md").readText()
val webhook = DiscordWebhook(
username = "${rootProject.name} Release Notifier",
avatarUrl = "https://raw.githubusercontent.com/btwonion/autodrop/main/src/main/resources/assets/autodrop/icon/icon.png",
embeds = listOf(
Embed(
title = "v$featureVersion of ${rootProject.name} released!",
description = "# Changelog\n$changelogText",
timestamp = Instant.now().toString(),
color = 0x4ab616,
fields = listOf(
Field(
"Supported versions", stonecutter.versions.joinToString { it.version }, false
),
Field("Modrinth", "https://modrinth.com/mod/autodrop", true),
Field("GitHub", "https://github.com/btwonion/autodrop", true)
)
)
)
)

@OptIn(ExperimentalSerializationApi::class)
val embedsJson = buildJsonArray {
webhook.embeds.map { embed ->
add(buildJsonObject {
put("title", embed.title)
put("description", embed.description)
put("timestamp", embed.timestamp)
put("color", embed.color)
putJsonArray("fields") {
addAll(embed.fields.map { field ->
buildJsonObject {
put("name", field.name)
put("value", field.value)
put("inline", field.inline)
}
})
}
})
}
}

val json = buildJsonObject {
put("username", webhook.username)
put("avatar_url", webhook.avatarUrl)
put("embeds", embedsJson)
}

val jsonString = Json.encodeToString(json)
HttpClient.newHttpClient().send(
HttpRequest.newBuilder(URI.create(url)).header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonString)).build(), HttpResponse.BodyHandlers.ofString()
)
}
10 changes: 10 additions & 0 deletions versions/1.21/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mcVersion=1.21
mcVersionRange=>=1.20.6 <=1.21
supportedMcVersions=1.21

deps.parchment=
deps.fapi=0.100.1+1.21
deps.yacl=3.5.0+1.21-fabric
deps.modMenu=11.0.0-beta.1

javaVer=21

0 comments on commit a9c1e75

Please sign in to comment.