summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorsaga <45262877+saga-00@users.noreply.github.com>2024-06-05 16:03:22 -0300
committerGitHub <noreply@github.com>2024-06-05 21:03:22 +0200
commit93229bf2caa30de689664b665b58ee59949137fc (patch)
tree1985b131881940055f5d977d6aa8310d06ea476a /src/main/java/at/hannibal2/skyhanni/features
parent7d4567cb774a791114eefce7d4bca1ca493a023d (diff)
downloadskyhanni-93229bf2caa30de689664b665b58ee59949137fc.tar.gz
skyhanni-93229bf2caa30de689664b665b58ee59949137fc.tar.bz2
skyhanni-93229bf2caa30de689664b665b58ee59949137fc.zip
Feature: Favorite Power Stones (#2002)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com> 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/FavoritePowerStone.kt75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/FavoritePowerStone.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/FavoritePowerStone.kt
new file mode 100644
index 000000000..91727dc01
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/FavoritePowerStone.kt
@@ -0,0 +1,75 @@
+package at.hannibal2.skyhanni.features.inventory
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.MaxwellAPI
+import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
+import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.KeyboardManager
+import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+@SkyHanniModule
+object FavoritePowerStone {
+
+ private val config get() = SkyHanniMod.feature.inventory
+ private val storage get() = ProfileStorageData.profileSpecific
+
+ private var highlightedSlots = setOf<Int>()
+ private var inInventory = false
+
+ @SubscribeEvent
+ fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!isEnabled() || !inInventory) return
+
+ highlightedSlots.forEach { event.gui.inventorySlots.inventorySlots[it] highlight LorenzColor.AQUA }
+ }
+
+ @SubscribeEvent
+ fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (!isEnabled() || !KeyboardManager.isShiftKeyDown() || !inInventory) return
+
+ val displayName = event.item?.name?.removeColor()?.trim() ?: return
+ val power = MaxwellAPI.getPowerByNameOrNull(displayName) ?: return
+
+ if (power in MaxwellAPI.favoritePowers) {
+ MaxwellAPI.favoritePowers -= power
+ highlightedSlots -= event.slotId
+ } else {
+ MaxwellAPI.favoritePowers += power
+ highlightedSlots += event.slotId
+ }
+
+ event.cancel()
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ if (!isEnabled() || !MaxwellAPI.isThaumaturgyInventory(event.inventoryName)) return
+
+ inInventory = true
+ }
+
+ @SubscribeEvent
+ fun onInventoryUpdated(event: InventoryUpdatedEvent) {
+ if (!isEnabled() || !inInventory) return
+
+ highlightedSlots = event.inventoryItems
+ .filter { (_, item) -> item.displayName.removeColor() in MaxwellAPI.favoritePowers }
+ .keys
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && storage != null && config.favoritePowerStone
+}