Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiversion support #13

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
433 changes: 401 additions & 32 deletions .editorconfig

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.gradle
/build/
build/
.idea/
run/
lib/
run/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# autodrop

This mod provides a function to automatically drop items from the
inventory if they are blacklisted. You can easily disable it by pressing a hotkey (`default: j`).

## Managing items

- use the configuration section of the modmenu integration
- press the keybinding for the config GUI (`default: o`)
- archives can be toggled by double-clicking the archive in the GUI

### Other
⚠️ The development version is always the latest stable release of Minecraft.
Therefore, new features will only be available for the current and following Minecraft versions.

If you need help with any of my mods just join my [discord server](https://nyon.dev/discord)
178 changes: 105 additions & 73 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
@file:Suppress("SpellCheckingInspection")

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import kotlin.io.path.readText

plugins {
kotlin("jvm") version "1.9.23"
kotlin("plugin.serialization") version "1.9.23"
kotlin("jvm") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24"
id("fabric-loom") version "1.6-SNAPSHOT"

id("com.modrinth.minotaur") version "2.8.7"
id("com.github.breadmoirai.github-release") version "2.5.2"
id("me.modmuss50.mod-publish-plugin") version "0.5.+"

`maven-publish`
signing
}

val featureVersion = "1.6.2"
val mcVersion = property("mcVersion")!!.toString()
val mcVersionRange = property("mcVersionRange")!!.toString()
version = "$featureVersion-$mcVersion"

group = "dev.nyon"
val majorVersion = "1.6.2"
val mcVersion = "24w13a"
version = "$majorVersion-$mcVersion"
val authors = listOf("btwonion")
val githubRepo = "btwonion/autodrop"

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

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

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

mixin { useLegacyMixinAp = false }
}

repositories {
mavenCentral()
maven("https://maven.terraformersmc.com")
Expand All @@ -32,117 +49,115 @@

dependencies {
minecraft("com.mojang:minecraft:$mcVersion")
mappings(
loom.layered {
parchment("org.parchmentmc.data:parchment-1.20.4:2024.02.25@zip")
officialMojangMappings()
}
)
mappings(loom.layered {

Check failure on line 52 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L52 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
build.gradle.kts:52:14: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)

Check failure on line 52 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L52 <standard:wrapping>

Missing newline after "("
Raw output
build.gradle.kts:52:14: error: Missing newline after "(" (standard:wrapping)
parchment("org.parchmentmc.data:parchment-${property("deps.parchment")}@zip")
officialMojangMappings()
})

Check failure on line 55 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L55 <standard:wrapping>

Missing newline before ")"
Raw output
build.gradle.kts:55:5: error: Missing newline before ")" (standard:wrapping)

implementation("org.vineflower:vineflower:1.9.3")
modImplementation("net.fabricmc:fabric-loader:0.15.7")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.96.13+1.20.5")
modImplementation("net.fabricmc:fabric-language-kotlin:1.10.19+kotlin.1.9.23")
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")

modCompileOnly("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.1+1.20.4")
modImplementation("com.terraformersmc:modmenu:10.0.0-alpha.3")
modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}")
modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}")

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

val javaVersion = property("javaVer")!!.toString()
tasks {
processResources {
val modId = "autodrop"
val modName = "autodrop"
val modDescription = "Mod to automatically drop items from your inventory"

inputs.property("id", modId)
inputs.property("name", modName)
inputs.property("description", modDescription)
inputs.property("version", project.version)
inputs.property("github", githubRepo)
val props = mapOf(

Check failure on line 75 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L75 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
build.gradle.kts:75:21: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version,
"github" to githubRepo,
"mc" to mcVersionRange
)

props.forEach(inputs::property)

filesMatching("fabric.mod.json") {
expand(
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version,
"github" to githubRepo
)
expand(props)
}
}

register("releaseMod") {
group = "publishing"

dependsOn("modrinthSyncBody")
dependsOn("modrinth")
dependsOn("githubRelease")
dependsOn("publishMods")
dependsOn("publish")
}

withType<JavaCompile> {
options.release.set(17)
options.release = javaVersion.toInt()
}

withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
kotlinOptions.jvmTarget = javaVersion
}
}

val changelogText =
buildString {
append("# v${project.version}\n")
rootDir.toPath().resolve("changelog.md").readText().also { append(it) }
val changelogText = buildString {

Check failure on line 107 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L107 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
build.gradle.kts:107:21: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
append("# v${project.version}\n")
file("../../changelog.md").readText().also { append(it) }
}

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

publishMods {
displayName = "v${project.version}"
file = tasks.remapJar.get().archiveFile
changelog = changelogText
type = STABLE
modLoaders.addAll("fabric", "quilt")

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

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

modrinth {
token.set(findProperty("modrinth.token")?.toString())
projectId.set("lg17V3i3")
versionNumber.set("${project.version}")
versionType.set("release")
uploadFile.set(tasks["remapJar"])
gameVersions.set(listOf(mcVersion))
loaders.set(listOf("fabric", "quilt"))
dependencies {
required.project("fabric-api")
required.project("fabric-language-kotlin")
required.project("yacl")
optional.project("modmenu")
github {
repository = githubRepo
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = "master"
}
changelog.set(changelogText)
syncBodyFrom.set(file("README.md").readText())
}

githubRelease {
token(findProperty("github.token")?.toString())

val split = githubRepo.split("/")
owner = split[0]
repo = split[1]
tagName = "v${project.version}"
body = changelogText
overwrite = true
releaseAssets(tasks["remapJar"].outputs.files)
targetCommitish = "main"
discord {
webhookUrl = providers.environmentVariable("DISCORD_WEBHOOK")
username = "Release Notifier"
content = "# A new version of autodrop released!\n$changelogText\n\n"
}
}

publishing {
repositories {
maven {
name = "nyon"
url = uri("https://repo.nyon.dev/releases")
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
credentials {
username = providers.environmentVariable("NYON_USERNAME").orNull
password = providers.environmentVariable("NYON_PASSWORD").orNull
}
}
}
publications {
create<MavenPublication>("maven") {
groupId = "dev.nyon"
artifactId = "autodrop"
artifactId = "better-boat-movement"
version = project.version.toString()
from(components["java"])
}
Expand All @@ -151,8 +166,25 @@

java {
withSourcesJar()

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

Check failure on line 171 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L171 <standard:indent>

Unexpected indentation (12) (should be 8)
Raw output
build.gradle.kts:171:1: error: Unexpected indentation (12) (should be 8) (standard:indent)
targetCompatibility = it

Check failure on line 172 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L172 <standard:indent>

Unexpected indentation (12) (should be 8)
Raw output
build.gradle.kts:172:1: error: Unexpected indentation (12) (should be 8) (standard:indent)
}

Check failure on line 173 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L173 <standard:indent>

Unexpected indentation (8) (should be 4)
Raw output
build.gradle.kts:173:1: error: Unexpected indentation (8) (should be 4) (standard:indent)
}

kotlin {
jvmToolchain(javaVersion.toInt())
}

/*
signing {
val signingKey: String? by project
val signingPassword: String? by project
useGpgCmd()
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(publishing.publications)
}
*/

Check failure on line 190 in build.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] build.gradle.kts#L190 <standard:final-newline>

Redundant newline (\n) at the end of file
Raw output
build.gradle.kts:190:4: error: Redundant newline (\n) at the end of file (standard:final-newline)
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- cleanup code
- update to 1.20.5
- support 1.20.1, 1.20.4, 1.20.6
- remove migrator for old config
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
kotlin.code.style=official

org.gradle.jvmargs=-Xmx4096M
17 changes: 17 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import dev.kikugie.stonecutter.gradle.StonecutterSettings

rootProject.name = "autodrop"

pluginManagement {
repositories {
gradlePluginPortal()
maven("https://maven.fabricmc.net/")
maven("https://server.bbkr.space/artifactory/libs-release/")
maven("https://maven.kikugie.dev/releases")
}
}

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

extensions.configure<StonecutterSettings> {
kotlinController = true
centralScript = "build.gradle.kts"
shared {
versions("1.20.1", "1.20.4", "1.20.6")
vcsVersion = "1.20.6"
}
create(rootProject)
}

Check failure on line 26 in settings.gradle.kts

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] settings.gradle.kts#L26 <standard:final-newline>

Redundant newline (\n) at the end of file
Raw output
settings.gradle.kts:26:2: error: Redundant newline (\n) at the end of file (standard:final-newline)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@Mixin(Minecraft.class)
public class MinecraftClientMixin {

@Inject(method = "tick", at = @At("TAIL"))
@Inject(
method = "tick",
at = @At("TAIL")
)
public void onTick(CallbackInfo ci) {
AutoDrop.INSTANCE.tick((Minecraft) (Object) this);
}
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/dev/nyon/autodrop/mixins/PlayerInventoryMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
@Mixin(Inventory.class)
public class PlayerInventoryMixin {

@Inject(method = "add(ILnet/minecraft/world/item/ItemStack;)Z", at = @At(value = "RETURN"))
public void onTake(int slot, ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
@Inject(
method = "add(ILnet/minecraft/world/item/ItemStack;)Z",
at = @At(value = "RETURN")
)
public void onTake(
int slot,
ItemStack stack,
CallbackInfoReturnable<Boolean> cir
) {
AutoDrop.INSTANCE.onTake();
}

@Inject(method = "setItem", at = @At(value = "RETURN"))
public void onTake(int i, ItemStack itemStack, CallbackInfo ci) {
@Inject(
method = "setItem",
at = @At(value = "RETURN")
)
public void onTake(
int i,
ItemStack itemStack,
CallbackInfo ci
) {
AutoDrop.INSTANCE.onTake();
}
}
Loading
Loading