From 368e75a26955703121bdb116503cf0544ad2e96a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:03:29 +0100 Subject: Add support for blocking quick crafting for the new quick craft UI. --- .../features/inventory/QuickCraftFeatures.kt | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt index 8b89f44a8..0126ee2f2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -23,6 +23,17 @@ class QuickCraftFeatures { private val quickCraftSlots = listOf(16, 25, 34) private var quickCraftableItems = emptyList() + enum class InventoryType(val inventoryName: String) { + CRAFT_ITEM("Craft Item"), + MORE_QUICK_CRAFT_OPTIONS("Quick Crafting"), + ; + } + + private fun InventoryType.ignoreSlot(slotNumber: Int?): Boolean = when (this) { + InventoryType.CRAFT_ITEM -> slotNumber !in quickCraftSlots + InventoryType.MORE_QUICK_CRAFT_OPTIONS -> slotNumber !in 10..44 + } + @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { quickCraftableItems = event.getConstant>("QuickCraftableItems") @@ -30,7 +41,8 @@ class QuickCraftFeatures { @SubscribeEvent fun onToolTip(event: LorenzToolTipEvent) { - if (!isEnabled() || !quickCraftSlots.contains(event.slot.slotNumber)) return + val inventoryType = getInventoryType() ?: return + if (inventoryType.ignoreSlot(event.slot.slotNumber)) return if (needsQuickCraftConfirmation(event.itemStack)) { event.toolTip.replaceAll { @@ -44,14 +56,14 @@ class QuickCraftFeatures { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!isEnabled()) return + val inventoryType = getInventoryType() ?: return if (KeyboardManager.isModifierKeyDown()) return if (event.gui !is GuiChest) return val chest = event.gui.inventorySlots as ContainerChest for (slot in chest.inventorySlots) { if (slot == null) continue - if (slot.slotNumber !in quickCraftSlots) continue + if (inventoryType.ignoreSlot(slot.slotNumber)) continue val stack = slot.stack ?: continue val name = stack.name ?: continue if (name == "§cQuick Crafting Slot") continue @@ -64,10 +76,10 @@ class QuickCraftFeatures { @SubscribeEvent(priority = EventPriority.HIGH) fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - if (!isEnabled() || !quickCraftSlots.contains(event.slot?.slotNumber)) return + val inventoryType = getInventoryType() ?: return + if (inventoryType.ignoreSlot(event.slot?.slotNumber)) return val clickedItem = event.slot?.stack ?: return - if (!KeyboardManager.isModifierKeyDown() && needsQuickCraftConfirmation(clickedItem)) { event.isCanceled = true } @@ -77,6 +89,10 @@ class QuickCraftFeatures { return !quickCraftableItems.contains(item.displayName.removeColor()) } - fun isEnabled() = - LorenzUtils.inSkyBlock && config.quickCraftingConfirmation && InventoryUtils.openInventoryName() == "Craft Item" + private fun getInventoryType(): InventoryType? { + if (!LorenzUtils.inSkyBlock || !config.quickCraftingConfirmation) return null + + val inventoryName = InventoryUtils.openInventoryName() + return InventoryType.entries.firstOrNull { it.inventoryName == inventoryName } + } } -- cgit