diff options
| author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-08-31 22:31:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-31 22:31:55 +0200 |
| commit | 79d891d5a3e1bffd31491a921757ccf7ab66b5fe (patch) | |
| tree | f6fd36060dd3764ecf81295f77a0aecf68e82364 /src/main/java/at/hannibal2/skyhanni/features | |
| parent | c834fbbb6a535b0c0c27d02c893433e687332268 (diff) | |
| download | skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.tar.gz skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.tar.bz2 skyhanni-79d891d5a3e1bffd31491a921757ccf7ab66b5fe.zip | |
Feature: Bits on Cookie (#2265)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/BitsPerCookieVisual.kt | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/BitsPerCookieVisual.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/BitsPerCookieVisual.kt new file mode 100644 index 000000000..8b38238ad --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/BitsPerCookieVisual.kt @@ -0,0 +1,80 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.BitsAPI +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcherWithIndex +import at.hannibal2.skyhanni.utils.RegexUtils.indexOfFirstMatch +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object BitsPerCookieVisual { + + private val config get() = SkyHanniMod.feature.misc.bits + + private val boosterCookie = "BOOSTER_COOKIE".asInternalName() + + private val patternGroup = RepoPattern.group("cookie.bits") + + private val wrongCookiePattern by patternGroup.pattern("wrong", "§[de]Booster Cookie") + + /** + * REGEX-TEST: §5§o§7Amount: §a1§7x + * REGEX-TEST: §5§o§6Booster Cookie §8x6 + */ + private val amountPattern by patternGroup.pattern("amount", "§5§o(?:§6Booster Cookie §8x|§7Amount: §a)(?<amount>\\d+).*") + + /** REGEX-TEST: §5§o§7§b4 §7days: + * */ + private val timePattern by patternGroup.pattern("time", "§5§o§7§b4 §7days:") + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!isEnabled()) return + if (event.itemStack.getInternalNameOrNull() != boosterCookie) return + if (wrongCookiePattern.matches(event.itemStack.name)) return + var timeReplaced = false + + val toolTip = event.toolTip + val (cookieAmount, loreIndex) = amountPattern.firstMatcherWithIndex(toolTip) { + group("amount").toInt() to it + } ?: (1 to 0) + val positionIndex = timePattern.indexOfFirstMatch(toolTip)?.also { + timeReplaced = true + if (config.bulkBuyCookieTime) { + toolTip.removeAt(it) + } + } ?: (loreIndex + 1) + + val gain = BitsAPI.bitsPerCookie() * cookieAmount + val newAvailable = BitsAPI.bitsAvailable + gain + val duration = 4 * cookieAmount + + var index = positionIndex + + if (timeReplaced) { + if (config.bulkBuyCookieTime) toolTip.add(index++, "§7§b$duration §7days") + toolTip.add(index++, "") + } else { + toolTip.add(index++, "") + if (config.bulkBuyCookieTime) toolTip.add(index++, "§8‣ §7Cookie Buff for §b$duration §7days") + } + + if (config.showBitsOnCookie) toolTip.add(index++, "§8‣ §7Gain §b${gain.addSeparators()} Bits") + if (config.showBitsChangeOnCookie) toolTip.add( + index++, + "§8‣ §7Available Bits: §3${BitsAPI.bitsAvailable.addSeparators()} §6→ §3${newAvailable.addSeparators()}", + ) + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && + config.let { it.bulkBuyCookieTime || it.showBitsOnCookie || it.showBitsChangeOnCookie } +} |
