From 167e9fa50f73133223f74d60f3a2e145092265e1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 12 Apr 2023 23:30:50 +0200 Subject: revert InventoryOpenEvent changes in CropAccessoryData that broke the accessory bag detection --- .../hannibal2/skyhanni/data/CropAccessoryData.kt | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt index ea50257c3..48b1c67b1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.NEUItems import com.google.gson.JsonElement import net.minecraft.item.ItemStack import net.minecraft.nbt.CompressedStreamTools +import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import java.io.ByteArrayInputStream @@ -46,13 +47,25 @@ class CropAccessoryData { // Handle accessory bag detection @SubscribeEvent - fun onGuiDraw(event: InventoryOpenEvent) { + fun onInventoryOpen(event: InventoryOpenEvent) { val groups = accessoryBagNamePattern.matchEntire(event.inventoryName)?.groups ?: return + isLoadingAccessories = true accessoryBagPageCount = groups[2]!!.value.toInt() accessoryBagPageNumber = groups[1]!!.value.toInt() - isLoadingAccessories = true + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + isLoadingAccessories = false + } - val bestCropAccessoryPage = bestCropAccessory(event.inventoryItems.values) + @SubscribeEvent + fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent) { + if (!isLoadingAccessories) return + val items = runCatching { + InventoryUtils.getItemsInOpenChest() + }.getOrNull() ?: return + val bestCropAccessoryPage = bestCropAccessory(items.map { it.stack }) accessoryPage[accessoryBagPageNumber] = bestCropAccessoryPage if (accessoryBagPageCount == accessoryPage.size) { accessoryInBag = accessoryPage.values.max().also { @@ -62,11 +75,6 @@ class CropAccessoryData { } } - @SubscribeEvent - fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { - isLoadingAccessories = false - } - // Handle inventory detection @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { -- cgit