diff options
author | Roman / Linnea Gräf <romangraef@gmail.com> | 2022-11-05 20:23:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 20:23:54 +0100 |
commit | 4cd48075604433a922bb79413f82a12209dd195e (patch) | |
tree | 35a443cbfaca004d2d030b146fbb5378d7187f5a /src | |
parent | c9b5b020ecbbc48cdbb7580c60125589a2529604 (diff) | |
download | skyhanni-4cd48075604433a922bb79413f82a12209dd195e.tar.gz skyhanni-4cd48075604433a922bb79413f82a12209dd195e.tar.bz2 skyhanni-4cd48075604433a922bb79413f82a12209dd195e.zip |
Bonzo's Mask Timer (#7)
Diffstat (limited to 'src')
3 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 47122a9dc..de9d1c2e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -163,6 +163,7 @@ public class SkyHanniMod { registerEvent(new GriffinBurrowHelper()); registerEvent(new GriffinBurrowParticleFinder()); registerEvent(new BurrowWarpHelper()); + registerEvent(new HighlightBonzoMasks()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java index 780db21e1..290492705 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Inventory.java @@ -115,4 +115,10 @@ public class Inventory { desc = "Show a compact star count in the item name for all items") @ConfigEditorBoolean public boolean itemStars = false; + + @Expose + @ConfigOption(name = "Highlight Depleted Bonzo's Masks", + desc = "Highlights used Bonzo's Masks with a background") + @ConfigEditorBoolean + public boolean highlightDepletedBonzosMasks = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HighlightBonzoMasks.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HighlightBonzoMasks.kt new file mode 100644 index 000000000..371c0578d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HighlightBonzoMasks.kt @@ -0,0 +1,61 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.RenderUtils.interpolate +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color +import kotlin.time.Duration.Companion.seconds +import kotlin.time.DurationUnit +import kotlin.time.ExperimentalTime +import kotlin.time.TimeMark +import kotlin.time.TimeSource + +/** + * @author Linnea Gräf + */ +@OptIn(ExperimentalTime::class) +class HighlightBonzoMasks { + + val bonzoMaskTimers = mutableMapOf<String, TimeMark>() + + // Technically this timer is overestimating since the cooldown is affected by mage level, however I do not care. + val bonzoMaskCooldown = 360.seconds + val bonzoMaskMessage = "Your (.*Bonzo's Mask) saved your life!".toRegex() + + val greenHue = Color.RGBtoHSB(0, 255, 0, null)[0].toDouble() + val redHue = Color.RGBtoHSB(255, 0, 0, null)[0].toDouble() + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!SkyHanniMod.feature.inventory.highlightDepletedBonzosMasks) return + for (slot in event.gui.inventorySlots.inventorySlots) { + val item = slot.stack ?: continue + val internalName = item.getInternalName() + if (!internalName.endsWith("BONZO_MASK")) continue + val timer = bonzoMaskTimers[internalName] ?: continue + if (timer.elapsedNow() < bonzoMaskCooldown) { + val progress = + timer.elapsedNow().toDouble(DurationUnit.SECONDS) / bonzoMaskCooldown.toDouble(DurationUnit.SECONDS) + val hue = interpolate(greenHue, redHue, progress.toFloat()) + slot.highlight(Color(Color.HSBtoRGB(hue.toFloat(), 1F, 1F))) + } + } + } + + @SubscribeEvent + fun onChatReceived(event: ClientChatReceivedEvent) { + val match = bonzoMaskMessage.matchEntire(event.message.unformattedText) ?: return + val bonzoId = if ("⚚" in match.groupValues[1]) "STARRED_BONZO_MASK" else "BONZO_MASK" + bonzoMaskTimers[bonzoId] = TimeSource.Monotonic.markNow() + } + + @SubscribeEvent + fun onJoinWorld(ignored: WorldEvent.Load) { + bonzoMaskTimers.clear() + } +}
\ No newline at end of file |