From 4ca75ad22d76d10fad04305f5d1a42a0b540bf4e Mon Sep 17 00:00:00 2001 From: catgirlseraid <77941535+catgirlseraid@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:50:29 +1300 Subject: [PATCH] add support for armour and bits simplify the code by not checking 9th slot instead of checking every item to see if it is blacklisted --- .../inventory/ItemPickupLogConfig.java | 14 ++++- .../features/inventory/ItemPickupLog.kt | 62 ++++++++++++++----- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java index 3e557a4a35e8..7d4b6ba5c793 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/ItemPickupLogConfig.java @@ -37,12 +37,22 @@ public class ItemPickupLogConfig { @Expose @ConfigOption(name = "Sacks", desc = "Show items added and removed from sacks.") @ConfigEditorBoolean - public boolean sack = false; + public boolean sack = true; @Expose @ConfigOption(name = "Coins", desc = "Show coins added and removed from purse.") @ConfigEditorBoolean - public boolean coins = false; + public boolean coins = true; + + @Expose + @ConfigOption(name = "Bits", desc = "Show bits added and removed from balance.") + @ConfigEditorBoolean + public boolean bits = true; + + @Expose + @ConfigOption(name = "Armour", desc = "Include armour in the pickup log.") + @ConfigEditorBoolean + public boolean armour = false; @Expose @ConfigOption( diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt index 12b3e9495d63..a1326b8d2a39 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemPickupLog.kt @@ -24,7 +24,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -78,8 +77,12 @@ object ItemPickupLog { } private val config get() = SkyHanniMod.feature.inventory.itemPickupLogConfig + private val coinIcon = "COIN_TALISMAN".asInternalName() + private const val COIN_HASH = 0 + private const val BITS_HASH = 1 + private var itemList = mutableMapOf>() private var itemsAddedToInventory = mutableMapOf() private var itemsRemovedFromInventory = mutableMapOf() @@ -136,6 +139,18 @@ object ItemPickupLog { updateItem(0, PickupEntry("§6Coins", event.coins.absoluteValue.toLong(), coinIcon), coinIcon.getItemStack(), event.coins < 0) } + //TODO commented out for now as this event doesn't work in testing +// @SubscribeEvent +// fun onBitsChange(event: BitsUpdateEvent) { +// //TODO not sure if this event returns negative bits when spent +// //TODO update this event doesn't fire at all +// if (!isEnabled() || !config.bits || !worldChangeCooldown()) return +// updateItem(1, PickupEntry("§9Bits", event.difference.absoluteValue.toLong(), coinIcon), coinIcon.getItemStack(), event.difference < 0) +// +// println(event) +// } + + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return @@ -146,7 +161,7 @@ object ItemPickupLog { if (!InventoryUtils.inInventory()) { itemList.clear() - val inventoryItems = InventoryUtils.getItemsInOwnInventory().toMutableList() + val inventoryItems = getInventoryItems() val cursorItem = Minecraft.getMinecraft().thePlayer?.inventory?.itemStack if (cursorItem != null) { @@ -184,7 +199,7 @@ object ItemPickupLog { // TODO merge with ItemAddInInventoryEvent private fun updateItem(hash: Int, itemInfo: PickupEntry, item: ItemStack, removed: Boolean) { - if (isBannedItem(item)) return +// if (isBannedItem(item)) return val targetInventory = if (removed) itemsRemovedFromInventory else itemsAddedToInventory val oppositeInventory = if (removed) itemsAddedToInventory else itemsRemovedFromInventory @@ -231,17 +246,6 @@ object ItemPickupLog { } } - private fun isBannedItem(item: ItemStack): Boolean { - val internalName = item.getInternalNameOrNull() ?: return true - if (internalName.startsWith("MAP") == true) return true - if (internalName in bannedItemsConverted) return true - - if (item.getExtraAttributes()?.hasKey("quiver_arrow") == true) { - return true - } - return false - } - private fun ItemStack.dynamicName(): String { val compact = when (getItemCategoryOrNull()) { ItemCategory.ENCHANTED_BOOK -> true @@ -331,6 +335,36 @@ object ItemPickupLog { } } +// private fun getInventoryItems(): MutableList { +// val inventoryItems = mutableListOf() +// +// for (i in 0..39) { +// if (i == 8) continue +// Minecraft.getMinecraft().thePlayer?.inventory?.getStackInSlot(i)?.let { inventoryItems.add(it) } +// } +// +// return inventoryItems +// } + + private fun getInventoryItems(): MutableList { + val inventoryItems = mutableListOf() + val player = Minecraft.getMinecraft().thePlayer + + player?.inventory?.mainInventory?.forEachIndexed { index, itemStack -> + if (index != 8 && itemStack != null) { + inventoryItems.add(itemStack) + } + } + + if (config.armour) { + player?.inventory?.armorInventory?.forEach { itemStack -> + inventoryItems.add(itemStack) + } + } + + return inventoryItems + } + private fun addRemainingRemovedItems( display: MutableList, removedItems: MutableMap,