aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusChestTracker.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt7
7 files changed, 38 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
index f72d2d5d2..6f96cafc1 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
@@ -331,6 +331,11 @@ object SackAPI {
var price: Long = 0,
var magmaFish: Long = 0,
)
+
+ fun NEUInternalName.getAmountInSacksOrNull(): Long? =
+ fetchSackItem(this).takeIf { it.statusIsCorrectOrAlright() }?.amount
+
+ fun NEUInternalName.getAmountInSacks(): Long = getAmountInSacksOrNull() ?: 0
}
data class SackItem(
diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusChestTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusChestTracker.kt
index 082175794..5584ee216 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusChestTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/CroesusChestTracker.kt
@@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.DungeonStorage.DungeonRunInfo
import at.hannibal2.skyhanni.data.ProfileStorageData
-import at.hannibal2.skyhanni.data.SackAPI
+import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.events.DungeonCompleteEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.events.RenderItemTipEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI.DungeonChest
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
@@ -89,7 +90,9 @@ class CroesusChestTracker {
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
- if ((SkyHanniMod.feature.dungeon.croesusUnopenedChestTracker || config.showUsedKismets) && croesusPattern.matches(event.inventoryName)) {
+ if ((SkyHanniMod.feature.dungeon.croesusUnopenedChestTracker || config.showUsedKismets) &&
+ croesusPattern.matches(event.inventoryName)
+ ) {
pageSetup(event)
if (croesusEmpty) {
@@ -238,9 +241,7 @@ class CroesusChestTracker {
private fun getKismetUsed(runIndex: Int) = getRun0(runIndex)?.kismetUsed ?: false
- private fun getKismetAmount() =
- (SackAPI.fetchSackItem(kismetInternalName).takeIf { it.statusIsCorrectOrAlright() }?.amount
- ?: 0) + InventoryUtils.getAmountOfItemInInventory(kismetInternalName)
+ private fun getKismetAmount() = kismetInternalName.getAmountInSacks() + kismetInternalName.getAmountInInventory()
private fun croesusSlotMapToRun(slotId: Int) = when (slotId) {
in 10..16 -> slotId - 10 // 0 - 6
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
index 979e661b2..4173e7e0d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt
@@ -4,8 +4,7 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig
import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig.OverlayPriceTypeEntry
import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig.RetrieveFromEntry
-import at.hannibal2.skyhanni.data.SackAPI
-import at.hannibal2.skyhanni.data.SackStatus
+import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacksOrNull
import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson
import at.hannibal2.skyhanni.data.model.ComposterUpgrade
import at.hannibal2.skyhanni.events.GuiRenderEvent
@@ -25,7 +24,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.ConfigUtils
-import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -479,18 +478,15 @@ object ComposterOverlay {
BazaarApi.searchForBazaarItem(itemName, itemsNeeded)
return
}
- val having = InventoryUtils.getAmountOfItemInInventory(internalName)
- if (having >= itemsNeeded) {
+ val havingInInventory = internalName.getAmountInInventory()
+ if (havingInInventory >= itemsNeeded) {
ChatUtils.chat("$itemName §8x${itemsNeeded} §ealready found in inventory!")
return
}
- val sackItem = SackAPI.fetchSackItem(internalName)
- val amountInSacks = sackItem.amount
- val sackStatus = sackItem.getStatus()
-
- if (sackStatus == SackStatus.MISSING || sackStatus == SackStatus.OUTDATED) {
- ChatUtils.sendCommandToServer("gfs ${internalName.asString()} ${itemsNeeded - having}")
+ val havingInSacks = internalName.getAmountInSacksOrNull()
+ if (havingInSacks == null) {
+ ChatUtils.sendCommandToServer("gfs ${internalName.asString()} ${itemsNeeded - havingInInventory}")
// TODO Add sack type repo data
val isDwarvenMineable =
@@ -501,7 +497,7 @@ object ComposterOverlay {
"sax"
)
return
- } else if (amountInSacks == 0L) {
+ } else if (havingInSacks == 0L) {
SoundUtils.playErrorSound()
if (LorenzUtils.noTradeMode) {
ChatUtils.chat("No $itemName §efound in sacks.")
@@ -512,8 +508,8 @@ object ComposterOverlay {
return
}
- ChatUtils.sendCommandToServer("gfs ${internalName.asString()} ${itemsNeeded - having}")
- if (amountInSacks <= itemsNeeded - having) {
+ ChatUtils.sendCommandToServer("gfs ${internalName.asString()} ${itemsNeeded - havingInInventory}")
+ if (itemsNeeded > havingInInventory - havingInSacks) {
if (LorenzUtils.noTradeMode) {
ChatUtils.chat("You're out of $itemName §ein your sacks!")
} else {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 3ebb8e5be..e513ff98f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -3,8 +3,8 @@ package at.hannibal2.skyhanni.features.garden.visitor
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig.HighlightMode
import at.hannibal2.skyhanni.data.IslandType
-import at.hannibal2.skyhanni.data.SackAPI
-import at.hannibal2.skyhanni.data.SackStatus
+import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
+import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacksOrNull
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -30,7 +30,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.EntityUtils
-import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemBlink
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
@@ -200,12 +200,9 @@ class GardenVisitorFeatures {
}
if (config.shoppingList.showSackCount) {
- val sackItemData = SackAPI.fetchSackItem(internalName)
- val itemStatus = sackItemData.getStatus()
- val itemAmount = sackItemData.amount
- if (itemStatus != SackStatus.OUTDATED) {
- val textColour = if (itemAmount >= amount) "a" else "e"
- list.add(" §7(§${textColour}x${sackItemData.amount.addSeparators()} §7in sacks)")
+ internalName.getAmountInSacksOrNull()?.let {
+ val textColour = if (it >= amount) "a" else "e"
+ list.add(" §7(§${textColour}x${it.addSeparators()} §7in sacks)")
}
}
@@ -537,13 +534,7 @@ class GardenVisitorFeatures {
private fun hasItems(visitor: VisitorAPI.Visitor): Boolean {
var ready = true
for ((internalName, required) in visitor.shoppingList) {
- val inventoryAmount = InventoryUtils.getAmountOfItemInInventory(internalName)
-
- val sackItemData = SackAPI.fetchSackItem(internalName)
- val sacksAmount = sackItemData.amount
-
- val having = inventoryAmount + sacksAmount
-
+ val having = internalName.getAmountInInventory() + internalName.getAmountInSacks()
if (having < required) {
ready = false
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
index 4e6761066..3a22672b6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarBestSellMethod.kt
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarDataOrError
-import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -48,7 +48,7 @@ class BazaarBestSellMethod {
if (internalName == null) {
return "§cUnknown Bazaar item!"
}
- var having = InventoryUtils.getAmountOfItemInInventory(internalName)
+ var having = internalName.getAmountInInventory()
lastClickedItem?.let {
if (it.getInternalName() == internalName) {
having += it.stackSize
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt
index b443997c1..580fdbc56 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt
@@ -3,8 +3,7 @@ package at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
import at.hannibal2.skyhanni.data.IslandType
-import at.hannibal2.skyhanni.data.SackAPI
-import at.hannibal2.skyhanni.data.SackStatus
+import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacksOrNull
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -221,22 +220,14 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) {
}
val sacksText = if (quest is FetchQuest && quest.state != QuestState.COLLECTED) {
- val sackItem = SackAPI.fetchSackItem(quest.displayItem)
- val sackStatus = sackItem.getStatus()
-
- if (sackStatus == SackStatus.OUTDATED) {
- " §7(§eSack data outdated§7)"
- } else {
- val amountInSacks = sackItem.amount
- val needAmount = quest.needAmount
-
- val color = if (amountInSacks >= needAmount) {
+ quest.displayItem.getAmountInSacksOrNull()?.let {
+ val color = if (it >= quest.needAmount) {
"§a"
} else {
"§c"
}
- " §7($color${amountInSacks.addSeparators()} §7in sacks)"
- }
+ " §7($color${it.addSeparators()} §7in sacks)"
+ } ?: " §7(§eSack data outdated/missing§7)"
} else {
""
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
index 3566761b2..610a0c270 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
@@ -76,10 +76,7 @@ object InventoryUtils {
return screen.slotUnderMouse.inventory is InventoryPlayer && screen.slotUnderMouse.stack == itemStack
}
- fun getAmountOfItemInInventory(name: NEUInternalName) =
- countItemsInLowerInventory { it.getInternalNameOrNull() == name }
-
- fun isItemInInventory(name: NEUInternalName) = getAmountOfItemInInventory(name) > 0
+ fun isItemInInventory(name: NEUInternalName) = name.getAmountInInventory() > 0
fun ContainerChest.getUpperItems(): Map<Slot, ItemStack> = buildMap {
for ((slot, stack) in getAllItems()) {
@@ -102,4 +99,6 @@ object InventoryUtils {
this[slot] = stack
}
}
+
+ fun NEUInternalName.getAmountInInventory(): Int = countItemsInLowerInventory { it.getInternalNameOrNull() == this }
}