blob: 8b38238adfdb91ac24e3b4bcee0cbbae5bd43490 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 }
}
|