From bbf8a530599f84923167ceeab195a39205fa5131 Mon Sep 17 00:00:00 2001 From: Paloys <40764414+Paloys@users.noreply.github.com> Date: Sun, 26 May 2024 15:54:48 +0200 Subject: Feature: Added a "Craftable!" message to the garden visitor shopping list when craftable from sacks (#1891) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../garden/visitor/GardenVisitorFeatures.kt | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/main/java') 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 aeb049417..7dcd156a1 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 @@ -43,6 +43,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.allIngredients import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil @@ -206,10 +207,32 @@ object GardenVisitorFeatures { } 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() + 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) -- cgit