aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-27 21:53:54 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-27 21:53:54 +0100
commit4c4bb62e334be479567439bde1f9eae4c71b5959 (patch)
tree2266c0b51c6e702d5d076668f58860c78f2bff98 /src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
parentbb0d26f682e803b83d7d9252f8863285164cba15 (diff)
downloadskyhanni-4c4bb62e334be479567439bde1f9eae4c71b5959.tar.gz
skyhanni-4c4bb62e334be479567439bde1f9eae4c71b5959.tar.bz2
skyhanni-4c4bb62e334be479567439bde1f9eae4c71b5959.zip
Used reworked InventoryOpenEvent.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
index 273809ccb..d135c78cc 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
@@ -1,17 +1,15 @@
package at.hannibal2.skyhanni.data
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
-import at.hannibal2.skyhanni.utils.InventoryUtils
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.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.regex.Pattern
class SkillExperience {
@@ -46,28 +44,18 @@ class SkillExperience {
val skill = matcher.group(1).lowercase()
val overflow = matcher.group(2).formatNumber()
val neededForNextLevel = matcher.group(3).formatNumber()
- val nextLevel = getLevelForExp(neededForNextLevel)
+ val nextLevel = getLevelForExpExactly(neededForNextLevel)
val baseExp = getExpForLevel(nextLevel - 1)
skillExp[skill] = baseExp + overflow
}
- private var tick = 0
- private var dirty = true
-
@SubscribeEvent
- fun onTick(event: TickEvent.ClientTickEvent) {
- if (event.phase != TickEvent.Phase.START) return
-
- tick++
- if (tick % 20 != 0) return
- if (InventoryUtils.openInventoryName() != "Your Skills") return
+ fun onTick(event: InventoryOpenEvent) {
+ if (event.inventoryName != "Your Skills") return
- if (!dirty) return
- dirty = false
-
- for (slot in InventoryUtils.getItemsInOpenChest()) {
- val stack = slot.stack
+ for ((_, stack) in event.inventoryItems) {
val name = stack.name?.removeColor() ?: continue
+ if (!name.contains(" ")) continue
val lore = stack.getLore()
@@ -78,7 +66,6 @@ class SkillExperience {
continue
}
if (next) {
- if (!name.contains(" ")) continue
val split = name.split(" ")
val skillName = split[0].lowercase()
val level = split[1].romanToDecimal()
@@ -89,6 +76,7 @@ class SkillExperience {
val overflow = rawNumber.formatNumber()
val experience = baseExp + overflow
skillExp[skillName] = experience
+ println("skill exp: $skillName -> $experience")
}
next = false
}
@@ -97,15 +85,10 @@ class SkillExperience {
if (skillExp.isNotEmpty()) return
}
- @SubscribeEvent
- fun onWorldChange(event: WorldEvent.Load) {
- dirty = true
- }
-
companion object {
private val skillExp = mutableMapOf<String, Long>()
- private fun getLevelForExp(experience: Long): Int {
+ private fun getLevelForExpExactly(experience: Long): Int {
var level = 1
for (levelXp in levelingExp) {
if (levelXp.toLong() == experience) {
@@ -207,9 +190,7 @@ private fun String.formatNumber(): Long {
} else if (text.endsWith("m")) {
text = text.substring(0, text.length - 1)
1_000_000
- } else {
- 1
- }
+ } else 1
val d = text.toDouble()
return (d * multiplier).toLong()
}