diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-25 10:03:29 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-25 10:03:29 +0100 |
commit | 368e75a26955703121bdb116503cf0544ad2e96a (patch) | |
tree | 28d372ea3b6242c50ca2c62d54d7f59710eee96d /src/main/java/at/hannibal2/skyhanni/features | |
parent | ef46ba9c02d395f6c884a3b819810ec394e6759b (diff) | |
download | skyhanni-368e75a26955703121bdb116503cf0544ad2e96a.tar.gz skyhanni-368e75a26955703121bdb116503cf0544ad2e96a.tar.bz2 skyhanni-368e75a26955703121bdb116503cf0544ad2e96a.zip |
Add support for blocking quick crafting for the new quick craft UI.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt | 30 |
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 }
+ }
}
|