diff options
| author | Brandon <brandon.wamboldt@gmail.com> | 2023-10-06 15:51:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-06 20:51:42 +0200 |
| commit | 63b83221ffb82be4b905081ebbb4be874e1b4af8 (patch) | |
| tree | 3fcd4cf60444d82ef4f41a956f9c7dac474b3e0f /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 0c35760ad4c2cc784bf8ab722ad06f4f8c250dbc (diff) | |
| download | skyhanni-63b83221ffb82be4b905081ebbb4be874e1b4af8.tar.gz skyhanni-63b83221ffb82be4b905081ebbb4be874e1b4af8.tar.bz2 skyhanni-63b83221ffb82be4b905081ebbb4be874e1b4af8.zip | |
Add optional feature to require confirmation on certain quick craft items (#478)
Quick Craft Confirmation #478
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt | 50 |
1 files changed, 50 insertions, 0 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 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<String>()
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ quickCraftableItems = event.getConstant<List<String>>("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 |
