aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-03-17 18:23:46 +0100
committerGitHub <noreply@github.com>2024-03-17 18:23:46 +0100
commitf72cf9906a49736948a353fceb135e49b3f041b5 (patch)
tree012116f3b0594b01ac95b2a8c863fa4c39c14502 /src/main/java/at/hannibal2/skyhanni/data
parentccf598ce287b3f179e65827c3a4caa05b75d3beb (diff)
downloadskyhanni-f72cf9906a49736948a353fceb135e49b3f041b5.tar.gz
skyhanni-f72cf9906a49736948a353fceb135e49b3f041b5.tar.bz2
skyhanni-f72cf9906a49736948a353fceb135e49b3f041b5.zip
Feature: Thaumaturgy Tuning in Custom Scoreboard (#1201)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt155
1 files changed, 132 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
index a40918e8d..98c410b86 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
@@ -1,13 +1,17 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.data.jsonobjects.repo.MaxwellPowersJson
-import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard
+import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardElement
import at.hannibal2.skyhanni.test.command.ErrorManager
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.LorenzUtils.groupOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
@@ -16,8 +20,11 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpace
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import com.google.gson.annotations.Expose
import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.regex.Pattern
object MaxwellAPI {
@@ -28,12 +35,19 @@ object MaxwellAPI {
set(value) {
storage?.maxwell?.currentPower = value ?: return
}
+
var magicalPower: Int?
get() = storage?.maxwell?.magicalPower
set(value) {
storage?.maxwell?.magicalPower = value ?: return
}
+ var tunings: List<ThaumaturgyPowerTuning>?
+ get() = storage?.maxwell?.tunings
+ set(value) {
+ storage?.maxwell?.tunings = value ?: return
+ }
+
private var powers = mutableListOf<String>()
private val group = RepoPattern.group("data.maxwell")
@@ -53,6 +67,26 @@ object MaxwellAPI {
"gui.thaumaturgy",
"Accessory Bag Thaumaturgy"
)
+ private val thaumaturgyStartPattern by group.pattern(
+ "gui.thaumaturgy.start",
+ "§7Your tuning:"
+ )
+ private val thaumaturgyDataPattern by group.pattern(
+ "gui.thaumaturgy.data",
+ "§(?<color>.)\\+(?<amount>[^ ]+)(?<icon>.) (?<name>.+)"
+ )
+ private val statsTuningGuiPattern by group.pattern(
+ "gui.thaumaturgy.statstuning",
+ "Stats Tuning"
+ )
+ private val statsTuningDataPattern by group.pattern(
+ "thaumaturgy.statstuning",
+ "§7You have: .+ §7\\+ §(?<color>.)(?<amount>[^ ]+) (?<icon>.)"
+ )
+ private val tuningAutoAssignedPattern by group.pattern(
+ "tuningpoints.chat.autoassigned",
+ "§aYour §r§eTuning Points §r§awere auto-assigned as convenience!"
+ )
private val yourBagsGuiPattern by group.pattern(
"gui.yourbags",
"Your Bags"
@@ -70,6 +104,8 @@ object MaxwellAPI {
"(?:§.)*Requires (?:§.)*Redstone Collection I+(?:§.)*\\."
)
+ fun isThaumaturgyInventory(inventoryName: String) = thaumaturgyGuiPattern.matches(inventoryName)
+
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
@@ -85,37 +121,103 @@ object MaxwellAPI {
"message" to message
)
}
+ tuningAutoAssignedPattern.matchMatcher(event.message) {
+ if (tunings?.isNotEmpty() == true) {
+ val tuningsInScoreboard = ScoreboardElement.TUNING in CustomScoreboard.config.scoreboardEntries
+ if (tuningsInScoreboard) {
+ ChatUtils.chat("Talk to Maxwell again to update the tuning data in scoreboard.")
+ }
+ }
+ }
}
- @SubscribeEvent
- fun onInventoryFullyLoaded(event: InventoryFullyOpenedEvent) {
+ // load earler, so that other features can already use the api in this event
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onInventoryFullyLoaded(event: InventoryOpenEvent) {
if (!isEnabled()) return
- if (thaumaturgyGuiPattern.matches(event.inventoryName)) {
- val selectedPowerStack =
- event.inventoryItems.values.find {
- powerSelectedPattern.matches(it.getLore().lastOrNull())
- } ?: return
- val displayName = selectedPowerStack.displayName.removeColor().trim()
-
- currentPower = getPowerByNameOrNull(displayName)
- ?: return ErrorManager.logErrorWithData(
- UnknownMaxwellPower("Unknown power: $displayName"),
- "Unknown power: $displayName",
- "displayName" to displayName,
- "lore" to selectedPowerStack.getLore(),
- noStackTrace = true
- )
- return
+ if (isThaumaturgyInventory(event.inventoryName)) {
+ loadThaumaturgyCurrentPower(event.inventoryItems)
+ loadThaumaturgyTunings(event.inventoryItems)
}
if (yourBagsGuiPattern.matches(event.inventoryName)) {
- val stacks = event.inventoryItems
-
- for (stack in stacks.values) {
+ for (stack in event.inventoryItems.values) {
if (accessoryBagStack.matches(stack.displayName)) processStack(stack)
}
}
+ if (statsTuningGuiPattern.matches(event.inventoryName)) {
+ loadThaumaturgyTuningsFromTuning(event.inventoryItems)
+ }
+ }
+
+ private fun loadThaumaturgyTuningsFromTuning(inventoryItems: Map<Int, ItemStack>) {
+ val map = mutableListOf<ThaumaturgyPowerTuning>()
+ for (stack in inventoryItems.values) {
+ for (line in stack.getLore()) {
+ statsTuningDataPattern.readTuningFromLine(line)?.let {
+ it.name = "§.. (?<name>.+)".toPattern().matchMatcher(stack.name) {
+ group("name")
+ } ?: ErrorManager.skyHanniError(
+ "found no name in thaumaturgy",
+ "stack name" to stack.name,
+ "line" to line
+ )
+ map.add(it)
+ }
+ }
+ }
+ tunings = map
+ }
+
+ private fun Pattern.readTuningFromLine(line: String): ThaumaturgyPowerTuning? {
+ return matchMatcher(line) {
+ val color = "§" + group("color")
+ val icon = group("icon")
+ val name = groupOrNull("name") ?: "<missing>"
+ val value = group("amount")
+ ThaumaturgyPowerTuning(value, color, name, icon)
+ }
+ }
+
+ private fun loadThaumaturgyCurrentPower(inventoryItems: Map<Int, ItemStack>) {
+ val selectedPowerStack =
+ inventoryItems.values.find {
+ powerSelectedPattern.matches(it.getLore().lastOrNull())
+ } ?: return
+ val displayName = selectedPowerStack.displayName.removeColor().trim()
+
+ currentPower = getPowerByNameOrNull(displayName)
+ ?: return ErrorManager.logErrorWithData(
+ UnknownMaxwellPower("Unknown power: $displayName"),
+ "Unknown power: $displayName",
+ "displayName" to displayName,
+ "lore" to selectedPowerStack.getLore(),
+ noStackTrace = true
+ )
+ }
+
+ private fun loadThaumaturgyTunings(inventoryItems: Map<Int, ItemStack>) {
+ val tunings = tunings ?: return
+
+ // Only load those rounded values if we dont have any valurs at all
+ if (tunings.isNotEmpty()) return
+
+ val item = inventoryItems[51] ?: return
+ var active = false
+ val map = mutableListOf<ThaumaturgyPowerTuning>()
+ for (line in item.getLore()) {
+ if (thaumaturgyStartPattern.matches(line)) {
+ active = true
+ continue
+ }
+ if (!active) continue
+ if (line.isEmpty()) break
+ thaumaturgyDataPattern.readTuningFromLine(line)?.let {
+ map.add(it)
+ }
+ }
+ this.tunings = map
}
private fun processStack(stack: ItemStack) {
@@ -153,7 +255,7 @@ object MaxwellAPI {
private fun getPowerByNameOrNull(name: String) = powers.find { it == name }
- fun isEnabled() = LorenzUtils.inSkyBlock && storage != null
+ private fun isEnabled() = LorenzUtils.inSkyBlock && storage != null
// Load powers from repo
@SubscribeEvent
@@ -163,4 +265,11 @@ object MaxwellAPI {
}
class UnknownMaxwellPower(message: String) : Exception(message)
+
+ class ThaumaturgyPowerTuning(
+ @Expose val value: String,
+ @Expose val color: String,
+ @Expose var name: String,
+ @Expose val icon: String,
+ )
}