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 --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../skyhanni/config/features/InventoryConfig.java | 6 +++ .../features/inventory/QuickCraftFeatures.kt | 50 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 807669791..b972dc6bf 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -145,6 +145,7 @@ import at.hannibal2.skyhanni.features.inventory.HideNotClickableItems import at.hannibal2.skyhanni.features.inventory.HighlightBonzoMasks import at.hannibal2.skyhanni.features.inventory.ItemDisplayOverlayFeatures import at.hannibal2.skyhanni.features.inventory.ItemStars +import at.hannibal2.skyhanni.features.inventory.QuickCraftFeatures import at.hannibal2.skyhanni.features.inventory.RngMeterInventory import at.hannibal2.skyhanni.features.inventory.SackDisplay import at.hannibal2.skyhanni.features.inventory.SkyBlockLevelGuideHelper @@ -573,6 +574,7 @@ class SkyHanniMod { loadModule(DungeonTeammateOutlines()) loadModule(DungeonRankTabListColor()) loadModule(FixNEUHeavyPearls()) + loadModule(QuickCraftFeatures()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/InventoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/InventoryConfig.java index b39adb8e2..db06c9a38 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/InventoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/InventoryConfig.java @@ -375,6 +375,12 @@ public class InventoryConfig { ) public List itemNumberAsStackSize = new ArrayList<>(Arrays.asList(3, 9, 11, 12)); + @Expose + @ConfigOption(name = "Quick Craft Confirmation", desc = "Require Ctrl+Click to craft items that aren't often quick crafted (e.g. armor, weapons, accessories). Sack items can be crafted normally.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enableQuickCraftingConfirmation = false; + @Expose @ConfigOption(name = "Sack Name", desc = "Show an abbreviation of the sack name.") @ConfigEditorBoolean 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