From fa60ec42f392748ac9f80cbbc63d0a897231c51a Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 6 Mar 2026 05:21:56 -0500 Subject: [PATCH] Add Support for Next / Prev Buttons for Ability Hud --- .../java/noppes/npcs/client/ClientProxy.java | 7 +++++++ .../noppes/npcs/client/KeyPressHandler.java | 20 +++++++++++++++++++ .../assets/customnpcs/lang/en_US.lang | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 3e209fa00..08342c93f 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -266,6 +266,8 @@ public class ClientProxy extends CommonProxy { public static KeyBinding NPCButton; public static KeyBinding SpecialKey; public static KeyBinding AbilityHudKey; + public static KeyBinding AbilityNextKey; + public static KeyBinding AbilityPrevKey; public static final Random RAND = new Random(); public static FontContainer Font; @@ -351,6 +353,11 @@ public class ClientProxy extends CommonProxy { AbilityHudKey = new KeyBinding("key.customnpcs.abilityHudKey", Keyboard.KEY_LMENU, "key.categories.customnpc"); ClientRegistry.registerKeyBinding(AbilityHudKey); + AbilityNextKey = new KeyBinding("key.customnpcs.abilityNext", Keyboard.KEY_NONE, "key.categories.customnpc"); + AbilityPrevKey = new KeyBinding("key.customnpcs.abilityPrev", Keyboard.KEY_NONE, "key.categories.customnpc"); + ClientRegistry.registerKeyBinding(AbilityNextKey); + ClientRegistry.registerKeyBinding(AbilityPrevKey); + new PresetController(CustomNpcs.Dir); if (ConfigMain.EnableUpdateChecker) { diff --git a/src/main/java/noppes/npcs/client/KeyPressHandler.java b/src/main/java/noppes/npcs/client/KeyPressHandler.java index 3b74b9d51..61731c522 100644 --- a/src/main/java/noppes/npcs/client/KeyPressHandler.java +++ b/src/main/java/noppes/npcs/client/KeyPressHandler.java @@ -8,6 +8,9 @@ import kamkeel.npcs.network.packets.player.SpecialKeyStatePacket; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import noppes.npcs.CustomNpcs; +import noppes.npcs.client.gui.hud.ClientHudManager; +import noppes.npcs.client.gui.hud.EnumHudComponent; +import noppes.npcs.client.gui.hud.ability.AbilityHotbarComponent; import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; import noppes.npcs.controllers.data.PlayerData; import org.lwjgl.input.Keyboard; @@ -45,6 +48,7 @@ public class KeyPressHandler { updateHeldStates(mc); handleNPCButton(mc); + handleAbilityCycleKeys(mc); if (!Keyboard.isRepeatEvent()) { int key = Keyboard.getEventKey(); @@ -69,6 +73,7 @@ public class KeyPressHandler { // Just update held states and handle keybind actions. updateHeldStates(mc); handleNPCButton(mc); + handleAbilityCycleKeys(mc); int button = Mouse.getEventButton(); if (button == -1 && Mouse.getEventDWheel() == 0) @@ -151,6 +156,21 @@ public class KeyPressHandler { } } + private static void handleAbilityCycleKeys(Minecraft mc) { + if (mc.currentScreen != null || mc.theWorld == null) return; + + AbilityHotbarComponent comp = (AbilityHotbarComponent) ClientHudManager.getInstance() + .getHudComponents().get(EnumHudComponent.AbilityHotbar); + if (comp == null || !comp.hasAnyAbilities()) return; + + if (ClientProxy.AbilityNextKey != null && ClientProxy.AbilityNextKey.isPressed()) { + comp.onCycleNext(); + } + if (ClientProxy.AbilityPrevKey != null && ClientProxy.AbilityPrevKey.isPressed()) { + comp.onCyclePrev(); + } + } + // ── Public State Queries ───────────────────────────────────────────── /** diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 11241c318..332919216 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -3,6 +3,8 @@ customnpcs.defaultTextColor=404040 key.categories.customnpc=CustomNPC+ key.customnpcs.special=Special Key key.customnpcs.abilityHudKey=HUD Key +key.customnpcs.abilityNext=Ability Next +key.customnpcs.abilityPrev=Ability Previous key.npcInventory=NPC Inventory entity.CustomNpc.name=Custom Npc