From a7ecc57e896693632a65fa341760ebca1ed309c5 Mon Sep 17 00:00:00 2001 From: sayomaki Date: Sun, 9 Jun 2024 18:07:10 +0800 Subject: Feature: Add chocolate production time for stray rabbits (#1978) Co-authored-by: Cal --- .../chocolatefactory/ChocolateFactoryConfig.java | 6 ++++ .../ChocolateFactoryTooltipStray.kt | 38 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltipStray.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index cbd43b214..ae36b2a51 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -98,6 +98,12 @@ public class ChocolateFactoryConfig { @FeatureToggle public boolean showDuplicateTime = false; + @Expose + @ConfigOption(name = "Stray Rabbit Time", desc = "Show the production time of chocolate gained from stray rabbits.") + @ConfigEditorBoolean + @FeatureToggle + public boolean showStrayTime = false; + @Expose @ConfigOption(name = "Time Tower Usage Warning", desc = "Notification when you have a new time tower usage available and " + "continuously warn when your time tower is full.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltipStray.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltipStray.kt new file mode 100644 index 000000000..0c785c761 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltipStray.kt @@ -0,0 +1,38 @@ +package at.hannibal2.skyhanni.features.inventory.chocolatefactory + +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst +import at.hannibal2.skyhanni.utils.TimeUtils.format +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object ChocolateFactoryTooltipStray { + private val config get() = ChocolateFactoryAPI.config + + /** + * REGEX-TEST: §7You gained §6+2,465,018 Chocolate§7! + * REGEX-TEST: §7gained §6+30,292 Chocolate§7! + * REGEX-TEST: §7§6+36,330 Chocolate§7! + */ + private val chocolateGainedPattern by ChocolateFactoryAPI.patternGroup.pattern( + "rabbit.stray", + "(?:§.)+(?:You )?(?:gained )?§6\\+(?[\\d,]+) Chocolate§7!" + ) + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onTooltip(event: LorenzToolTipEvent) { + if (!ChocolateFactoryAPI.inChocolateFactory) return + if (!config.showStrayTime) return + if (event.slot.slotNumber > 26 || event.slot.slotNumber == ChocolateFactoryAPI.infoIndex) return + + val tooltip = event.toolTip + tooltip.matchFirst(chocolateGainedPattern) { + val amount = group("amount").formatLong() + val format = ChocolateFactoryAPI.timeUntilNeed(amount + 1).format(maxUnits = 2) + tooltip[tooltip.lastIndex] += " §7(§a+§b$format §aof production§7)" + } + } +} -- cgit