summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-08 21:13:11 +0200
committerGitHub <noreply@github.com>2024-05-08 21:13:11 +0200
commit64ffd48ac791019ce4e4a610541b143a4c9d9b44 (patch)
treeec231583b75aa432061ab22604001e09c25633de /src/main/java/at/hannibal2/skyhanni/features
parentbd117b2d181a6abb419021f815e4ad07cc05a37f (diff)
downloadskyhanni-64ffd48ac791019ce4e4a610541b143a4c9d9b44.tar.gz
skyhanni-64ffd48ac791019ce4e4a610541b143a4c9d9b44.tar.bz2
skyhanni-64ffd48ac791019ce4e4a610541b143a4c9d9b44.zip
Improvement: Custom Reminder (#1740)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt147
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt1
3 files changed, 150 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
index 8566d6257..0cd7bc0da 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
@@ -12,5 +12,6 @@ object ReminderUtils {
// TODO: add arachne fight, add slayer boss spawned, add dragon fight
fun isBusy(ignoreFarmingContest: Boolean = false): Boolean =
DungeonAPI.inDungeon() || LorenzUtils.inKuudraFight || (FarmingContestAPI.inContest && !ignoreFarmingContest) ||
- RiftAPI.inRift() || IslandType.DARK_AUCTION.isInIsland()|| IslandType.MINESHAFT.isInIsland()
+ RiftAPI.inRift() || IslandType.DARK_AUCTION.isInIsland() || IslandType.MINESHAFT.isInIsland() ||
+ IslandType.NONE.isInIsland() || IslandType.UNKNOWN.isInIsland()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt
new file mode 100644
index 000000000..5e03ccb44
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt
@@ -0,0 +1,147 @@
+package at.hannibal2.skyhanni.features.inventory.chocolatefactory
+
+import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
+import at.hannibal2.skyhanni.features.fame.ReminderUtils
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.SoundUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
+import at.hannibal2.skyhanni.utils.TimeUtils.minutes
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object ChocolateFactoryCustomReminder {
+ private val configReminder get() = ChocolateFactoryAPI.config.customReminder
+ private val configUpgradeWarnings get() = ChocolateFactoryAPI.config.chocolateUpgradeWarnings
+
+ private var targetGoal: Long?
+ get() = ChocolateFactoryAPI.profileStorage?.targetGoal
+ set(value) {
+ ChocolateFactoryAPI.profileStorage?.targetGoal = value
+ }
+ private var targetName: String?
+ get() = ChocolateFactoryAPI.profileStorage?.targetName
+ set(value) {
+ ChocolateFactoryAPI.profileStorage?.targetName = value
+ }
+
+ fun isActive() = targetGoal != null
+
+ private var display = emptyList<Renderable>()
+
+ private var lastUpgradeWarning = SimpleTimeMark.farPast()
+
+ @SubscribeEvent
+ fun onChat(event: SystemMessageEvent) {
+ if (!isEnabled()) return
+ if (configReminder.hideChat) {
+ if (event.message == "§cYou don't have enough Chocolate!") {
+ event.blockedReason = "custom_reminder"
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ if (!isEnabled()) return
+ update()
+ }
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (!isEnabled()) return
+ val item = event.item ?: return
+ // TODO add support for prestige and for Chocolate Milestone
+ val cost = ChocolateFactoryAPI.getChocolateBuyCost(item.getLore()) ?: return
+ val duration = ChocolateAmount.CURRENT.timeUntilGoal(cost)
+
+ // the user has enough chocolate, and just bought something
+ if (duration.isNegative()) {
+ reset()
+ return
+ }
+ setReminder(cost, item.name)
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (!inChocolateMenu()) return
+
+ configReminder.position.renderRenderables(display, posLabel = "Chocolate Factory Custom Reminder")
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (!configReminder.always) return
+ if (Minecraft.getMinecraft().currentScreen is GuiChest) return
+
+ configReminder.position.renderRenderables(display, posLabel = "Chocolate Factory Custom Reminder")
+ }
+
+ private fun inChocolateMenu() = ChocolateShopPrice.inInventory || ChocolateFactoryAPI.inChocolateFactory ||
+ ChocolateFactoryAPI.chocolateFactoryPaused
+
+ private fun setReminder(target: Long, name: String) {
+ if (targetName == name) {
+ reset()
+ return
+ }
+ targetGoal = target
+ targetName = name
+ update()
+ }
+
+ private fun update() {
+ display = mutableListOf<Renderable>().also { list ->
+ getTargetDescription()?.let {
+ list.add(Renderable.clickAndHover(it, listOf("§eClick to remove the goal!"), onClick = {
+ reset()
+ }))
+ }
+ }
+ }
+
+ private fun getTargetDescription(): String? {
+ val goal = targetGoal ?: return null
+ val duration = ChocolateAmount.CURRENT.timeUntilGoal(goal)
+ if (duration.isNegative()) {
+ warn()
+ return "§aGoal Reached! §eBuy §f$targetName"
+ }
+ val format = duration.format(maxUnits = 2)
+ return "§f$targetName §ein §b$format"
+ }
+
+ private fun warn() {
+ if (ReminderUtils.isBusy()) return
+ if (inChocolateMenu()) return
+
+ if (lastUpgradeWarning.passedSince() < configUpgradeWarnings.timeBetweenWarnings.minutes) return
+ lastUpgradeWarning = SimpleTimeMark.now()
+
+ if (configUpgradeWarnings.upgradeWarningSound) {
+ SoundUtils.playBeepSound()
+ }
+ ChatUtils.chat("You can now purchase §f$targetName §ein Chocolate factory!")
+ }
+
+ private fun reset() {
+ targetGoal = null
+ targetName = ""
+
+ display = emptyList()
+ }
+
+ fun isEnabled() = LorenzUtils.inSkyBlock && configReminder.enabled
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt
index 28e89855c..c99356106 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryUpgradeWarning.kt
@@ -35,6 +35,7 @@ object ChocolateFactoryUpgradeWarning {
if (!ChocolateFactoryAPI.isEnabled()) return
if (!config.upgradeWarning) return
if (ReminderUtils.isBusy()) return
+ if (ChocolateFactoryCustomReminder.isActive()) return
if (lastUpgradeWarning.passedSince() < config.timeBetweenWarnings.minutes) return
lastUpgradeWarning = SimpleTimeMark.now()
if (config.upgradeWarningSound) {