From aa34b32d73bf8bda001693154531075132f0c8a8 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 26 Oct 2023 00:56:50 +0200 Subject: Add ping for incoming visitors, and accept hotkey (#621) Help with 2023 Halloween visitor challenge #621 --- .../skyhanni/config/features/GardenConfig.java | 17 +++++++++++- .../features/garden/visitor/GardenVisitorTimer.kt | 4 ++- .../features/garden/visitor/VisitorListener.kt | 31 +++++++++++++++++----- .../transformers/gui/AccessorGuiContainer.java | 5 ++++ 4 files changed, 49 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index 4e70150c0..29bcac5bf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -73,10 +73,15 @@ public class GardenConfig { @Expose @ConfigOption(name = "Sixth Visitor Warning", desc = "Notifies when it is believed that the sixth visitor has arrived. " + - "May be inaccurate with co-op members farming simultaneously.") + "May be inaccurate with co-op members farming simultaneously.") @ConfigEditorBoolean public boolean sixthVisitorWarning = true; + @Expose + @ConfigOption(name = "Ping when close to new visitor", desc = "Pings you when you are less than 10 seconds away from getting a new visitor.") + @ConfigEditorBoolean + public boolean pingForVisitorArrivals = false; + @Expose public Position pos = new Position(390, 65, false, true); } @@ -314,6 +319,16 @@ public class GardenConfig { @Expose public Position pos = new Position(5, 20, false, true); } + + @Expose + @ConfigOption( + name = "Accept Hotkey", + desc = "Accept a visitor when you press this keybind while in the visitor GUI" + ) + @ConfigEditorKeybind( + defaultKey = Keyboard.KEY_NONE + ) + public int acceptHotkey = Keyboard.KEY_NONE; } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index a4b86e03c..52dcd86b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -135,7 +135,9 @@ class GardenVisitorTimer { val factor = diff / 1000.0 "§7/§$formatColor" + TimeUtils.formatDuration((millis / factor).roundToLong()) } else "" - + if (config.pingForVisitorArrivals && millis < 10000){ + SoundUtils.playBeepSound() + } val formatDuration = TimeUtils.formatDuration(millis) val next = if (queueFull && (!isSixthVisitorEnabled() || millis < 0)) "§cQueue Full!" else { "Next in §$formatColor$formatDuration$extraSpeed" 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 98a48a76a..96ec316a1 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 @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.garden.visitor +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.CheckRenderEntityEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -12,6 +13,9 @@ import at.hannibal2.skyhanni.events.garden.visitor.VisitorRenderEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.VisitorStatus +import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.config +import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer +import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld @@ -22,8 +26,10 @@ import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation import at.hannibal2.skyhanni.utils.StringUtils.removeColor import io.github.moulberry.notenoughupdates.events.SlotClickEvent import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.entity.item.EntityArmorStand import net.minecraft.network.play.client.C02PacketUseEntity +import net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -103,7 +109,7 @@ class VisitorListener { } for (name in visitorsInTab) { - VisitorAPI.addVisitor(name) + VisitorAPI.addVisitor(name) } } @@ -112,7 +118,7 @@ class VisitorListener { if (!GardenAPI.inGarden()) return val npcItem = event.inventoryItems[VISITOR_INFO_ITEM_SLOT] ?: return val lore = npcItem.getLore() - if(!VisitorAPI.isVisitorInfo(lore)) return + if (!VisitorAPI.isVisitorInfo(lore)) return val offerItem = event.inventoryItems[VISITOR_ACCEPT_ITEM_SLOT] ?: return if (offerItem.name != "§aAccept Offer") return @@ -138,6 +144,17 @@ class VisitorListener { VisitorAPI.inInventory = false } + @SubscribeEvent + fun onKeybind(event: KeyboardInputEvent.Post) { + if (!VisitorAPI.inInventory) return + if (!config.acceptHotkey.isKeyHeld()) return + val inventory = event.gui as? AccessorGuiContainer ?: return + inventory as GuiContainer + val slot = inventory.inventorySlots.getSlot(29) + inventory.handleMouseClick_skyhanni(slot, slot.slotIndex, 0, 0) + } + + @SubscribeEvent(priority = EventPriority.HIGH) fun onStackClick(event: SlotClickEvent) { if (!VisitorAPI.inInventory) return @@ -158,8 +175,8 @@ class VisitorListener { LorenzUtils.chat("§e[SkyHanni] §cBlocked refusing visitor ${visitor.visitorName} §7(${it.displayName}§7)") if (config.rewardWarning.bypassKey == Keyboard.KEY_NONE) { LorenzUtils.clickableChat( - "§eIf you want to deny this visitor, set a keybind in §e/sh bypass", - "sh bypass" + "§eIf you want to deny this visitor, set a keybind in §e/sh bypass", + "sh bypass" ) } Minecraft.getMinecraft().thePlayer.closeScreen() @@ -170,7 +187,9 @@ class VisitorListener { VisitorAPI.changeStatus(visitor, VisitorStatus.REFUSED, "refused") return } - if (event.slotId == VISITOR_ACCEPT_ITEM_SLOT && event.slot.stack?.getLore()?.any { it == "§eClick to give!" } == true) { + if (event.slotId == VISITOR_ACCEPT_ITEM_SLOT && event.slot.stack?.getLore() + ?.any { it == "§eClick to give!" } == true + ) { VisitorAPI.changeStatus(visitor, VisitorStatus.ACCEPTED, "accepted") return } @@ -209,4 +228,4 @@ class VisitorListener { } } } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java index 5fbc6dee5..8ca114a1c 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.mixins.transformers.gui; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(GuiContainer.class) public interface AccessorGuiContainer { @@ -10,6 +12,9 @@ public interface AccessorGuiContainer { @Accessor("guiLeft") int getGuiLeft(); + @Invoker("handleMouseClick") + void handleMouseClick_skyhanni(Slot slotIn, int slotId, int clickedButton, int clickType); + @Accessor("guiTop") int getGuiTop(); -- cgit