Skip to content

Commit

Permalink
add support for armour and bits
Browse files Browse the repository at this point in the history
simplify the code by not checking 9th slot instead of checking every item to see if it is blacklisted
  • Loading branch information
catgirlseraid committed Oct 25, 2024
1 parent 0507e8b commit 4ca75ad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Int, Pair<ItemStack, Int>>()
private var itemsAddedToInventory = mutableMapOf<Int, PickupEntry>()
private var itemsRemovedFromInventory = mutableMapOf<Int, PickupEntry>()
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -331,6 +335,36 @@ object ItemPickupLog {
}
}

// private fun getInventoryItems(): MutableList<ItemStack> {
// val inventoryItems = mutableListOf<ItemStack>()
//
// 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<ItemStack> {
val inventoryItems = mutableListOf<ItemStack>()
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<Renderable>,
removedItems: MutableMap<Int, PickupEntry>,
Expand Down

0 comments on commit 4ca75ad

Please sign in to comment.