Skip to content

Commit

Permalink
Improved auto armor structure (#5602)
Browse files Browse the repository at this point in the history
  • Loading branch information
superblaubeere27 authored Feb 12, 2025
1 parent d4bb145 commit 1d58487
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ClickInventoryAction> {
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
*/
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -146,7 +146,12 @@ class ItemCategorization(
)
}

private val bestPiecesIfFullArmor: List<ItemSlot>
/**
* 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<ItemSlot>
private val armorComparator: ArmorComparator

init {
Expand All @@ -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 }
Expand All @@ -178,7 +183,7 @@ class ItemCategorization(
val specificItemFacets: Array<ItemFacet> = 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemSlot>,
private val stacksToKeep: List<ItemSlot>,
private val armorComparator: ArmorComparator
) : ItemFacet(itemSlot) {
private val armorPiece = ArmorPiece(itemSlot)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1d58487

Please sign in to comment.