From 76d9ac63df01111c0f067fb9f50ebbbc8a8a7d41 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 18 May 2023 12:37:20 +0200 Subject: Reading the current pet additionally from the pet inventory Fixes #111 --- .../skyhanni/features/misc/CurrentPetDisplay.kt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt index bb21b7da6..936aa04ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt @@ -3,10 +3,13 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.between import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -38,6 +41,24 @@ class CurrentPetDisplay { } } + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + val config = ProfileStorageData.profileSpecific ?: return + + val inventoryNamePattern = "(?:\\(\\d+/\\d+\\))? Pets".toPattern() + if (!inventoryNamePattern.matcher(event.inventoryName).matches()) return + + val lore = event.inventoryItems[4]?.getLore() ?: return + val selectedPetPattern = "§7§7Selected pet: (?.*)".toPattern() + for (line in lore) { + selectedPetPattern.matchMatcher(line) { + val newPet = group("pet") + config.currentPet = if (newPet != "§cNone") newPet else "" + } + } + } + + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!LorenzUtils.inSkyBlock) return -- cgit