Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Favorite Power Stones #2002

Merged
merged 13 commits into from
Jun 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ public String toString() {
@FeatureToggle
public boolean powerStoneGuide = true;

@Expose
@ConfigOption(name = "Favorite Power Stone", desc = "Shows your favorite power stones. You can add/remove them by shift clicking a Power Stone.")
@ConfigEditorBoolean
@FeatureToggle
public boolean favoritePowerStone = false;

@Expose
@ConfigOption(name = "Shift Click Equipment", desc = "Makes normal clicks to shift clicks in equipment inventory.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public static class MaxwellPowerStorage {

@Expose
public List<MaxwellAPI.ThaumaturgyPowerTuning> tunings = new ArrayList<>();

@Expose
public List<String> favoritePowers = new ArrayList<>();
}

@Expose
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ object MaxwellAPI {
storage?.maxwell?.tunings = value ?: return
}

var favoritePowers: List<String>
get() = storage?.maxwell?.favoritePowers ?: listOf()
set(value) {
storage?.maxwell?.favoritePowers = value
}

private var powers = mutableListOf<String>()

private val patternGroup = RepoPattern.group("data.maxwell")
Expand Down Expand Up @@ -282,7 +288,7 @@ object MaxwellAPI {
if (!foundMagicalPower) magicalPower = 0
}

private fun getPowerByNameOrNull(name: String) = powers.find { it == name }
fun getPowerByNameOrNull(name: String) = powers.find { it == name }

private fun isEnabled() = LorenzUtils.inSkyBlock && storage != null

Expand Down
Original file line number Diff line number Diff line change
@@ -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
saga-00 marked this conversation as resolved.
Show resolved Hide resolved
} 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
}
Loading