diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/cheststealer/ModuleChestStealer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/cheststealer/ModuleChestStealer.kt index 253b61f57d8..521436223cb 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/cheststealer/ModuleChestStealer.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/cheststealer/ModuleChestStealer.kt @@ -80,13 +80,10 @@ object ModuleChestStealer : ClientModule("ChestStealer", Category.PLAYER) { } val emptySlot = findEmptyStorageSlotsInInventory().firstOrNull() ?: break - event.schedule(inventoryConstrains, when (itemMoveMode) { - ItemMoveMode.QUICK_MOVE -> listOf(ClickInventoryAction.performQuickMove(screen, slot)) - ItemMoveMode.DRAG_AND_DROP -> listOf( - ClickInventoryAction.performPickup(screen, slot), - ClickInventoryAction.performPickup(screen, emptySlot), - ) - }, + + val actions = getActionsForMove(screen, from = slot, to = emptySlot) + + event.schedule(inventoryConstrains, actions, /** * we prioritize item based on how important it is * for example we should prioritize armor over apples @@ -101,6 +98,23 @@ object ModuleChestStealer : ClientModule("ChestStealer", Category.PLAYER) { } } + /** + * Create a list of actions that will move the item in the slot [from] to the slot [to]. + */ + private fun getActionsForMove( + screen: GenericContainerScreen, + from: ContainerItemSlot, + to: ItemSlot + ): List { + return when (itemMoveMode) { + ItemMoveMode.QUICK_MOVE -> listOf(ClickInventoryAction.performQuickMove(screen, from)) + ItemMoveMode.DRAG_AND_DROP -> listOf( + ClickInventoryAction.performPickup(screen, from), + ClickInventoryAction.performPickup(screen, to), + ) + } + } + /** * @return if we should wait */ @@ -175,8 +189,7 @@ object ModuleChestStealer : ClientModule("ChestStealer", Category.PLAYER) { * we prioritize item based on how important it is * for example we should prioritize armor over apples */ - ItemCategorization(listOf()).getItemFacets(hotbarSwap.from) - .maxOf { it.category.type.allocationPriority } + hotbarSwap.priority ) // todo: hook to schedule and check if swap was successful diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlan.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlan.kt index a5e0951bb38..1a4c5c358e3 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlan.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/CleanupPlan.kt @@ -19,10 +19,11 @@ package net.ccbluex.liquidbounce.features.module.modules.player.invcleaner import net.ccbluex.liquidbounce.utils.inventory.ItemSlot +import net.ccbluex.liquidbounce.utils.kotlin.Priority import net.minecraft.component.ComponentMap import net.minecraft.item.Item -data class InventorySwap(val from: ItemSlot, val to: ItemSlot) +data class InventorySwap(val from: ItemSlot, val to: ItemSlot, val priority: Priority) data class ItemId(val item: Item, val nbt: ComponentMap) @@ -52,11 +53,10 @@ class InventoryCleanupPlan( this.usefulItems.addAll(usefulItemsToAdd) this.swaps.forEachIndexed { index, hotbarSwap -> - val newSwap = - InventorySwap( - slotMap[hotbarSwap.from] ?: hotbarSwap.from, - slotMap[hotbarSwap.to] ?: hotbarSwap.to, - ) + val newSwap = hotbarSwap.copy( + from = slotMap[hotbarSwap.from] ?: hotbarSwap.from, + to = slotMap[hotbarSwap.to] ?: hotbarSwap.to + ) this.swaps[index] = newSwap } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemCategorization.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemCategorization.kt index d378c6ba552..030529dd496 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemCategorization.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemCategorization.kt @@ -64,8 +64,8 @@ enum class ItemType( val providedFunction: ItemFunction? = null ) { ARMOR(true, allocationPriority = Priority.IMPORTANT_FOR_PLAYER_LIFE), - SWORD(true, allocationPriority = Priority.IMPORTANT_FOR_USAGE_2, providedFunction = ItemFunction.WEAPON_LIKE), - WEAPON(true, allocationPriority = Priority.NOT_IMPORTANT, providedFunction = ItemFunction.WEAPON_LIKE), + SWORD(true, allocationPriority = Priority.IMPORTANT_FOR_USAGE_3, providedFunction = ItemFunction.WEAPON_LIKE), + WEAPON(true, allocationPriority = Priority.IMPORTANT_FOR_USAGE_2, providedFunction = ItemFunction.WEAPON_LIKE), BOW(true), CROSSBOW(true), ARROW(true), @@ -146,7 +146,12 @@ class ItemCategorization( ) } - private val bestPiecesIfFullArmor: List + /** + * Sometimes there are situations where armor pieces are not the best ones with the current armor, but become + * the best ones as soon as we upgrade one of the other armor pieces. + * In those cases we don't want to miss out on this armor piece in the future thus we keep it. + */ + private val futureArmorToKeep: List private val armorComparator: ArmorComparator init { @@ -158,7 +163,7 @@ class ItemCategorization( val armorComparatorForFullArmor = ArmorEvaluation.getArmorComparatorForParameters(armorParameterForSlot) - this.bestPiecesIfFullArmor = ArmorEvaluation.findBestArmorPiecesWithComparator( + this.futureArmorToKeep = ArmorEvaluation.findBestArmorPiecesWithComparator( availableItems, armorComparatorForFullArmor ).values.mapNotNull { it?.itemSlot } @@ -178,7 +183,7 @@ class ItemCategorization( val specificItemFacets: Array = when (val item = slot.itemStack.item) { // Treat animal armor as a normal item is AnimalArmorItem -> arrayOf(ItemFacet(slot)) - is ArmorItem -> arrayOf(ArmorItemFacet(slot, this.bestPiecesIfFullArmor, this.armorComparator)) + is ArmorItem -> arrayOf(ArmorItemFacet(slot, this.futureArmorToKeep, this.armorComparator)) is SwordItem -> arrayOf(SwordItemFacet(slot)) is BowItem -> arrayOf(BowItemFacet(slot)) is CrossbowItem -> arrayOf(CrossbowItemFacet(slot)) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt index d974ef33dac..109d208d175 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/ItemPacker.kt @@ -78,7 +78,7 @@ class ItemPacker { val targetSlot = fillItemIntoSlot(filledInItemSlot, leftHotbarSlotIterator) if (targetSlot != null && targetSlot !in forbiddenSlotsToFill) { - moves.add(InventorySwap(filledInItemSlot, targetSlot)) + moves.add(InventorySwap(filledInItemSlot, targetSlot, filledInItem.category.type.allocationPriority)) } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ArmorItemFacet.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ArmorItemFacet.kt index 111a0c26d89..7b534682723 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ArmorItemFacet.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ArmorItemFacet.kt @@ -25,11 +25,11 @@ import net.ccbluex.liquidbounce.utils.item.ArmorComparator import net.ccbluex.liquidbounce.utils.item.ArmorPiece /** - * @param fullArmorKit the armor kit, if the other armor pieces were already the best ones expected (i.e. full dia) + * @param stacksToKeep armor items which should be kept since they might be strong in future situations */ class ArmorItemFacet( itemSlot: ItemSlot, - private val fullArmorKit: List, + private val stacksToKeep: List, private val armorComparator: ArmorComparator ) : ItemFacet(itemSlot) { private val armorPiece = ArmorPiece(itemSlot) @@ -38,10 +38,7 @@ class ArmorItemFacet( get() = ItemCategory(ItemType.ARMOR, armorPiece.entitySlotId) override fun shouldKeep(): Boolean { - // Sometimes there are situations where armor pieces are not the best ones with the current armor, but become - // the best ones as soon as we upgrade one of the other armor pieces. In those cases we don't want to miss out - // on this armor piece in the future thus we keep it. - return this.fullArmorKit.contains(this.itemSlot) + return this.stacksToKeep.contains(this.itemSlot) } override fun compareTo(other: ItemFacet): Int { diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ItemFacet.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ItemFacet.kt index 684d7678d8d..01c441816a0 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ItemFacet.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/invcleaner/items/ItemFacet.kt @@ -23,6 +23,7 @@ import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemFu import net.ccbluex.liquidbounce.utils.inventory.ItemSlot import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlotType import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemType +import net.ccbluex.liquidbounce.utils.kotlin.Priority import net.ccbluex.liquidbounce.utils.sorting.compareValueByCondition import net.minecraft.item.ItemStack