diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt | 26 |
1 files changed, 17 insertions, 9 deletions
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) { |