From da27cfe31d4c75143bc914ef3a62ac13cf9ce369 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:03:06 +0100 Subject: Fix: Fixed Bits to claim & current power (#1189) Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/BitsAPI.kt | 21 +++++++++----- .../java/at/hannibal2/skyhanni/data/MaxwellAPI.kt | 32 ++++++++++++++++------ 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt index 2802399bf..d8b45ddb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt @@ -20,7 +20,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object BitsAPI { private val profileStorage get() = ProfileStorageData.profileSpecific?.bits private val playerStorage get() = SkyHanniMod.feature.storage - + var bits: Int get() = profileStorage?.bits ?: 0 private set(value) { @@ -146,14 +146,21 @@ object BitsAPI { val stacks = event.inventoryItems if (bitsGuiNamePattern.matches(event.inventoryName)) { - val cookieStack = stacks.values.lastOrNull { bitsGuiStackPattern.matches(it.displayName) } ?: return - for (line in cookieStack.getLore()) { - bitsAvailableMenuPattern.matchMatcher(line) { - bitsToClaim = group("toClaim").formatInt() + val cookieStack = stacks.values.lastOrNull { bitsGuiStackPattern.matches(it.displayName) } + + // If the cookie stack is null, then the player should not have any bits to claim + if (cookieStack == null) { + bitsToClaim = 0 + return + } + + for (line in cookieStack.getLore()) { + bitsAvailableMenuPattern.matchMatcher(line) { + bitsToClaim = group("toClaim").formatInt() - return - } + return } + } return } diff --git a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt index 704f8ce77..a40918e8d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland @@ -21,7 +22,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object MaxwellAPI { private val storage get() = ProfileStorageData.profileSpecific - + var currentPower: String? get() = storage?.maxwell?.currentPower set(value) { @@ -60,6 +61,14 @@ object MaxwellAPI { "gui.selectedpower", "§aPower is selected!" ) + private val accessoryBagStack by group.pattern( + "stack.accessorybag", + "§.Accessory Bag" + ) + private val redstoneCollectionRequirementPattern by group.pattern( + "collection.redstone.requirement", + "(?:§.)*Requires (?:§.)*Redstone Collection I+(?:§.)*\\." + ) @SubscribeEvent fun onChat(event: LorenzChatEvent) { @@ -104,13 +113,20 @@ object MaxwellAPI { val stacks = event.inventoryItems for (stack in stacks.values) { - processStack(stack) + if (accessoryBagStack.matches(stack.displayName)) processStack(stack) } } } private fun processStack(stack: ItemStack) { for (line in stack.getLore()) { + redstoneCollectionRequirementPattern.matchMatcher(line) { + ChatUtils.chat("Seems like you don't have the Requirement for the Accessory Bag yet, setting power to No Power and magical power to 0.") + currentPower = getPowerByNameOrNull("No Power") + magicalPower = 0 + return + } + inventoryMPPattern.matchMatcher(line) { // MagicalPower is boosted in catacombs if (IslandType.CATACOMBS.isInIsland()) return@matchMatcher @@ -124,12 +140,12 @@ object MaxwellAPI { val power = group("power") currentPower = getPowerByNameOrNull(power) ?: return@matchMatcher ErrorManager.logErrorWithData( - UnknownMaxwellPower("Unknown power: ${stack.displayName}"), - "Unknown power: ${stack.displayName}", - "displayName" to stack.displayName, - "lore" to stack.getLore(), - noStackTrace = true - ) + UnknownMaxwellPower("Unknown power: ${stack.displayName}"), + "Unknown power: ${stack.displayName}", + "displayName" to stack.displayName, + "lore" to stack.getLore(), + noStackTrace = true + ) return@matchMatcher } } -- cgit