From 2cad7c87e85afa94465ed9a79cec4a20b303b26f Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Mon, 13 May 2024 17:15:22 +0200 Subject: Fix: Supercrafted Items in Profit Trackers (#1784) --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt | 14 ++++++++++++-- .../skyhanni/features/inventory/SuperCraftFeatures.kt | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 64b331a08..e5ccf33f8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -926,7 +926,7 @@ class SkyHanniMod { loadModule(GardenInventoryTooltipOverflow()) loadModule(SkillTooltip()) loadModule(MaxPurseItems()) - loadModule(SuperCraftFeatures()) + loadModule(SuperCraftFeatures) loadModule(InfernoMinionFeatures()) loadModule(LimboPlaytime()) loadModule(RareDropMessages()) diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt index 498d87d10..386f90965 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt @@ -6,11 +6,14 @@ import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.SackChangeEvent import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent +import at.hannibal2.skyhanni.features.inventory.SuperCraftFeatures.craftedPattern import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.TimeLimitedSet import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds @@ -57,11 +60,12 @@ class ItemAddManager { for (sackChange in event.sackChanges) { val change = sackChange.delta - if (change > 0) { - val internalName = sackChange.internalName + val internalName = sackChange.internalName + if (change > 0 && internalName !in superCraftedItems) { Source.SACKS.addItem(internalName, change) } } + superCraftedItems.clear() } @SubscribeEvent @@ -83,11 +87,17 @@ class ItemAddManager { } private var lastDiceRoll = SimpleTimeMark.farPast() + private var superCraftedItems = TimeLimitedSet(30.seconds) @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (diceRollChatPattern.matches(event.message)) { lastDiceRoll = SimpleTimeMark.now() } + craftedPattern.matchMatcher(event.message) { + val internalName = NEUInternalName.fromItemName(group("item")) + if (!SackAPI.sackListInternalNames.contains(internalName.asString())) return@matchMatcher + superCraftedItems.add(internalName) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperCraftFeatures.kt index 9d3f92104..c95533184 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SuperCraftFeatures.kt @@ -12,8 +12,8 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class SuperCraftFeatures { - private val craftedPattern by RepoPattern.pattern( +object SuperCraftFeatures { + val craftedPattern by RepoPattern.pattern( "inventory.supercrafting.craft.new", "§eYou Supercrafted §r§r§r§.(?[^§]+)(?:§r§8x(?[\\d,]+))?§r§e!" ) -- cgit