11package at.hannibal2.skyhanni.features.misc.items
22
33import at.hannibal2.skyhanni.SkyHanniMod
4+ import at.hannibal2.skyhanni.SkyHanniMod.launch
45import at.hannibal2.skyhanni.api.event.HandleEvent
56import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
67import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig
78import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemValueCalculationDataJson
89import 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
1410import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
1511import at.hannibal2.skyhanni.events.RenderItemTooltipEvent
1612import 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
1715import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
1816import at.hannibal2.skyhanni.test.command.ErrorManager
1917import at.hannibal2.skyhanni.utils.ConditionalUtils
@@ -32,21 +30,28 @@ import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
3230import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
3331import at.hannibal2.skyhanni.utils.SkyBlockUtils
3432import at.hannibal2.skyhanni.utils.compat.formattedTextCompatLeadingWhiteLessResets
33+ import at.hannibal2.skyhanni.utils.coroutines.CoroutineSettings
3534import at.hannibal2.skyhanni.utils.renderables.Renderable
3635import at.hannibal2.skyhanni.utils.renderables.primitives.StringRenderable
3736import net.minecraft.client.Minecraft
3837import net.minecraft.world.item.ItemStack
3938import org.lwjgl.glfw.GLFW
4039import kotlin.math.roundToLong
4140
41+ private typealias NeuGemstoneCostJson = HashMap <NeuInternalName , HashMap <String , List <String >>>
42+
4243@SkyHanniModule
4344object 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,
0 commit comments