diff options
author | jani270 <69345714+jani270@users.noreply.github.com> | 2024-06-07 13:38:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-07 13:38:11 +0200 |
commit | cfb12e7e3bbaf820f9402c286cba6bb0a33671fa (patch) | |
tree | a515fcbfd22f460871bf1c063c323afc9b8b08dc /src | |
parent | 5641066f42fef8f48eceb4cb39680a03f0b3a4db (diff) | |
download | skyhanni-cfb12e7e3bbaf820f9402c286cba6bb0a33671fa.tar.gz skyhanni-cfb12e7e3bbaf820f9402c286cba6bb0a33671fa.tar.bz2 skyhanni-cfb12e7e3bbaf820f9402c286cba6bb0a33671fa.zip |
Fix: Non Craftable Items breaking the Visitor Shopping List (#2019)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index ccac68803..3902b5ded 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -182,68 +182,80 @@ object GardenVisitorFeatures { } private fun MutableList<List<Any>>.drawShoppingList(shoppingList: MutableMap<NEUInternalName, Int>) { - if (shoppingList.isNotEmpty()) { - var totalPrice = 0.0 - addAsSingletonList("§7Visitor Shopping List:") - for ((internalName, amount) in shoppingList) { - val name = internalName.itemName - val itemStack = internalName.getItemStack() + if (shoppingList.isEmpty()) return - val list = mutableListOf<Any>() - list.add(" §7- ") - list.add(itemStack) + var totalPrice = 0.0 + addAsSingletonList("§7Visitor Shopping List:") + for ((internalName, amount) in shoppingList) { + val name = internalName.itemName + val itemStack = internalName.getItemStack() + + val list = mutableListOf<Any>() + list.add(" §7- ") + list.add(itemStack) + + list.add(Renderable.optionalLink("$name §ex${amount.addSeparators()}", { + if (Minecraft.getMinecraft().currentScreen is GuiEditSign) { + LorenzUtils.setTextIntoSign("$amount") + } else { + BazaarApi.searchForBazaarItem(name, amount) + } + }) { GardenAPI.inGarden() && !NEUItems.neuHasFocus() }) - list.add(Renderable.optionalLink("$name §ex${amount.addSeparators()}", { - if (Minecraft.getMinecraft().currentScreen is GuiEditSign) { - LorenzUtils.setTextIntoSign("$amount") - } else { - BazaarApi.searchForBazaarItem(name, amount) - } - }) { GardenAPI.inGarden() && !NEUItems.neuHasFocus() }) + if (config.shoppingList.showPrice) { + val price = internalName.getPrice() * amount + totalPrice += price + val format = NumberUtil.format(price) + list.add(" §7(§6$format§7)") + } - if (config.shoppingList.showPrice) { - val price = internalName.getPrice() * amount - totalPrice += price - val format = NumberUtil.format(price) - list.add(" §7(§6$format§7)") - } + addSackData(internalName, amount, list) - if (config.shoppingList.showSackCount) { - var amountInSacks = 0 - internalName.getAmountInSacksOrNull()?.let { - amountInSacks = it - val textColour = if (it >= amount) "a" else "e" - list.add(" §7(§${textColour}x${it.addSeparators()} §7in sacks)") - } - val ingredients = NEUItems.getRecipes(internalName) - // TODO describe what this line does - .firstOrNull() { !it.allIngredients().first().internalItemId.contains("PEST") } - ?.allIngredients() ?: return - val requiredIngredients = mutableMapOf<String, Int>() - for (ingredient in ingredients) { - val key = ingredient.internalItemId - requiredIngredients[key] = requiredIngredients.getOrDefault(key, 0) + ingredient.count.toInt() - } - var hasIngredients = true - for ((key, value) in requiredIngredients) { - val sackItem = key.asInternalName().getAmountInSacks() - if (sackItem < value * (amount - amountInSacks)) { - hasIngredients = false - break - } - } - if (hasIngredients) { - list.add(" §7(§aCraftable!§7)") - } - } + add(list) + } + if (totalPrice > 0) { + val format = NumberUtil.format(totalPrice) + this[0] = listOf("§7Visitor Shopping List: §7(§6$format§7)") + } + } - add(list) - } - if (totalPrice > 0) { - val format = NumberUtil.format(totalPrice) - this[0] = listOf("§7Visitor Shopping List: §7(§6$format§7)") + private fun addSackData( + internalName: NEUInternalName, + amount: Int, + list: MutableList<Any> + ) { + if (!config.shoppingList.showSackCount) return + + var amountInSacks = 0 + internalName.getAmountInSacksOrNull()?.let { + amountInSacks = it + val textColour = if (it >= amount) "a" else "e" + list.add(" §7(§${textColour}x${it.addSeparators()} §7in sacks)") + } + + val ingredients = NEUItems.getRecipes(internalName) + // TODO describe what this line does + .firstOrNull() { !it.allIngredients().first().internalItemId.contains("PEST") } + ?.allIngredients() ?: emptySet() + if (ingredients.isEmpty()) return + + val requiredIngredients = mutableMapOf<String, Int>() + for (ingredient in ingredients) { + val key = ingredient.internalItemId + requiredIngredients[key] = + requiredIngredients.getOrDefault(key, 0) + ingredient.count.toInt() + } + var hasIngredients = true + for ((key, value) in requiredIngredients) { + val sackItem = key.asInternalName().getAmountInSacks() + if (sackItem < value * (amount - amountInSacks)) { + hasIngredients = false + break } } + if (hasIngredients) { + list.add(" §7(§aCraftable!§7)") + } } private fun MutableList<List<Any>>.drawVisitors( |