Skip to content

Commit

Permalink
fix isPetMenu usages
Browse files Browse the repository at this point in the history
  • Loading branch information
martimavocado committed Oct 20, 2024
1 parent d04ad5d commit d58dd48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.extraAttributes
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzRarity
Expand All @@ -31,13 +30,13 @@ import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.hasGroup
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes
import at.hannibal2.skyhanni.utils.StringUtils.convertToUnformatted
import at.hannibal2.skyhanni.utils.chat.Text.hover
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.Gson
import com.google.gson.JsonObject
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
Expand Down Expand Up @@ -403,7 +402,7 @@ object PetAPI {
}

private fun getPetDataFromItem(item: ItemStack) {
val (_, _, rarity, petItem, _, petXP, _) = parsePetNBT(item.extraAttributes)
val (_, _, rarity, petItem, _, petXP, _) = parsePetNBT(item)
val (internalName, name, _, _, level, _, skin) = parsePetName(item.displayName) ?: return

val newPet = PetData(
Expand All @@ -418,13 +417,10 @@ object PetAPI {
updatePet(newPet)
}

private fun parsePetNBT(nbt: NBTTagCompound): PetData {
val jsonString = nbt.getString("petInfo")
.replace("\\", "")
.removePrefix("\"")
.removeSuffix("\"")
val petInfo = Gson().fromJson(jsonString, PetNBT::class.java)
private fun parsePetNBT(item: ItemStack): PetData {
val petInfo = Gson().fromJson(item.getExtraAttributes()?.getString("petInfo"), PetNBT::class.java)

println(petInfo)
val rarity = LorenzRarity.getByName(petInfo.tier) ?: ErrorManager.skyHanniError(
"Couldn't parse pet rarity.",
Pair("petNBT", petInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ object CaptureFarmingGear {
val storage = GardenAPI.storage?.fortune ?: return
val outdatedItems = outdatedItems ?: return
val items = event.inventoryItems
if (PetAPI.isPetMenu(event.inventoryName)) {
if (PetAPI.isPetMenu(event.inventoryName, event.inventoryItems)) {
pets(items, outdatedItems)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object CurrentPetDisplay {

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!PetAPI.isPetMenu(event.inventoryName)) return
if (!PetAPI.isPetMenu(event.inventoryName, event.inventoryItems)) return

val lore = event.inventoryItems[4]?.getLore() ?: return
lore.matchFirst(inventorySelectedPetPattern) {
Expand Down

0 comments on commit d58dd48

Please sign in to comment.