aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeRaid <77941535+SeRaid743@users.noreply.github.com>2024-05-03 00:41:48 +1200
committerGitHub <noreply@github.com>2024-05-02 14:41:48 +0200
commit510c025c11a186254176273a93dcf48535907212 (patch)
tree8064f3b8b317b428a5dc0079bb1d16c8a37d6c30
parent382f226797a2fae468c950a6941b74fd5d525404 (diff)
downloadskyhanni-510c025c11a186254176273a93dcf48535907212.tar.gz
skyhanni-510c025c11a186254176273a93dcf48535907212.tar.bz2
skyhanni-510c025c11a186254176273a93dcf48535907212.zip
Chocfactorykeybinds (#1644)
Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryKeybindsConfig.java41
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/GuiKeyPressEvent.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryKeybinds.kt51
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt6
7 files changed, 113 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index ff58c9e61..a32036d5e 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -273,6 +273,7 @@ import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactor
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryBarnManager
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryDataLoader
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryInventory
+import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryKeybinds
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryShortcut
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStats
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryTimeTowerManager
@@ -643,6 +644,7 @@ class SkyHanniMod {
loadModule(ChocolateFactoryTooltipCompact)
loadModule(ChocolateFactoryTimeTowerManager)
loadModule(ChocolateFactoryTooltip)
+ loadModule(ChocolateFactoryKeybinds)
loadModule(ChocolateShopPrice)
loadModule(ChocolateFactoryUpgradeWarning)
loadModule(HoppityNpc)
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java
index fab7e5ce3..d6f8a24fb 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java
@@ -154,4 +154,9 @@ public class ChocolateFactoryConfig {
@Accordion
public ChocolateShopPriceConfig chocolateShopPrice = new ChocolateShopPriceConfig();
+ @Expose
+ @ConfigOption(name = "Chocolate Factory Keybinds", desc = "")
+ @Accordion
+ public ChocolateFactoryKeybindsConfig keybinds = new ChocolateFactoryKeybindsConfig();
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryKeybindsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryKeybindsConfig.java
new file mode 100644
index 000000000..7e68a1d7a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryKeybindsConfig.java
@@ -0,0 +1,41 @@
+package at.hannibal2.skyhanni.config.features.inventory.chocolatefactory;
+
+import at.hannibal2.skyhanni.config.FeatureToggle;
+import com.google.gson.annotations.Expose;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
+import org.lwjgl.input.Keyboard;
+
+public class ChocolateFactoryKeybindsConfig {
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "In the Chocolate Factory, press buttons with your number row on the keyboard to upgrade the rabbits.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = false;
+
+ @Expose
+ @ConfigOption(name = "Key 1", desc = "Key for Rabbit Bro.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_1)
+ public int key1 = Keyboard.KEY_1;
+
+ @Expose
+ @ConfigOption(name = "Key 2", desc = "Key for Rabbit Cousin.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_2)
+ public int key2 = Keyboard.KEY_2;
+
+ @Expose
+ @ConfigOption(name = "Key 3", desc = "Key for Rabbit Sis.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_3)
+ public int key3 = Keyboard.KEY_3;
+
+ @Expose
+ @ConfigOption(name = "Key 4", desc = "Key for Rabbit Daddy.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_4)
+ public int key4 = Keyboard.KEY_4;
+
+ @Expose
+ @ConfigOption(name = "Key 5", desc = "Key for Rabbit Granny.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_5)
+ public int key5 = Keyboard.KEY_5;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GuiKeyPressEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GuiKeyPressEvent.kt
index 1c420d743..4cfd1dfd9 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/GuiKeyPressEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/GuiKeyPressEvent.kt
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.events
import net.minecraft.client.gui.inventory.GuiContainer
+import net.minecraftforge.fml.common.eventhandler.Cancelable
+@Cancelable
class GuiKeyPressEvent(val guiContainer: GuiContainer) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt
index ff239fc66..44f8a51b6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HarpFeatures.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.inventory
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.GuiKeyPressEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.RenderItemTipEvent
@@ -20,7 +21,6 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.item.Item
-import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
import kotlin.time.Duration.Companion.milliseconds
@@ -34,17 +34,6 @@ object HarpFeatures {
private const val closeButtonSlot = 40
- private object KeyIterable : Iterable<Int> {
-
- override fun iterator() = object : Iterator<Int> {
- private var currentIndex = 0
-
- override fun hasNext() = currentIndex < 7
-
- override fun next() = getKey(currentIndex++) ?: throw NoSuchElementException("currentIndex: $currentIndex")
- }
- }
-
private val buttonColors = listOf('d', 'e', 'a', '2', '5', '9', 'b')
private val patternGroup = RepoPattern.group("harp")
@@ -65,16 +54,19 @@ object HarpFeatures {
private fun isMenuGui(chestName: String) = menuTitlePattern.matches(chestName)
@SubscribeEvent
- fun onGui(event: GuiScreenEvent) {
+ fun onGui(event: GuiKeyPressEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.keybinds) return
if (!isHarpGui(InventoryUtils.openInventoryName())) return
- val chest = event.gui as? GuiChest ?: return
+ val chest = event.guiContainer as? GuiChest ?: return
- for ((index, key) in KeyIterable.withIndex()) {
+ for (index in 0..6) {
+ val key = getKey(index) ?: error("no key for index $index")
if (!key.isKeyHeld()) continue
if (lastClick.passedSince() < 200.milliseconds) break
+ event.cancel()
+
Minecraft.getMinecraft().playerController.windowClick(
chest.inventorySlots.windowId,
37 + index,
@@ -87,7 +79,7 @@ object HarpFeatures {
}
}
- fun getKey(index: Int) = when (index) {
+ private fun getKey(index: Int) = when (index) {
0 -> config.harpKeybinds.key1
1 -> config.harpKeybinds.key2
2 -> config.harpKeybinds.key3
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryKeybinds.kt
new file mode 100644
index 000000000..ca4ec9705
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryKeybinds.kt
@@ -0,0 +1,51 @@
+package at.hannibal2.skyhanni.features.inventory.chocolatefactory
+
+import at.hannibal2.skyhanni.events.GuiKeyPressEvent
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
+
+object ChocolateFactoryKeybinds {
+ private val config get() = ChocolateFactoryAPI.config.keybinds
+ private var lastClick = SimpleTimeMark.farPast()
+
+ @SubscribeEvent
+ fun onKeyPress(event: GuiKeyPressEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.enabled) return
+ if (!ChocolateFactoryAPI.inChocolateFactory) return
+
+ val chest = event.guiContainer as? GuiChest ?: return
+
+ for (index in 0..4) {
+ val key = getKey(index) ?: error("no key for index $index")
+ if (!key.isKeyClicked()) continue
+ if (lastClick.passedSince() < 200.milliseconds) break
+ lastClick = SimpleTimeMark.now()
+
+ event.cancel()
+
+ Minecraft.getMinecraft().playerController.windowClick(
+ chest.inventorySlots.windowId,
+ 29 + index,
+ 2,
+ 3,
+ Minecraft.getMinecraft().thePlayer
+ )
+ break
+ }
+ }
+
+ private fun getKey(index: Int) = when (index) {
+ 0 -> config.key1
+ 1 -> config.key2
+ 2 -> config.key3
+ 3 -> config.key4
+ 4 -> config.key5
+ else -> null
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
index 32562bde7..20e8cab67 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt
@@ -49,9 +49,11 @@ object KeyboardManager {
fun getModifierKeyName(): String = if (SystemUtils.IS_OS_MAC) "Command" else "Control"
@SubscribeEvent
- fun onGuiScreenKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) {
+ fun onGuiScreenKeybind(event: GuiScreenEvent.KeyboardInputEvent.Pre) {
val guiScreen = event.gui as? GuiContainer ?: return
- GuiKeyPressEvent(guiScreen).postAndCatch()
+ if (GuiKeyPressEvent(guiScreen).postAndCatch()) {
+ event.isCanceled = true
+ }
}
@SubscribeEvent