From 5ff579652ef80207a780a80399be376c345342b0 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Fri, 12 Apr 2024 19:11:02 +0200 Subject: Backend: Remove Neu Constant (#1191) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../at/hannibal2/skyhanni/api/GetFromSackAPI.kt | 40 +++------------------- .../java/at/hannibal2/skyhanni/api/SkillAPI.kt | 32 ++++++----------- 2 files changed, 16 insertions(+), 56 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/api') diff --git a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt index 3e128292e..025b4cead 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt @@ -1,21 +1,18 @@ package at.hannibal2.skyhanni.api import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.config.ConfigManager -import at.hannibal2.skyhanni.data.jsonobjects.other.NeuSacksJson +import at.hannibal2.skyhanni.data.SackAPI import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent -import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent import at.hannibal2.skyhanni.features.commands.tabcomplete.GetFromSacksTabComplete import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ChatUtils.isCommand import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni -import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -25,9 +22,7 @@ import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveSta import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.fromJson import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.inventory.Slot import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.Deque @@ -75,11 +70,11 @@ object GetFromSackAPI { private var lastItemStack: PrimitiveItemStack? = null - var sackListInternalNames = emptySet() - private set + @Deprecated("", ReplaceWith("SackAPI.sackListInternalNames")) + val sackListInternalNames get() = SackAPI.sackListInternalNames - var sackListNames = emptySet() - private set + @Deprecated("", ReplaceWith("SackAPI.sackListNames")) + val sackListNames get() = SackAPI.sackListNames private fun addToQueue(items: List) = queue.addAll(items) @@ -222,29 +217,4 @@ object GetFromSackAPI { WRONG_AMOUNT, INTERNAL_ERROR } - - @SubscribeEvent - fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { - val data = event.getConstant("sacks") ?: ErrorManager.skyHanniError("NEU sacks data is null.") - try { - val sacksData = ConfigManager.gson.fromJson(data).sacks - val uniqueSackItems = mutableSetOf() - - sacksData.values.forEach { sackInfo -> - sackInfo.contents.forEach { content -> - uniqueSackItems.add(content) - } - } - - sackListInternalNames = uniqueSackItems.map { it.asString() }.toSet() - sackListNames = uniqueSackItems.map { it.itemNameWithoutColor.uppercase() }.toSet() - - } catch (e: Exception) { - ErrorManager.logErrorWithData( - e, "Error getting NEU sacks data, make sure your neu repo is updated.", - "sacksJson" to data - ) - Utils.showOutdatedRepoNotification() - } - } } diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt index 55384443f..bcbee1cad 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt @@ -1,10 +1,11 @@ package at.hannibal2.skyhanni.api import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuSkillLevelJson import at.hannibal2.skyhanni.events.ActionBarUpdateEvent -import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.events.SkillOverflowLevelupEvent import at.hannibal2.skyhanni.features.skillprogress.SkillProgress @@ -16,7 +17,6 @@ import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.calculateOverFlow import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getLevel import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getLevelExact import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getSkillInfo -import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.levelArray import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.xpRequiredForLevel import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.cleanName @@ -30,11 +30,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import com.google.gson.GsonBuilder import com.google.gson.annotations.Expose -import com.google.gson.reflect.TypeToken -import io.github.moulberry.notenoughupdates.util.Constants -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.command.CommandBase import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.LinkedList @@ -69,6 +65,7 @@ object SkillAPI { val storage get() = ProfileStorageData.profileSpecific?.skillData var exactLevelingMap = mapOf() var levelingMap = mapOf() + var levelArray = listOf() var activeSkill: SkillType? = null // TODO Use a map maxSkillLevel and move it into the repo @@ -135,14 +132,10 @@ object SkillAPI { } @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - val gson = GsonBuilder().create() - val xpList: List = gson.fromJson( - Utils.getElement(Constants.LEVELING, "leveling_xp").asJsonArray.toString(), - object : TypeToken>() {}.type - ) - levelingMap = xpList.withIndex().associate { (index, xp) -> index to xp } - exactLevelingMap = xpList.withIndex().associate { (index, xp) -> xp to index } + fun onNEURepoReload(event: NeuRepositoryReloadEvent) { + levelArray = event.readConstant("leveling").levelingXp + levelingMap = levelArray.withIndex().associate { (index, xp) -> index to xp } + exactLevelingMap = levelArray.withIndex().associate { (index, xp) -> xp to index } } @SubscribeEvent @@ -190,8 +183,7 @@ object SkillAPI { val splitProgress = progress.split("/") val currentXp = splitProgress.first().formatLong() val neededXp = splitProgress.last().formatLong() - val levelingArray = levelArray() - val levelXp = calculateLevelXp(levelingArray, skillLevel - 1).toLong() + val levelXp = calculateLevelXp(skillLevel - 1).toLong() skillInfo?.apply { this.currentXp = currentXp @@ -310,9 +302,8 @@ object SkillAPI { } val existingLevel = getSkillInfo(skillType) ?: SkillInfo() val xpPercentage = matcher.group("progress").formatDouble() - val levelingArray = levelArray() - val levelXp = calculateLevelXp(levelingArray, existingLevel.level - 1) - val nextLevelDiff = levelingArray[tablistLevel]?.asDouble ?: 7_600_000.0 + val levelXp = calculateLevelXp(existingLevel.level - 1) + val nextLevelDiff = levelArray.getOrNull(tablistLevel)?.toDouble() ?: 7_600_000.0 val nextLevelProgress = nextLevelDiff * xpPercentage / 100 val totalXp = levelXp + nextLevelProgress val (_, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo( @@ -341,8 +332,7 @@ object SkillAPI { val currentXp = matcher.group("current").formatLong() val maxXp = matcher.group("needed").formatLong() val level = getLevelExact(maxXp) - val levelingArray = levelArray() - val levelXp = calculateLevelXp(levelingArray, level - 1).toLong() + currentXp + val levelXp = calculateLevelXp(level - 1).toLong() + currentXp val (currentLevel, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo( level, currentXp, -- cgit