aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 12:34:18 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 12:34:18 +0200
commit4293cfd919c3c93d4532534f722c407d7ad1370d (patch)
treef9f612f021ef7f4283d74312edfaca30badc6749 /src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
parent538e3ceb76f8e0b590291ce9aa90aa94896cdcb6 (diff)
parent024ba52fb69b6cd44b4e31542867f802de656f15 (diff)
downloadSkyHanni-cum.tar.gz
SkyHanni-cum.tar.bz2
SkyHanni-cum.zip
Merge branch 'beta' into cumcum
# Conflicts: # src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt # src/main/java/at/hannibal2/skyhanni/config/features/AshfangConfig.java
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
index d6145fb63..b42a331fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
@@ -1,16 +1,18 @@
package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData
+import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getNameWithEnchantment
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
+import io.github.moulberry.notenoughupdates.events.SlotClickEvent
+import net.minecraft.item.ItemStack
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -18,40 +20,36 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class BazaarBestSellMethod {
private var display = ""
+ // Working with the last clicked item manually because
+ // the open inventory event happen while the recent clicked item in the inventory is not in the inventory or in the cursor slot
+ private var lastClickedItem: ItemStack? = null
+ private var nextCloseWillResetItem = false
+
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
display = ""
+ if (lastClickedItem != null) {
+ if (nextCloseWillResetItem) {
+ lastClickedItem = null
+ }
+ nextCloseWillResetItem = !nextCloseWillResetItem
+ }
}
@SubscribeEvent
- fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent.Post) {
+ fun onBazaarOpenedProduct(event: BazaarOpenedProductEvent) {
if (!isEnabled()) return
- display = getNewText(event)
+ display = updateDisplay(event.openedProduct)
}
- private fun getNewText(event: GuiScreenEvent.DrawScreenEvent.Post): String {
+ private fun updateDisplay(internalName: NEUInternalName): String {
try {
- if (event.gui !is GuiChest) return ""
- val chest = (event.gui as GuiChest).inventorySlots as ContainerChest
-
- val inv = chest.lowerChestInventory ?: return ""
-
- val buyInstantly = inv.getStackInSlot(10)
- if (buyInstantly == null || buyInstantly.displayName != "§aBuy Instantly") return ""
- val bazaarItem = inv.getStackInSlot(13) ?: return ""
-
- val internalName = NEUItems.getInternalNameOrNull(bazaarItem.displayName) ?: return ""
-
- var having = 0
- for (slot in chest.inventorySlots) {
- if (slot == null) continue
- if (slot.slotNumber == slot.slotIndex) continue
- val stack = slot.stack ?: continue
- if (internalName == stack.getInternalName()) {
- having += stack.stackSize
+ var having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName }
+ lastClickedItem?.let {
+ if (it.getInternalName() == internalName) {
+ having += it.stackSize
}
}
-
if (having <= 0) return ""
val data = internalName.getBazaarData() ?: return ""
@@ -73,5 +71,11 @@ class BazaarBestSellMethod {
SkyHanniMod.feature.bazaar.bestSellMethodPos.renderString(display, posLabel = "Bazaar Best Sell Method")
}
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onStackClick(event: SlotClickEvent) {
+ lastClickedItem = event.slot?.stack
+ nextCloseWillResetItem = false
+ }
+
private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.bestSellMethod
} \ No newline at end of file