From a9c1e7589af4ece986019452118719ef2baecd82 Mon Sep 17 00:00:00 2001 From: btwonion Date: Tue, 18 Jun 2024 16:55:00 +0200 Subject: [PATCH] update to 1.21 --- .github/workflows/build-commit.yml | 18 +++- .github/workflows/release.yml | 14 ++- build.gradle.kts | 51 +++++----- changelog.md | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 16 +++- .../dev/nyon/autodrop/config/ConfigHandler.kt | 4 +- .../dev/nyon/autodrop/config/YaclScreen.kt | 2 +- .../autodrop/util/IdentifierSerializer.kt | 2 +- src/main/resources/fabric.mod.json | 2 +- stonecutter.gradle.kts | 96 ++++++++++++++++++- versions/1.21/gradle.properties | 10 ++ 12 files changed, 170 insertions(+), 51 deletions(-) create mode 100644 versions/1.21/gradle.properties diff --git a/.github/workflows/build-commit.yml b/.github/workflows/build-commit.yml index dd116f5..9733faf 100644 --- a/.github/workflows/build-commit.yml +++ b/.github/workflows/build-commit.yml @@ -5,7 +5,7 @@ name: build-commit on: push: paths-ignore: - - "readme.md" + - "README.md" - "LICENSE" - ".gitignore" - "changelog.md" @@ -13,7 +13,7 @@ on: - "src/*/resources/lang/*" pull_request: paths-ignore: - - "readme.md" + - "README.md" - "LICENSE" - ".gitignore" - "changelog.md" @@ -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' \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd58a72..3a834af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} @@ -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' \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 15564ed..bcf68a2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,12 @@ -@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.+" @@ -13,7 +14,8 @@ plugins { 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" @@ -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 } @@ -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")!!}") @@ -100,13 +101,15 @@ tasks { } withType { - 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 = @@ -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 { @@ -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 { @@ -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 + } } /* diff --git a/changelog.md b/changelog.md index 4cea6b1..c60203b 100644 --- a/changelog.md +++ b/changelog.md @@ -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 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..0d18421 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/settings.gradle.kts b/settings.gradle.kts index 0bc7341..65efa95 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ -import dev.kikugie.stonecutter.gradle.StonecutterSettings +import dev.kikugie.stonecutter.StonecutterSettings rootProject.name = "autodrop" @@ -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 { 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) } diff --git a/src/main/kotlin/dev/nyon/autodrop/config/ConfigHandler.kt b/src/main/kotlin/dev/nyon/autodrop/config/ConfigHandler.kt index 546559f..96186bd 100644 --- a/src/main/kotlin/dev/nyon/autodrop/config/ConfigHandler.kt +++ b/src/main/kotlin/dev/nyon/autodrop/config/ConfigHandler.kt @@ -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 diff --git a/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt b/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt index 852c03d..166547b 100644 --- a/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt +++ b/src/main/kotlin/dev/nyon/autodrop/config/YaclScreen.kt @@ -117,7 +117,7 @@ private fun ConfigCategory.Builder.appendLockedSlotsOptions(): ConfigCategory.Bu group( ListOption.createBuilder().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() diff --git a/src/main/kotlin/dev/nyon/autodrop/util/IdentifierSerializer.kt b/src/main/kotlin/dev/nyon/autodrop/util/IdentifierSerializer.kt index 299d0da..f344f63 100644 --- a/src/main/kotlin/dev/nyon/autodrop/util/IdentifierSerializer.kt +++ b/src/main/kotlin/dev/nyon/autodrop/util/IdentifierSerializer.kt @@ -18,6 +18,6 @@ object IdentifierSerializer : KSerializer { } override fun deserialize(decoder: Decoder): ResourceLocation { - return ResourceLocation(decoder.decodeString()) + return /*? if >=1.21 {*/ /*ResourceLocation.parse(decoder.decodeString()) *//*?} else {*/ ResourceLocation(decoder.decodeString()) /*?}*/ } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f87ae0b..aed40ad 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -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}" diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 4952f61..f72c03b 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -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" @@ -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 +) + +private data class DiscordWebhook( + val username: String, val avatarUrl: String, val embeds: List +) + +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() + ) +} diff --git a/versions/1.21/gradle.properties b/versions/1.21/gradle.properties new file mode 100644 index 0000000..42c32c4 --- /dev/null +++ b/versions/1.21/gradle.properties @@ -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 \ No newline at end of file