Skip to content

Commit 80f4f9b

Browse files
authored
Backend: Get rid of StackingEnchantsJson in favor of EnchantsJson (hannibal002#5578)
1 parent d21be96 commit 80f4f9b

5 files changed

Lines changed: 47 additions & 48 deletions

File tree

src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/StackingEnchantsJson.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package at.hannibal2.skyhanni.features.misc.discordrpc
44

55
import at.hannibal2.skyhanni.SkyHanniMod
66
import at.hannibal2.skyhanni.SkyHanniMod.feature
7+
import at.hannibal2.skyhanni.SkyHanniMod.launch
78
import at.hannibal2.skyhanni.SkyHanniMod.launchUnScoped
89
import at.hannibal2.skyhanni.api.EliteDevApi
910
import at.hannibal2.skyhanni.api.event.HandleEvent
@@ -15,6 +16,9 @@ import at.hannibal2.skyhanni.config.features.misc.DiscordRPCConfig.PriorityEntry
1516
import at.hannibal2.skyhanni.data.HypixelData
1617
import at.hannibal2.skyhanni.data.repo.ChatProgressUpdates
1718
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
19+
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
20+
import at.hannibal2.skyhanni.features.misc.items.enchants.Enchant
21+
import at.hannibal2.skyhanni.features.misc.items.enchants.EnchantsJson
1822
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
1923
import at.hannibal2.skyhanni.test.command.ErrorManager
2024
import at.hannibal2.skyhanni.utils.ChatUtils
@@ -56,11 +60,15 @@ object DiscordRPCManager {
5660
private var retryJob: Job? = null
5761
private var lastDebugInfo: Map<String, String> = emptyMap()
5862

63+
private val repoReloadCoroutine = CoroutineSettings("discord RPC manager repo reload")
5964
private val startCoroutine = CoroutineSettings("discord RPC start", timeout = Duration.INFINITE).withIOContext()
6065
private val presenceCoroutine = CoroutineSettings("discord RPC updatePresence", timeout = Duration.INFINITE).withIOContext()
6166
private val stopCoroutine = CoroutineSettings("discord RPC stop", timeout = Duration.INFINITE).withIOContext()
6267
private val manualStartCoroutine = CoroutineSettings("discord RPC manual start", timeout = Duration.INFINITE).withIOContext()
6368

69+
internal var stackingEnchants: Map<String, Enchant.Stacking> = emptyMap()
70+
private set
71+
6472
private fun isConnected() = client?.isConnected == true
6573
private fun isEnabled() = config.enabled.get()
6674

@@ -113,6 +121,11 @@ object DiscordRPCManager {
113121
beenAfkFor = SimpleTimeMark.now()
114122
}
115123

124+
@HandleEvent
125+
fun onRepoReload(event: RepositoryReloadEvent) = repoReloadCoroutine.launch {
126+
stackingEnchants = event.getConstantAsync<EnchantsJson>("EnchantsJson").stacking
127+
}
128+
116129
@HandleEvent
117130
fun onDebugDataCollect(event: DebugDataCollectEvent) {
118131
event.title("Discord RPC")

src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import at.hannibal2.skyhanni.data.garden.cropmilestones.CropMilestonesApi.getMax
1414
import at.hannibal2.skyhanni.data.garden.cropmilestones.CropMilestonesApi.getMilestoneCounter
1515
import at.hannibal2.skyhanni.data.garden.cropmilestones.CropMilestonesApi.isMaxMilestone
1616
import at.hannibal2.skyhanni.data.garden.cropmilestones.CropMilestonesApi.percentToNextMilestone
17-
import at.hannibal2.skyhanni.data.jsonobjects.repo.StackingEnchantData
1817
import at.hannibal2.skyhanni.features.dungeon.DungeonApi
1918
import at.hannibal2.skyhanni.features.garden.GardenApi
2019
import at.hannibal2.skyhanni.features.garden.GardenApi.getCropType
2120
import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboardUtils
2221
import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList
23-
import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValue
22+
import at.hannibal2.skyhanni.features.misc.items.enchants.Enchant
2423
import at.hannibal2.skyhanni.features.misc.pathfind.AreaNode
2524
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraApi
2625
import at.hannibal2.skyhanni.features.rift.RiftApi
@@ -80,7 +79,6 @@ private fun getPetDisplay(): String = CurrentPetApi.currentPet?.getUserFriendlyN
8079
?: "No pet equipped"
8180

8281
enum class DiscordStatus(private val displayMessageSupplier: DiscordStatus.() -> String?) {
83-
8482
NONE({ null }),
8583

8684
LOCATION(
@@ -270,16 +268,16 @@ enum class DiscordStatus(private val displayMessageSupplier: DiscordStatus.() ->
270268
if (extraAttributes != null) {
271269
val enchantments = extraAttributes.getCompoundOrDefault("enchantments")
272270
var stackingEnchant = ""
273-
for (enchant in EstimatedItemValue.stackingEnchants) {
274-
if (extraAttributes.contains(enchant.value.statName)) {
275-
stackingEnchant = enchant.key
271+
for ((name, enchant) in DiscordRPCManager.stackingEnchants) {
272+
if (enchant.nbtNum in extraAttributes) {
273+
stackingEnchant = name
276274
break
277275
}
278276
}
279-
val stackingData = EstimatedItemValue.stackingEnchants[stackingEnchant] ?: StackingEnchantData()
280-
val levels = stackingData.levels
277+
val stackingData = DiscordRPCManager.stackingEnchants[stackingEnchant] ?: Enchant.Stacking()
278+
val levels = stackingData.stackLevel
281279
val level = enchantments.getIntOrDefault(stackingEnchant)
282-
val amount = extraAttributes.getIntOrDefault(stackingData.statName)
280+
val amount = extraAttributes.getIntOrDefault(stackingData.nbtNum)
283281
val stackingPercent = getProgressPercent(amount, levels)
284282

285283
stackingReturn =

src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package at.hannibal2.skyhanni.features.misc.items
22

33
import at.hannibal2.skyhanni.SkyHanniMod
4+
import at.hannibal2.skyhanni.SkyHanniMod.launch
45
import at.hannibal2.skyhanni.api.event.HandleEvent
56
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
67
import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig
78
import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemValueCalculationDataJson
89
import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
9-
import at.hannibal2.skyhanni.data.jsonobjects.repo.StackingEnchantData
10-
import at.hannibal2.skyhanni.data.jsonobjects.repo.StackingEnchantsJson
11-
import at.hannibal2.skyhanni.events.ConfigLoadEvent
12-
import at.hannibal2.skyhanni.events.GuiRenderEvent
13-
import at.hannibal2.skyhanni.events.InventoryCloseEvent
1410
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
1511
import at.hannibal2.skyhanni.events.RenderItemTooltipEvent
1612
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
13+
import at.hannibal2.skyhanni.features.misc.items.enchants.Enchant
14+
import at.hannibal2.skyhanni.features.misc.items.enchants.EnchantsJson
1715
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
1816
import at.hannibal2.skyhanni.test.command.ErrorManager
1917
import at.hannibal2.skyhanni.utils.ConditionalUtils
@@ -32,21 +30,28 @@ import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
3230
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
3331
import at.hannibal2.skyhanni.utils.SkyBlockUtils
3432
import at.hannibal2.skyhanni.utils.compat.formattedTextCompatLeadingWhiteLessResets
33+
import at.hannibal2.skyhanni.utils.coroutines.CoroutineSettings
3534
import at.hannibal2.skyhanni.utils.renderables.Renderable
3635
import at.hannibal2.skyhanni.utils.renderables.primitives.StringRenderable
3736
import net.minecraft.client.Minecraft
3837
import net.minecraft.world.item.ItemStack
3938
import org.lwjgl.glfw.GLFW
4039
import kotlin.math.roundToLong
4140

41+
private typealias NeuGemstoneCostJson = HashMap<NeuInternalName, HashMap<String, List<String>>>
42+
4243
@SkyHanniModule
4344
object EstimatedItemValue {
4445

4546
val config: EstimatedItemValueConfig get() = SkyHanniMod.feature.inventory.estimatedItemValues
47+
48+
private val repoReloadCoroutine = CoroutineSettings("estimated item value repo reload")
49+
private val neuRepoReloadCoroutine = CoroutineSettings("estimated item value neu repo reload")
50+
4651
private var display = emptyList<Renderable>()
4752
private val cache = mutableMapOf<ItemStack, List<Renderable>>()
4853
private var lastToolTipTime = 0L
49-
var gemstoneUnlockCosts = HashMap<NeuInternalName, HashMap<String, List<String>>>()
54+
var gemstoneUnlockCosts = NeuGemstoneCostJson()
5055
var hasLegacyGemstoneSlots = emptyList<NeuInternalName>()
5156
var bookBundleAmount = mapOf<String, Int>()
5257
var crimsonPrestigeCosts = mapOf<String, Map<NeuInternalName, Int>>()
@@ -55,25 +60,24 @@ object EstimatedItemValue {
5560
var itemValueCalculationData: ItemValueCalculationDataJson? = null
5661
private set
5762

58-
var stackingEnchants: Map<String, StackingEnchantData> = emptyMap()
63+
internal var stackingEnchants: Map<String, Enchant.Stacking> = emptyMap()
5964
private set
6065

6166
fun isCurrentlyShowing() = currentlyShowing && Minecraft.getInstance().screen != null
6267

6368
@HandleEvent
64-
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
65-
gemstoneUnlockCosts =
66-
event.getConstant<HashMap<NeuInternalName, HashMap<String, List<String>>>>("gemstonecosts")
69+
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) = neuRepoReloadCoroutine.launch {
70+
gemstoneUnlockCosts = event.getConstantAsync<NeuGemstoneCostJson>("gemstonecosts")
6771
}
6872

6973
@HandleEvent
70-
fun onRepoReload(event: RepositoryReloadEvent) {
71-
val data = event.getConstant<ItemsJson>("Items")
74+
fun onRepoReload(event: RepositoryReloadEvent) = repoReloadCoroutine.launch {
75+
val data = event.getConstantAsync<ItemsJson>("Items")
7276
bookBundleAmount = data.bookBundleAmount
7377
itemValueCalculationData = data.valueCalculationData
7478
crimsonPrestigeCosts = data.crimsonPrestigeCosts
7579
hasLegacyGemstoneSlots = data.hasLegacyGemstoneSlots ?: emptyList()
76-
stackingEnchants = event.getConstant<StackingEnchantsJson>("StackingEnchants").enchants
80+
stackingEnchants = event.getConstantAsync<EnchantsJson>("EnchantsJson").stacking
7781
}
7882

7983
// TODO test if this can go now since NEU pv is gone (SB-PV mod support?)
@@ -86,7 +90,7 @@ object EstimatedItemValue {
8690
private var renderedItems = 0
8791

8892
@HandleEvent
89-
fun onGuiRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
93+
fun onGuiRenderOverlay() {
9094
renderedItems = 0
9195
}
9296

@@ -121,7 +125,7 @@ object EstimatedItemValue {
121125
}
122126

123127
@HandleEvent
124-
fun onChestGuiRender(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
128+
fun onChestGuiRender() {
125129
tryRendering()
126130
}
127131

@@ -137,12 +141,12 @@ object EstimatedItemValue {
137141
}
138142

139143
@HandleEvent
140-
fun onInventoryClose(event: InventoryCloseEvent) {
144+
fun onInventoryClose() {
141145
cache.clear()
142146
}
143147

144148
@HandleEvent
145-
fun onConfigLoad(event: ConfigLoadEvent) {
149+
fun onConfigLoad() {
146150
with(config) {
147151
ConditionalUtils.onToggle(
148152
enchantmentsCap,

src/main/java/at/hannibal2/skyhanni/features/misc/items/enchants/Enchant.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import net.minecraft.network.chat.Component
2323
import net.minecraft.network.chat.Style
2424
import net.minecraft.network.chat.TextColor
2525
import net.minecraft.world.item.ItemStack
26-
import java.util.TreeSet
2726

2827
private val PROMISING_SHOVEL = "PROMISING_SHOVEL".toInternalName()
2928
private val STONK_PICKAXE = "STONK_PICKAXE".toInternalName()
@@ -155,24 +154,21 @@ open class Enchant : Comparable<Enchant> {
155154

156155
class Stacking : Enchant() {
157156
@Expose
158-
private val nbtNum: String? = null
157+
val nbtNum: String = ""
159158

160159
@Expose
161-
@Suppress("UnusedPrivateProperty")
162-
private val statLabel: String? = null
160+
private val statLabel: String = ""
163161

164162
@Expose
165-
private val stackLevel: TreeSet<Int>? = null
163+
val stackLevel: List<Int> = emptyList()
166164

167165
override fun toString() = "$nbtNum $stackLevel ${super.toString()}"
168166

169167
fun progressString(item: ItemStack): String {
170-
val nbtKey = nbtNum ?: return ""
171-
val levels = stackLevel ?: return ""
172-
val label = statLabel?.splitCamelCase()?.replaceFirstChar { it.uppercase() }?.replace("Xp", "XP") ?: return ""
173-
val progress = item.extraAttributes.getDoubleOrDefault(nbtKey).roundTo(0).toInt()
168+
val label = statLabel.splitCamelCase().replaceFirstChar { it.uppercase() }.replace("Xp", "XP")
169+
val progress = item.extraAttributes.getDoubleOrDefault(nbtNum).roundTo(0).toInt()
174170
if (progress == 0) return ""
175-
val nextLevel = levels.higher(progress)
171+
val nextLevel = stackLevel.minByOrNull { it > progress }
176172
val tail = nextLevel?.shortFormat()?.insert(0, "/ ") ?: "(Maxed)"
177173
return "§7$label: §c${progress.shortFormat()} §7$tail"
178174
}

0 commit comments

Comments
 (0)