Skip to content

Commit

Permalink
2.0.0 (#15)
Browse files Browse the repository at this point in the history
* add new logic

* add screen for general options

* screen logic is weird af

* it works ... somehow

* cleanup workflows

* finish ui of custom config screen

* screen finish - no to porting

* remove onJump and onHotbarSwitch

* fix some bugs

* port and drop 1.20.1 support

* add german translations

* update readme and changelog
  • Loading branch information
btwonion authored Jul 10, 2024
1 parent bc93def commit 6337dc3
Show file tree
Hide file tree
Showing 37 changed files with 1,311 additions and 321 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Used when a commit is pushed to the repository
# This makes use of caching for faster builds and uploads the resulting artifacts
name: build-commit

on:
Expand Down Expand Up @@ -43,14 +41,4 @@ jobs:
command: ./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/[email protected]
with:
auth-token: ${{ secrets.MODRINTH_API_KEY }}
slug: 'autodrop'
path: versions/**/build/libs/*.jar
20 changes: 20 additions & 0 deletions .github/workflows/readme-modrinth-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: sync-readme

on:
push:
paths:
- "README.md"
branches:
- main
workflow_dispatch:

jobs:
modrinth-description:
runs-on: ubuntu-latest
name: Sync Modrinth description
steps:
- uses: actions/checkout@v4
- uses: funnyboy-roks/[email protected]
with:
auth-token: ${{ secrets.MODRINTH_API_KEY }}
slug: 'autodrop'
12 changes: 1 addition & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,4 @@ jobs:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_ROLE_ID: ${{ secrets.DISCORD_ROLE_ID }}
NYON_USERNAME: ${{ secrets.NYON_USERNAME }}
NYON_PASSWORD: ${{ secrets.NYON_PASSWORD }}

modrinth-description:
runs-on: ubuntu-latest
name: Sync Modrinth description
steps:
- uses: actions/checkout@v4
- uses: funnyboy-roks/[email protected]
with:
auth-token: ${{ secrets.MODRINTH_API_KEY }}
slug: 'autodrop'
NYON_PASSWORD: ${{ secrets.NYON_PASSWORD }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gradle
build/
.idea/
run/
run/
.kotlin
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ inventory if they are blacklisted. You can easily disable it by pressing a hotke

## Managing items

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

### Component/Nbt filtering

*You have to be careful: Setting the item to null and leaving an empty component will cause the mod to drop every item.*

The format of the components/nbt is always the item command syntax of the version of Minecraft you're playing on.
Unless you know the syntax by heart, you can simply use
a [give command generator](https://www.gamergeeks.net/apps/minecraft/give-command-generator) and copy the component
part (enclosed by `{}` or `[]`).

### Other

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

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -14,8 +14,8 @@ plugins {
signing
}

val beta: Int? = null // Pattern is '1.0.0-beta1-1.20.6-pre.2'
val featureVersion = "1.7.1${if (beta != null) "-beta$beta" else ""}"
val beta: Int? = 1 // Pattern is '1.0.0-beta1-1.20.6-pre.2'
val featureVersion = "2.0.0${if (beta != null) "-beta$beta" else ""}"
val mcVersion = property("mcVersion")!!.toString()
val mcVersionRange = property("mcVersionRange")!!.toString()
version = "$featureVersion-$mcVersion"
Expand Down Expand Up @@ -109,7 +109,8 @@ tasks {

val changelogText = buildString {
append("# v${project.version}\n")
file("../../changelog.md").readText().also(::append)
if (beta != null) append("### 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> =
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- fix config screen on 1.20.6
- add new ui for configuring the archives
- now support nbt/component filters and filter for amounts
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pluginManagement {
}

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


Expand All @@ -27,7 +27,7 @@ extensions.configure<StonecutterSettings> {
kotlinController = true
centralScript = "build.gradle.kts"
shared {
versions("1.20.1", "1.20.4", "1.20.6", "1.21")
versions("1.20.4", "1.20.6", "1.21")
vcsVersion = "1.21"
}
create(rootProject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.nyon.autodrop.mixins;

import dev.nyon.autodrop.AutoDrop;
import dev.nyon.autodrop.config.ConfigHandlerKt;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -10,29 +11,33 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Inventory.class)
public class PlayerInventoryMixin {
public class InventoryMixin {

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

@Inject(
method = "setItem",
at = @At(value = "RETURN")
)
public void onTake(
public void invokeOnTake(
int i,
ItemStack itemStack,
CallbackInfo ci
) {
AutoDrop.INSTANCE.onTake();
if (ConfigHandlerKt.getConfig()
.getTriggerConfig()
.getOnPickup()) AutoDrop.INSTANCE.invokeAutodrop();
}
}
32 changes: 32 additions & 0 deletions src/main/java/dev/nyon/autodrop/mixins/PlayerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.nyon.autodrop.mixins;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.nyon.autodrop.AutoDrop;
import dev.nyon.autodrop.config.ConfigHandlerKt;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(Player.class)
public class PlayerMixin {

@WrapOperation(
method = "updatePlayerPose",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;setPose(Lnet/minecraft/world/entity/Pose;)V"
)
)
private void invokeOnCrouch(
Player instance,
Pose pose,
Operation<Void> original
) {
if (ConfigHandlerKt.getConfig()
.getTriggerConfig()
.getOnSneak() && pose == Pose.CROUCHING) AutoDrop.INSTANCE.invokeAutodrop();
original.call(instance, pose);
}
}
117 changes: 83 additions & 34 deletions src/main/kotlin/dev/nyon/autodrop/AutoDrop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package dev.nyon.autodrop

import com.mojang.blaze3d.platform.InputConstants
import dev.nyon.autodrop.config.*
import dev.nyon.autodrop.config.models.Config
import dev.nyon.autodrop.config.screen.root.ArchiveScreen
import dev.nyon.autodrop.extensions.DataComponentPatchSerializer
import dev.nyon.autodrop.extensions.ItemSerializer
import dev.nyon.autodrop.extensions.StoredComponents
import dev.nyon.konfig.config.config
import dev.nyon.konfig.config.loadConfig
import dev.nyon.konfig.config.saveConfig
import kotlinx.coroutines.*
import kotlinx.serialization.modules.SerializersModule
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper
import net.fabricmc.loader.api.FabricLoader
Expand All @@ -17,56 +21,99 @@ import net.minecraft.network.chat.Component
import net.minecraft.network.chat.Style
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.ClickType
import net.minecraft.world.item.Item
import org.lwjgl.glfw.GLFW
import kotlin.time.Duration.Companion.milliseconds

lateinit var mcDispatcher: CoroutineDispatcher
//? if >=1.20.5
import net.minecraft.world.item.enchantment.ItemEnchantments

lateinit var mcScope: CoroutineScope
lateinit var minecraft: Minecraft

object AutoDrop : ClientModInitializer {
private val toggleKeyBind = KeyBindingHelper.registerKeyBinding(
KeyMapping(
"Toggle AutoDrop", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_J, "autodrop"
)
)

private val menuKeyBind = KeyBindingHelper.registerKeyBinding(
KeyMapping(
"Open GUI", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "autodrop"
)
)
private val toggleKeyBind =
KeyMapping("key.autodrop.toggle", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.autodrop.category")
private val menuKeyBind =
KeyMapping("key.autodrop.gui", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "key.autodrop.category")

fun tick(client: Minecraft) {
if (toggleKeyBind.consumeClick()) {
settings.enabled = !settings.enabled
saveConfig(settings)
config.enabled = !config.enabled
saveConfig(config)
client.gui.setOverlayMessage(
Component.translatable("menu.autodrop.name").append(" ").append(
Component.translatable(if (settings.enabled) "menu.autodrop.overlay.enabled" else "menu.autodrop.overlay.disabled")
).withStyle(Style.EMPTY.withColor(0xF99147)), false
Component.translatable(if (config.enabled) "menu.autodrop.overlay.enabled" else "menu.autodrop.overlay.disabled")
).withStyle(Style.EMPTY.withColor(0xF99147)), false
)
if (settings.enabled) onTake()
if (config.enabled) invokeAutodrop()
}
if (menuKeyBind.consumeClick()) client.setScreen(createYaclScreen(null))
if (menuKeyBind.consumeClick()) client.setScreen(ArchiveScreen(null))
}

private var jobWaiting = false

fun onTake() = runBlocking {
if (!settings.enabled) return@runBlocking
if (settings.activeArchives.isEmpty()) return@runBlocking
val player = minecraft.player ?: return@runBlocking
fun invokeAutodrop() = runBlocking {
if (jobWaiting) return@runBlocking
if (!config.enabled) return@runBlocking
if (currentItems.isEmpty()) return@runBlocking
val player = minecraft.player ?: return@runBlocking
if (config.triggerConfig.onSneak && !player.isCrouching) return@runBlocking
jobWaiting = true

mcScope.launch {
delay(settings.dropDelay.milliseconds)
delay(config.dropDelay.milliseconds)

val screen = InventoryScreen(player)
screen.menu.slots.filter {
it.hasItem() && !blockedSlots.contains(it.index) && currentItems.contains(it.item.item) && it.container is Inventory
it.hasItem() && !ignoredSlots.contains(it.index) && it.container is Inventory
}.forEach { slot ->
val itemStack = slot.item
val isValid = currentItems.any { identifier ->
val typeValid = identifier.type == null || itemStack.item == identifier.type
val amountValid = itemStack.count >= identifier.amount

/*? if >=1.21 {*/val componentValid =
identifier.components.isEmpty || identifier.components.entrySet().all { (key, component) ->
val identifierComponent = component.get()
val itemComponent = itemStack.get(key) ?: return@all false

if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().description.string }
.contains(entry.key.value().description.string)
}
}

itemComponent == identifierComponent
}
/*?} else if >=1.20.5 {*//*val componentValid = identifier.components.isEmpty || identifier.components.all { component ->
val identifierComponent = component.value
val itemComponent = itemStack.get(component.type) ?: return@all false
if (identifierComponent as? ItemEnchantments != null && itemComponent as? ItemEnchantments != null) {
return@all identifierComponent.entrySet()
.all { entry -> // How tf is minecraft too bad to create a simple equals check - or is it me?
itemComponent.entrySet().map { it.key.value().descriptionId }
.contains(entry.key.value().descriptionId)
}
}
itemComponent == identifierComponent
}
*//*?} else {*/
/*val componentValid = identifier.components.allKeys.all { key ->
if (itemStack.tag == null) return@all false
itemStack.tag!!.get(key) == identifier.components.get(key)
}*//*?}*/
typeValid && amountValid && componentValid
}


if (!isValid) return@forEach

minecraft.gameMode?.handleInventoryMouseClick(
screen.menu.containerId, slot.index, 1, ClickType.THROW, player
)
Expand All @@ -77,16 +124,18 @@ object AutoDrop : ClientModInitializer {
}

override fun onInitializeClient() {
KeyBindingHelper.registerKeyBinding(menuKeyBind)
KeyBindingHelper.registerKeyBinding(toggleKeyBind)
minecraft = Minecraft.getInstance()
mcDispatcher = minecraft.asCoroutineDispatcher()
mcScope = CoroutineScope(SupervisorJob() + mcDispatcher)

config(
FabricLoader.getInstance().configDir.resolve("autodrop.json"),
1,
Config()
) { jsonTree, version -> migrate(jsonTree, version) }
settings = loadConfig<Config>()
mcScope = CoroutineScope(SupervisorJob() + minecraft.asCoroutineDispatcher())

config(FabricLoader.getInstance().configDir.resolve("autodrop.json"), 1, Config(), jsonBuilder = {
serializersModule = SerializersModule {
contextual(Item::class, ItemSerializer)
contextual(StoredComponents::class, DataComponentPatchSerializer)
}
}) { jsonTree, version -> migrate(jsonTree, version) }
config = loadConfig<Config>()

reloadArchiveProperties()
}
Expand Down
Loading

0 comments on commit 6337dc3

Please sign in to comment.