aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-02 14:21:09 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-02 14:21:09 +0100
commit35d358151fdd3a344a28407a1da950d99f62675c (patch)
tree82c6ce7d46acccc222dc7f818136c5e56ab4dd54 /src/main/java/at/hannibal2/skyhanni/features
parent017edfa6eaca6b682a68c16fc0a9c621ebaf1177 (diff)
downloadskyhanni-35d358151fdd3a344a28407a1da950d99f62675c.tar.gz
skyhanni-35d358151fdd3a344a28407a1da950d99f62675c.tar.bz2
skyhanni-35d358151fdd3a344a28407a1da950d99f62675c.zip
Preparations
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt61
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt8
2 files changed, 9 insertions, 60 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
index c0ae5d6fa..bae238577 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
@@ -32,13 +32,10 @@ class MinionCraftHelper {
private val tierOneMinionsDone = mutableListOf<String>()
private val allIngredients = mutableListOf<String>()
private val alreadyNotified = mutableListOf<String>()
- private val recipesCache = mutableMapOf<String, List<NeuRecipe>>()
- private var multiplierCache = mutableMapOf<String, Pair<String, Int>>()
@SubscribeEvent
fun onWorldChange(event: WorldEvent.Load) {
alreadyNotified.clear()
- recipesCache.clear()
}
@SubscribeEvent
@@ -101,7 +98,7 @@ class MinionCraftHelper {
minions[name] = rawId
} else {
if (!allIngredients.contains(rawId)) continue
- val (itemId, multiplier) = getMultiplier(rawId)
+ val (itemId, multiplier) = NEUItems.getMultiplier(rawId)
val old = otherItems.getOrDefault(itemId, 0)
otherItems[itemId] = old + item.stackSize * multiplier
}
@@ -121,7 +118,7 @@ class MinionCraftHelper {
}
if (internalId.contains("_GENERATOR_")) {
- for (recipe in getRecipes(internalId)) {
+ for (recipe in NEUItems.getRecipes(internalId)) {
if (recipe !is CraftingRecipe) continue
for (ingredient in recipe.ingredients) {
@@ -148,7 +145,7 @@ class MinionCraftHelper {
}
for (minionId in tierOneMinionsFiltered) {
- for (recipe in getRecipes(minionId)) {
+ for (recipe in NEUItems.getRecipes(minionId)) {
if (recipe !is CraftingRecipe) continue
if (recipe.ingredients.any { help.contains(it.internalItemId) }) {
val name = recipe.output.itemStack.name!!.removeColor()
@@ -164,7 +161,7 @@ class MinionCraftHelper {
val minionName = "§9$name Minion $nextTier"
display.add(minionName)
val nextMinionId = minionId.addOneToId()
- val recipes: List<NeuRecipe> = getRecipes(nextMinionId)
+ val recipes: List<NeuRecipe> = NEUItems.getRecipes(nextMinionId)
for (recipe in recipes) {
if (recipe !is CraftingRecipe) continue
val output = recipe.output
@@ -181,7 +178,7 @@ class MinionCraftHelper {
}
var allDone = true
for ((rawId, need) in map) {
- val (itemId, multiplier) = getMultiplier(rawId)
+ val (itemId, multiplier) = NEUItems.getMultiplier(rawId)
val needAmount = need * multiplier
val have = otherItems.getOrDefault(itemId, 0)
val percentage = have.toDouble() / needAmount
@@ -213,15 +210,6 @@ class MinionCraftHelper {
SkyHanniMod.feature.bingo.minionCraftHelperPos.renderStrings(display, center = true)
}
- private fun getRecipes(minionId: String): List<NeuRecipe> {
- if (recipesCache.contains(minionId)) {
- return recipesCache[minionId]!!
- }
- val recipes = NEUItems.manager.getAvailableRecipesFor(minionId)
- recipesCache[minionId] = recipes
- return recipes
- }
-
private fun notify(minionName: String) {
if (alreadyNotified.contains(minionName)) return
@@ -234,43 +222,4 @@ class MinionCraftHelper {
val next = lastText.toInt() + 1
return replace(lastText, "" + next)
}
-
-
- private fun getMultiplier(rawId: String, tryCount: Int = 0, parent: String? = null): Pair<String, Int> {
- if (multiplierCache.contains(rawId)) {
- return multiplierCache[rawId]!!
- }
- if (tryCount == 10) {
- val message = "Error reading getMultiplier for item '$rawId'"
- Error(message).printStackTrace()
- LorenzUtils.error(message)
- return Pair(rawId, 1)
- }
- for (recipe in getRecipes(rawId)) {
- if (recipe !is CraftingRecipe) continue
-
- val map = mutableMapOf<String, Int>()
- for (ingredient in recipe.ingredients) {
- val count = ingredient.count.toInt()
- val internalItemId = ingredient.internalItemId
- val old = map.getOrDefault(internalItemId, 0)
- map[internalItemId] = old + count
- }
- if (map.size != 1) continue
- val current = map.iterator().next().toPair()
- val id = current.first
- return if (id != parent) {
- val child = getMultiplier(id, tryCount + 1, rawId)
- val result = Pair(child.first, child.second * current.second)
- multiplierCache[rawId] = result
- result
- } else {
- Pair(parent, 1)
- }
- }
-
- val result = Pair(rawId, 1)
- multiplierCache[rawId] = result
- return result
- }
}
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 b9fb4ee5f..a43f9671f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
@@ -140,7 +140,7 @@ class GardenVisitorFeatures {
var totalPrice = 0.0
var amountDifferentItems = 0
var endReached = false
- for ((i, l) in list.withIndex()) {
+ for ((i, l) in list.toMutableList().withIndex()) {
val line = l.substring(4)
if (line == "") {
if (amountDifferentItems > 1) {
@@ -153,9 +153,9 @@ class GardenVisitorFeatures {
if (i > 1 && !endReached) {
val (itemName, amount) = ItemUtils.readItemAmount(line)
if (itemName != null) {
- val lowestBin: Double
+ val internalName: String
try {
- lowestBin = NEUItems.getPrice(NEUItems.getInternalName(itemName))
+ internalName = NEUItems.getInternalName(itemName)
} catch (e: NullPointerException) {
val message = "internal name is null: '$itemName'"
println(message)
@@ -163,7 +163,7 @@ class GardenVisitorFeatures {
e.printStackTrace()
return
}
- val price = lowestBin * amount
+ val price = NEUItems.getPrice(internalName) * amount
totalPrice += price
val format = NumberUtil.format(price)
list[i] = "$line §7(§6$format§7)"