blob: b7bd0694ac8e414c4be23207bd45413aae496552 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package at.hannibal2.skyhanni.features.inventory
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.makeShiftClick
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object ShiftClickNPCSell {
private val config get() = SkyHanniMod.feature.inventory.shiftClickNPCSell
private val sellSlot = -4
private val lastLoreLineOfSellPattern by RepoPattern.pattern(
"inventory.npc.sell.lore",
"§7them to this Shop!|§eClick to buyback!"
)
var inInventory = false
private set
fun isEnabled() = LorenzUtils.inSkyBlock && config
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
if (event.inventoryItems.isEmpty()) return
val item = event.inventoryItems[event.inventoryItems.keys.last() + sellSlot] ?: return
inInventory = lastLoreLineOfSellPattern.matches(item.getLore().lastOrNull())
}
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
inInventory = false
}
@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (!isEnabled()) return
if (!inInventory) return
val slot = event.slot ?: return
if (slot.slotNumber == slot.slotIndex) return
event.makeShiftClick()
}
}
|