diff options
author | Obsidian <108832807+Obsidianninja11@users.noreply.github.com> | 2024-05-02 01:09:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 11:09:39 +0200 |
commit | f6fefac5b5ee7298dbc34f82b277a030e808ca2a (patch) | |
tree | 6cdd37cc9d364a2b006e3c645337ecc65724a228 /src/main | |
parent | 74b7e95157f5f7ae2e05f245bd2ad74eb7f73cc0 (diff) | |
download | skyhanni-f6fefac5b5ee7298dbc34f82b277a030e808ca2a.tar.gz skyhanni-f6fefac5b5ee7298dbc34f82b277a030e808ca2a.tar.bz2 skyhanni-f6fefac5b5ee7298dbc34f82b277a030e808ca2a.zip |
Fix: ClickType IDs and Visitor Reward Warning (#1639)
Diffstat (limited to 'src/main')
4 files changed, 24 insertions, 69 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt index 814f53d68..9b4d534fc 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt @@ -62,7 +62,7 @@ abstract class GuiContainerEvent(open val gui: GuiContainer, open val container: ) : GuiContainerEvent(gui, container) { fun makePickblock() { - if (this.clickedButton == 2 && this.clickTypeEnum == ClickType.HOTBAR) return + if (this.clickedButton == 2 && this.clickTypeEnum == ClickType.MIDDLE) return slot?.slotNumber?.let { slotNumber -> Minecraft.getMinecraft().playerController.windowClick( container.windowId, slotNumber, 2, 3, Minecraft.getMinecraft().thePlayer @@ -73,11 +73,11 @@ abstract class GuiContainerEvent(open val gui: GuiContainer, open val container: } enum class ClickType(val id: Int) { - NORMAL(1), - SHIFT(2), - HOTBAR(3), - MIDDLE(4), - DROP(5), + NORMAL(0), + SHIFT(1), + HOTBAR(2), + MIDDLE(3), + DROP(4), ; companion object { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index 4c0fe34f4..8c40c3562 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -217,7 +217,7 @@ object VisitorAPI { RARE_REWARD("§aRare visitor reward found", true), CHEAP_COPPER("§aCheap copper", true), EXPENSIVE_COPPER("§cExpensive copper", false), - LOW_LOSS("§cLow Loss", true), - HIGH_LOSS("§aHigh Loss", false) + LOW_LOSS("§aLow Loss", true), + HIGH_LOSS("§cHigh Loss", false) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt index 1234dd435..5dc76b5fb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.garden.visitor import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig import at.hannibal2.skyhanni.events.CheckRenderEntityEvent -import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiKeyPressEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -17,8 +16,6 @@ import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.ACCEPT_SLOT import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.INFO_SLOT import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.lastClickedNpc import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld @@ -37,7 +34,6 @@ import net.minecraft.network.play.client.C02PacketUseEntity import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard import kotlin.time.Duration.Companion.seconds class VisitorListener { @@ -142,50 +138,6 @@ class VisitorListener { } @SubscribeEvent(priority = EventPriority.HIGH) - fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - if (!VisitorAPI.inInventory) return - if (event.clickType != 0) return - - val visitor = VisitorAPI.getVisitor(lastClickedNpc) ?: return - - if (event.slotId == VISITOR_REFUSE_ITEM_SLOT) { - if (event.slot?.stack?.name != "§cRefuse Offer") return - - visitor.hasReward()?.let { - if (config.rewardWarning.preventRefusing) { - if (config.rewardWarning.bypassKey.isKeyHeld()) { - ChatUtils.chat("§cBypassed blocking refusal of visitor ${visitor.visitorName} §7(${it.displayName}§7)") - return - } - event.isCanceled = true - ChatUtils.chat("§cBlocked refusing visitor ${visitor.visitorName} §7(${it.displayName}§7)") - if (config.rewardWarning.bypassKey == Keyboard.KEY_NONE) { - ChatUtils.chatAndOpenConfig( - "§eIf you want to deny this visitor, set a keybind in §e/sh bypass", - GardenAPI.config.visitors.rewardWarning::bypassKey - ) - } - Minecraft.getMinecraft().thePlayer.closeScreen() - return - } - } - - VisitorAPI.changeStatus(visitor, VisitorAPI.VisitorStatus.REFUSED, "refused") - // fallback if tab list is disabled - DelayedRun.runDelayed(10.seconds) { - VisitorAPI.removeVisitor(visitor.visitorName) - } - return - } - if (event.slotId == VISITOR_ACCEPT_ITEM_SLOT && event.slot?.stack?.getLore() - ?.any { it == "§eClick to give!" } == true - ) { - VisitorAPI.changeStatus(visitor, VisitorAPI.VisitorStatus.ACCEPTED, "accepted") - return - } - } - - @SubscribeEvent(priority = EventPriority.HIGH) fun onTooltip(event: ItemTooltipEvent) { if (!GardenAPI.onBarnPlot) return if (!VisitorAPI.inInventory) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt index c66faf0f4..935be19c0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt @@ -6,6 +6,8 @@ import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.ACCEPT_SLOT import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.REFUSE_SLOT import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.VisitorBlockReason import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.lastClickedNpc +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld @@ -19,6 +21,7 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.absoluteValue +import kotlin.time.Duration.Companion.seconds class VisitorRewardWarning { private val config get() = VisitorAPI.config.rewardWarning @@ -65,14 +68,17 @@ class VisitorRewardWarning { return } - // clicktypes 0, 2, 3, and 4 work for interacting with visitor, but not 1 - if (event.clickTypeEnum == GuiContainerEvent.ClickType.NORMAL) return + // all but shift clicktypes work for accepting visitor + if (event.clickTypeEnum == GuiContainerEvent.ClickType.SHIFT) return if (isRefuseSlot) { VisitorAPI.changeStatus(visitor, VisitorAPI.VisitorStatus.REFUSED, "refused") + // fallback if tab list is disabled + DelayedRun.runDelayed(10.seconds) { + VisitorAPI.removeVisitor(visitor.visitorName) + } return } - if (isAcceptSlot) { - if (stack.name != "§eClick to give!") return + if (isAcceptSlot && stack.getLore().contains("§eClick to give!")) { VisitorAPI.changeStatus(visitor, VisitorAPI.VisitorStatus.ACCEPTED, "accepted") return } @@ -120,27 +126,24 @@ class VisitorRewardWarning { // TODO remove !! - best by creating new class LoadedVisitor without any nullable objects val loss = visitor.totalPrice!! - visitor.totalReward!! val formattedLoss = NumberUtil.format(loss.absoluteValue) - blockedToolTip.add(blockReason(blockReason, pricePerCopper, loss, formattedLoss)) + blockedToolTip.add(blockDescription(blockReason, pricePerCopper, loss, formattedLoss)) blockedToolTip.add(" §7(Bypass by holding ${KeyboardManager.getKeyName(config.bypassKey)})") visitor.blockedLore = blockedToolTip } - private fun blockReason( + private fun blockDescription( blockReason: VisitorBlockReason, pricePerCopper: String?, loss: Double, formattedLoss: String, - ) = when (blockReason) { + ) = blockReason.description + when (blockReason) { VisitorBlockReason.CHEAP_COPPER, VisitorBlockReason.EXPENSIVE_COPPER -> - "${blockReason.description} §7(§6$pricePerCopper §7per)" + " §7(§6$pricePerCopper §7per)" VisitorBlockReason.LOW_LOSS, VisitorBlockReason.HIGH_LOSS -> - if (loss > 0) - "${blockReason.description} §7(§6$formattedLoss §7selling §9Green Thumb I§7)" - else - "§7(§6$formattedLoss §7profit §7selling §9Green Thumb I§7)" + " §7(§6$formattedLoss §7${if (loss > 0) "loss" else "profit"} selling §9Green Thumb I§7)" - else -> blockReason.description + else -> "" } } |