diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 23:30:50 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-12 23:30:50 +0200 |
commit | 167e9fa50f73133223f74d60f3a2e145092265e1 (patch) | |
tree | b4dbedc6f51337a4342d9b9931ef88b10266f2e8 /src/main/java/at/hannibal2/skyhanni/data | |
parent | 8f8df60eb5f8bc69eb76b385f4298d29ca8ca649 (diff) | |
download | skyhanni-167e9fa50f73133223f74d60f3a2e145092265e1.tar.gz skyhanni-167e9fa50f73133223f74d60f3a2e145092265e1.tar.bz2 skyhanni-167e9fa50f73133223f74d60f3a2e145092265e1.zip |
revert InventoryOpenEvent changes in CropAccessoryData that broke the accessory bag detection
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) { |