From ef14bc11b65eb8bbc11ac0e8b9f5edb9f105c5e6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:48:02 +0100 Subject: [PATCH] Improvement + Fix: Craftable Item list (#3094) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: calwolfson --- .../features/inventory/InventoryConfig.java | 2 +- .../at/hannibal2/skyhanni/data/SackAPI.kt | 3 +- .../inventory/craft/CraftableItemList.kt | 55 ++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java index 7a0aa9c7a36f..c5f17354f6dc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/InventoryConfig.java @@ -70,7 +70,7 @@ public class InventoryConfig { public ItemPickupLogConfig itemPickupLogConfig = new ItemPickupLogConfig(); @Expose - @Category(name = "Craftable Item List", desc = "") + @Category(name = "Craftable Item List", desc = "Helps to find items to §e/craft.") @Accordion public CraftableItemListConfig craftableItemList = new CraftableItemListConfig(); diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt index 9db3f0ff1ac7..da619fd9eb61 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt @@ -236,7 +236,8 @@ object SackAPI { if (savingSacks) saveSackData() } - private var sackData = mapOf() + var sackData = mapOf() + private set data class SackChange(val delta: Int, val internalName: NEUInternalName, val sacks: List) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/craft/CraftableItemList.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/craft/CraftableItemList.kt index 60ce4cf91b17..6a5328fa9401 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/craft/CraftableItemList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/craft/CraftableItemList.kt @@ -1,13 +1,15 @@ package at.hannibal2.skyhanni.features.inventory.craft import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks +import at.hannibal2.skyhanni.data.SackAPI +import at.hannibal2.skyhanni.data.model.TextInput import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc +import at.hannibal2.skyhanni.utils.CollectionUtils.toSingletonListOrEmpty import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice @@ -25,6 +27,9 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.renderables.Searchable +import at.hannibal2.skyhanni.utils.renderables.buildSearchableScrollable +import at.hannibal2.skyhanni.utils.renderables.toSearchable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.floor @@ -35,6 +40,7 @@ object CraftableItemList { private var display = listOf() private var inInventory = false + private val textInput = TextInput() private val craftItemPattern by RepoPattern.pattern( "craftableitemlist.craftitem", "Craft Item", @@ -47,23 +53,30 @@ object CraftableItemList { inInventory = true val pricePer = mutableMapOf() - val lines = mutableMapOf() + val lines = mutableMapOf() loadItems(pricePer, lines) display = if (lines.isEmpty()) { - listOf(Renderable.string("§7No Items to craft")) + Renderable.hoverTips( + "§7No Items to craft", + tips = listOf( + "§7No items found in your Inventory", + "or sacks that can be used as", + "material in crafting recipes.", + ), + ).toSingletonListOrEmpty() } else { - val items = pricePer.sortedDesc().keys.map { lines[it] ?: error("impossible") } - listOf( - Renderable.string("§eCraftable items (${items.size})"), - Renderable.scrollList(items, height = 250, velocity = 20.0), - ) + buildList { + val items = pricePer.sortedDesc().keys.map { lines[it] ?: error("impossible") } + add(Renderable.string("§e§lCraftable Items §7(${items.size})")) + add(items.buildSearchableScrollable(height = 250, textInput, velocity = 20.0)) + } } } private fun loadItems( pricePer: MutableMap, - lines: MutableMap, + lines: MutableMap, ) { val availableMaterial = readItems() for (internalName in NEUItems.allInternalNames) { @@ -83,7 +96,7 @@ object CraftableItemList { availableMaterial: Map, pricePer: MutableMap, internalName: NEUInternalName, - ): Renderable? { + ): Searchable? { val neededItems = ItemUtils.neededItems(recipe) // Just a fail save, should not happen normally if (neededItems.isEmpty()) return null @@ -94,8 +107,9 @@ object CraftableItemList { val amountFormat = canCraftAmount.addSeparators() val totalPrice = pricePer(neededItems) pricePer[internalName] = totalPrice - val tooltip = buildList { - add(internalName.itemName) + val itemName = internalName.itemName + val tooltip = buildList { + add(itemName) add("") add("§7Craft cost: §6${totalPrice.shortFormat()}") for ((item, amount) in neededItems) { @@ -106,17 +120,17 @@ object CraftableItemList { add("") add("§7You have enough materials") val timeName = StringUtils.pluralize(canCraftAmount, "time", "times") - add("§7to craft this item $amountFormat $timeName!") + add("§7to craft this item §e$amountFormat §7$timeName!") add("") add("§eClick to craft!") } return Renderable.clickAndHover( - "§8x$amountFormat ${internalName.itemName}", + "§8x$amountFormat $itemName", tips = tooltip, onClick = { HypixelCommands.viewRecipe(internalName.asString()) }, - ) + ).toSearchable(itemName) } @SubscribeEvent @@ -134,9 +148,7 @@ object CraftableItemList { ): Int { val canCraftTotal = mutableListOf() for ((name, neededAmount) in need) { - val inventory = available[name] ?: 0 - val sacks = if (config.includeSacks) name.getAmountInSacks() else 0 - val having = inventory + sacks + val having = available[name] ?: 0 val canCraft = floor(having.toDouble() / neededAmount).toInt() canCraftTotal.add(canCraft) } @@ -149,6 +161,11 @@ object CraftableItemList { val item = stack.toPrimitiveStackOrNull() ?: continue materials.addOrPut(item.internalName, item.amount.toLong()) } + if (config.includeSacks) { + for ((internalName, item) in SackAPI.sackData) { + materials.addOrPut(internalName, item.amount.toLong()) + } + } return materials } @@ -157,7 +174,7 @@ object CraftableItemList { if (!isEnabled()) return if (!inInventory) return - config.position.renderRenderables(display, posLabel = "Craft Materials From Bazaar") + config.position.renderRenderables(display, posLabel = "Craftable Item List") } fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled