From 63b83221ffb82be4b905081ebbb4be874e1b4af8 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 6 Oct 2023 15:51:42 -0300 Subject: Add optional feature to require confirmation on certain quick craft items (#478) Quick Craft Confirmation #478 --- .../features/inventory/QuickCraftFeatures.kt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt new file mode 100644 index 000000000..2cf9e688b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -0,0 +1,50 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class QuickCraftFeatures { + private val config get() = SkyHanniMod.feature.inventory + private val quickCraftSlots = listOf(16, 25, 34) + private var quickCraftableItems = emptyList() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + quickCraftableItems = event.getConstant>("QuickCraftableItems") ?: emptyList() + } + + @SubscribeEvent + fun onToolTip(event: LorenzToolTipEvent) { + if (!isEnabled() || !quickCraftSlots.contains(event.slot.slotNumber)) return + + if (needsQuickCraftConfirmation(event.itemStack)) { + event.toolTip.replaceAll { it.replace("Click to craft!", "§cCtrl+Click to craft!") } + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!isEnabled() || !quickCraftSlots.contains(event.slot?.slotNumber)) return + + val clickedItem = event.slot?.stack ?: return + + if (!LorenzUtils.isControlKeyDown() && needsQuickCraftConfirmation(clickedItem)) { + event.isCanceled = true + } + } + + private fun needsQuickCraftConfirmation(item: ItemStack): Boolean { + return !quickCraftableItems.contains(item.displayName.removeColor()) + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enableQuickCraftingConfirmation && InventoryUtils.openInventoryName() == "Craft Item" + +} \ No newline at end of file -- cgit