diff options
author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2023-01-04 01:24:26 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 15:24:26 +0100 |
commit | dea9a94fb430f4c4a7ab2a8e9d642780d71423e3 (patch) | |
tree | 17c44f93ad6bc950eb2ffce5800029a8266ceb2d /src/main/java | |
parent | a683745aad92c190b64ef269ca7b15cc40e54778 (diff) | |
download | NotEnoughUpdates-dea9a94fb430f4c4a7ab2a8e9d642780d71423e3.tar.gz NotEnoughUpdates-dea9a94fb430f4c4a7ab2a8e9d642780d71423e3.tar.bz2 NotEnoughUpdates-dea9a94fb430f4c4a7ab2a8e9d642780d71423e3.zip |
Hotkeys for wardrobe slots (#494)
* Hotkeys for wardrobe slots, e.g when in the wardrobe, pressing 1 will select the first wardrobe slot
* fix wardrobe keybinds not updating
* fix up some stuff
* i suppose
* I should learn more kotlin
* considered
Diffstat (limited to 'src/main/java')
5 files changed, 203 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index bc2666d3..f10db528 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -63,6 +63,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.PowerStoneStatsDisplay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; +import io.github.moulberry.notenoughupdates.miscfeatures.WardrobeMouseButtons; import io.github.moulberry.notenoughupdates.miscfeatures.WitherCloakChanger; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; @@ -83,7 +84,6 @@ import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.FuelBar; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.recipes.KatRecipe; import io.github.moulberry.notenoughupdates.recipes.RecipeGenerator; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -349,6 +349,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(FrozenTreasuresHighlighter.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneFavourites.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneContactHelper.getInstance()); + MinecraftForge.EVENT_BUS.register(new WardrobeMouseButtons()); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt new file mode 100644 index 00000000..4e99f5a7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ +package io.github.moulberry.notenoughupdates.miscfeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.core.config.KeybindHelper +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class WardrobeMouseButtons { + + private val keybinds: List<Int> get() = listOf( + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot1, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot2, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot3, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot4, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot5, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot6, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot7, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot8, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot9, + ) + private var lastClick = -1L + + @SubscribeEvent + fun onGui(event: GuiScreenEvent) { + if (!NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.enableWardrobeKeybinds) return + val gui = event.gui as? GuiChest ?: return + if (!Utils.getOpenChestName().contains("Wardrobe")) return + + for (i in keybinds.indices) { + if (KeybindHelper.isKeyDown(keybinds[i])) { + if (System.currentTimeMillis() - lastClick > 300) { + Utils.sendLeftMouseClick(gui.inventorySlots.windowId, 36 + i) + lastClick = System.currentTimeMillis() + } + break + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index b5237a46..129f973b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; -import io.github.moulberry.notenoughupdates.options.seperateSections.WorldConfig; import io.github.moulberry.notenoughupdates.options.seperateSections.AHGraph; import io.github.moulberry.notenoughupdates.options.seperateSections.AHTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.AccessoryBag; @@ -66,6 +65,8 @@ import io.github.moulberry.notenoughupdates.options.seperateSections.StorageGUI; import io.github.moulberry.notenoughupdates.options.seperateSections.Toolbar; import io.github.moulberry.notenoughupdates.options.seperateSections.TooltipTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.TradeMenu; +import io.github.moulberry.notenoughupdates.options.seperateSections.WardrobeKeybinds; +import io.github.moulberry.notenoughupdates.options.seperateSections.WorldConfig; import io.github.moulberry.notenoughupdates.overlays.MiningOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -360,6 +361,13 @@ public class NEUConfig extends Config { @Expose @Category( + name = "Wardrobe Keybinds", + desc = "Keybinds for your wardrobe" + ) + public WardrobeKeybinds wardrobeKeybinds = new WardrobeKeybinds(); + + @Expose + @Category( name = "Accessory Bag Overlay", desc = "Accessory Bag Overlay" ) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java new file mode 100644 index 00000000..48d1b434 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.options.seperateSections; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorKeybind; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; + +public class WardrobeKeybinds { + + @Expose + @ConfigOption( + name = "Enable Wardrobe Keybinds", + desc = "Lets you use your number keys to quickly change your wardrobe" + ) + @ConfigEditorBoolean + public boolean enableWardrobeKeybinds = false; + + @ConfigOption( + name = "Wardrobe Keybinds", + desc = "" + ) + @ConfigEditorAccordion(id = 2) + public boolean wardrobeKeybindAccordion = false; + @Expose + @ConfigOption( + name = "Slot 1", + desc = "Keybind to toggle the first set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_1) + @ConfigAccordionId(id = 2) + public int wardrobeSlot1 = Keyboard.KEY_1; + + @Expose + @ConfigOption( + name = "Slot 2", + desc = "Keybind to toggle the second set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_2) + @ConfigAccordionId(id = 2) + public int wardrobeSlot2 = Keyboard.KEY_2; + + @Expose + @ConfigOption( + name = "Slot 3", + desc = "Keybind to toggle the third set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_3) + @ConfigAccordionId(id = 2) + public int wardrobeSlot3 = Keyboard.KEY_3; + + @Expose + @ConfigOption( + name = "Slot 4", + desc = "Keybind to toggle the fourth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_4) + @ConfigAccordionId(id = 2) + public int wardrobeSlot4 = Keyboard.KEY_4; + + @Expose + @ConfigOption( + name = "Slot 5", + desc = "Keybind to toggle the fifth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_5) + @ConfigAccordionId(id = 2) + public int wardrobeSlot5 = Keyboard.KEY_5; + + @Expose + @ConfigOption( + name = "Slot 6", + desc = "Keybind to toggle the sixth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_6) + @ConfigAccordionId(id = 2) + public int wardrobeSlot6 = Keyboard.KEY_6; + + @Expose + @ConfigOption( + name = "Slot 7", + desc = "Keybind to toggle the seventh set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_7) + @ConfigAccordionId(id = 2) + public int wardrobeSlot7 = Keyboard.KEY_7; + + @Expose + @ConfigOption( + name = "Slot 8", + desc = "Keybind to toggle the eighth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_8) + @ConfigAccordionId(id = 2) + public int wardrobeSlot8 = Keyboard.KEY_8; + + @Expose + @ConfigOption( + name = "Slot 9", + desc = "Keybind to toggle the ninth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_9) + @ConfigAccordionId(id = 2) + public int wardrobeSlot9 = Keyboard.KEY_9; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 0ea1dafb..571a43f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -2057,4 +2057,11 @@ public class Utils { } } } + + public static void sendLeftMouseClick(int windowId, int slot) { + Minecraft.getMinecraft().playerController.windowClick( + windowId, + slot, 0, 0, Minecraft.getMinecraft().thePlayer + ); + } } |