diff options
Diffstat (limited to 'src/main')
5 files changed, 20 insertions, 43 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() } diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt index ec740a223..135159106 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt @@ -3,8 +3,7 @@ package at.hannibal2.skyhanni.events import at.hannibal2.skyhanni.data.InventoryData import net.minecraft.item.ItemStack -class InventoryOpenEvent(val inventory: InventoryData.Inventory): LorenzEvent() { - +class InventoryOpenEvent(inventory: InventoryData.Inventory): LorenzEvent() { val inventoryId: Int by lazy { inventory.windowId } val inventoryName: String by lazy {inventory.title } val inventorySize: Int by lazy {inventory.slotCount } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index 5ececdff3..f8139e3b9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -1,6 +1,5 @@ package at.hannibal2.skyhanni.features.bazaar -import at.hannibal2.skyhanni.data.InventoryData import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -44,12 +43,12 @@ class BazaarApi { @SubscribeEvent fun onInventoryOpen(event: InventoryOpenEvent) { - inBazaarInventory = checkIfInBazaar(event.inventory) + inBazaarInventory = checkIfInBazaar(event) } - private fun checkIfInBazaar(inventory: InventoryData.Inventory): Boolean { - val returnItem = inventory.slotCount - 5 - for ((slot, item) in inventory.items) { + private fun checkIfInBazaar(event: InventoryOpenEvent): Boolean { + val returnItem = event.inventorySize - 5 + for ((slot, item) in event.inventoryItems) { if (slot == returnItem) { if (item.name?.removeColor().let { it == "Go Back" }) { val lore = item.getLore() @@ -60,9 +59,8 @@ class BazaarApi { } } - val title = inventory.title - if (title.startsWith("Bazaar ➜ ")) return true - return when (title) { + if (event.inventoryName.startsWith("Bazaar ➜ ")) return true + return when (event.inventoryName) { "How many do you want?" -> true "How much do you want to pay?" -> true "Confirm Buy Order" -> true diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index b3eb82c95..7a9966cc7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -36,7 +36,7 @@ class GardenVisitorFeatures { inVisitorInventory = false if (!isEnabled()) return - val npcItem = event.inventory.items[13] ?: return + val npcItem = event.inventoryItems[13] ?: return val lore = npcItem.getLore() var isVisitor = false if (lore.size == 4) { @@ -47,7 +47,7 @@ class GardenVisitorFeatures { } if (!isVisitor) return - val offerItem = event.inventory.items[29] ?: return + val offerItem = event.inventoryItems[29] ?: return if (offerItem.name != "§aAccept Offer") return inVisitorInventory = true diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt index d28d9abe4..06498031a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt @@ -30,13 +30,12 @@ class SkyMartBestProfit { fun onInventoryOpen(event: InventoryOpenEvent) { if (!isEnabled()) return - val inventory = event.inventory - if (inventory.title != "SkyMart") return + if (event.inventoryName != "SkyMart") return val priceMap = mutableMapOf<Pair<String, String>, Double>() val iconMap = mutableMapOf<String, ItemStack>() - for (stack in inventory.items.values) { + for (stack in event.inventoryItems.values) { for (line in stack.getLore()) { val matcher = pattern.matcher(line) if (!matcher.matches()) continue |