aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt30
1 files changed, 23 insertions, 7 deletions
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<String>()
+ 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<List<String>>("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 }
+ }
}