diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-15 22:11:57 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-15 22:11:57 +0200 |
commit | aa6c25de0aa73ec963d1c50f4d7da8431a89f8dc (patch) | |
tree | 1ee9f8ac76837e7970142f27541e92811069d14b /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 85056a0998192037bc01290c6872cace5e1f59f8 (diff) | |
download | skyhanni-aa6c25de0aa73ec963d1c50f4d7da8431a89f8dc.tar.gz skyhanni-aa6c25de0aa73ec963d1c50f4d7da8431a89f8dc.tar.bz2 skyhanni-aa6c25de0aa73ec963d1c50f4d7da8431a89f8dc.zip |
moved garden level into garden api
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
3 files changed, 22 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 05e407781..d7469416f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -38,6 +38,13 @@ object GardenAPI { private var inBarn = false val onBarnPlot get() = inBarn && inGarden() val config get() = ProfileStorageData.profileSpecific?.garden + var gardenExp: Long? + get() = config?.experience + set(value) { + value?.let { + config?.experience = it + } + } private val barnArea = AxisAlignedBB(35.5, 70.0, -4.5, -32.5, 100.0, -46.5) @@ -203,7 +210,8 @@ object GardenAPI { return 0 } - fun getLevelForExp(gardenExp: Long): Int { + fun getGardenLevel(): Int { + val gardenExp = this.gardenExp ?: return 0 var tier = 0 var totalExp = 0L for (tierExp in gardenExperience) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index 0fa4888cc..496fe1712 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -13,7 +13,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.math.roundToInt +import kotlin.math.roundToLong import kotlin.time.Duration.Companion.milliseconds class GardenLevelDisplay { @@ -21,11 +21,6 @@ class GardenLevelDisplay { private val expToNextLevelPattern = "(?:.*) §e(?<nextLevelExp>.*)§6\\/(?:.*)".toPattern() private val overflowPattern = ".*§r §6(?<overflow>.*) XP".toPattern() private val namePattern = "Garden Level (?<currentLevel>.*)".toPattern() - private var gardenExp - get() = GardenAPI.config?.experience ?: -1 - set(value) { - GardenAPI.config?.experience = value - } private var display = "" private var visitorRewardPattern = " {4}§r§8\\+§r§2(?<exp>.*) §r§7Garden Experience".toPattern() @@ -44,9 +39,10 @@ class GardenLevelDisplay { } private fun addExp(moreExp: Int) { - val oldLevel = GardenAPI.getLevelForExp(gardenExp.toLong()) - gardenExp += moreExp - val newLevel = GardenAPI.getLevelForExp(gardenExp.toLong()) + val gardenExp = GardenAPI.gardenExp ?: return + val oldLevel = GardenAPI.getGardenLevel() + GardenAPI.gardenExp = gardenExp + moreExp + val newLevel = GardenAPI.getGardenLevel() if (newLevel == oldLevel + 1) { if (newLevel > 15) { LorenzUtils.runDelayed(50.milliseconds) { @@ -69,20 +65,20 @@ class GardenLevelDisplay { namePattern.matchMatcher(item.name!!.removeColor()) { val currentLevel = group("currentLevel").romanToDecimalIfNeeded() - var nextLevelExp = 0 + var nextLevelExp = 0L for (line in item.getLore()) { expToNextLevelPattern.matchMatcher(line) { - nextLevelExp = group("nextLevelExp").replace(",", "").toDouble().roundToInt() + nextLevelExp = group("nextLevelExp").replace(",", "").toDouble().roundToLong() } overflowPattern.matchMatcher(line) { - val overflow = group("overflow").replace(",", "").toDouble().roundToInt() - gardenExp = overflow + val overflow = group("overflow").replace(",", "").toDouble().roundToLong() + GardenAPI.gardenExp = overflow update() return } } val expForLevel = GardenAPI.getExpForLevel(currentLevel).toInt() - gardenExp = expForLevel + nextLevelExp + GardenAPI.gardenExp = expForLevel + nextLevelExp update() } } @@ -92,8 +88,8 @@ class GardenLevelDisplay { } private fun drawDisplay(): String { - if (gardenExp == -1) return "§aGarden Level ? §cOpen the desk!" - val currentLevel = GardenAPI.getLevelForExp(gardenExp.toLong()) + val gardenExp = GardenAPI.gardenExp ?: return "§aGarden Level ? §cOpen the desk!" + val currentLevel = GardenAPI.getGardenLevel() val needForLevel = GardenAPI.getExpForLevel(currentLevel).toInt() val nextLevel = currentLevel + 1 val needForNextLevel = GardenAPI.getExpForLevel(nextLevel).toInt() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt index 136917c7c..e10a8f831 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFStats.kt @@ -183,7 +183,7 @@ object FFStats { } private fun getPetFFData(item: ItemStack, out: MutableMap<FFTypes, Double>) { - val gardenLvl = GardenAPI.getLevelForExp((GardenAPI.config?.experience ?: -1).toLong()) + val gardenLvl = GardenAPI.getGardenLevel() out[FFTypes.TOTAL] = 0.0 out[FFTypes.BASE] = getPetFF(item) out[FFTypes.PET_ITEM] = when (item.getPetItem()) { |