From 80cfdfd41e79430af09e5763109dbe79a58180c6 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Wed, 14 Sep 2022 07:32:45 +0200 Subject: [PATCH] fixed the keybinds triggering when they are un binded (#9) * fix keybind triggering when un binded * translation had wrong key * it's in the same class --- .../mcp/mobius/waila/client/KeyEvent.java | 103 ++++++------------ .../resources/assets/waila/lang/nl_NL.lang | 14 +-- 2 files changed, 43 insertions(+), 74 deletions(-) diff --git a/src/main/java/mcp/mobius/waila/client/KeyEvent.java b/src/main/java/mcp/mobius/waila/client/KeyEvent.java index 8f60d0e..6ebed64 100644 --- a/src/main/java/mcp/mobius/waila/client/KeyEvent.java +++ b/src/main/java/mcp/mobius/waila/client/KeyEvent.java @@ -1,94 +1,63 @@ package mcp.mobius.waila.client; -import java.util.List; - -import org.lwjgl.input.Keyboard; - import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; import mcp.mobius.waila.api.impl.ConfigHandler; -import mcp.mobius.waila.cbcore.LangUtil; import mcp.mobius.waila.gui.screens.config.ScreenConfig; -import mcp.mobius.waila.overlay.RayTracing; import mcp.mobius.waila.utils.Constants; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.settings.KeyBinding; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.MovingObjectPosition; import net.minecraftforge.common.config.Configuration; +import org.lwjgl.input.Keyboard; public class KeyEvent { + public static KeyBinding key_cfg; public static KeyBinding key_show; public static KeyBinding key_liquid; public static KeyBinding key_recipe; public static KeyBinding key_usage; - + + public KeyEvent() { + ClientRegistry.registerKeyBinding(key_cfg = new KeyBinding(Constants.BIND_WAILA_CFG, Keyboard.KEY_NUMPAD0, "Waila")); + ClientRegistry.registerKeyBinding(key_show = new KeyBinding(Constants.BIND_WAILA_SHOW, Keyboard.KEY_NUMPAD1, "Waila")); + ClientRegistry.registerKeyBinding(key_liquid = new KeyBinding(Constants.BIND_WAILA_LIQUID, Keyboard.KEY_NUMPAD2, "Waila")); + ClientRegistry.registerKeyBinding(key_recipe = new KeyBinding(Constants.BIND_WAILA_RECIPE, Keyboard.KEY_NUMPAD3, "Waila")); + ClientRegistry.registerKeyBinding(key_usage = new KeyBinding(Constants.BIND_WAILA_USAGE, Keyboard.KEY_NUMPAD4, "Waila")); + } + @SubscribeEvent - public void onKeyEvent(KeyInputEvent event){ - int key = Keyboard.getEventKey(); - Minecraft mc = Minecraft.getMinecraft(); - - if (Keyboard.getEventKeyState()){ - if (key == key_cfg.getKeyCode()){ - if(mc.currentScreen == null) - mc.displayGuiScreen(new ScreenConfig(mc.currentScreen)); + public void onKeyEvent(KeyInputEvent event) { + if (key_cfg.isPressed()) { + Minecraft mc = Minecraft.getMinecraft(); + if (mc.currentScreen == null) { + mc.displayGuiScreen(new ScreenConfig(null)); } - - else if (key == key_show.getKeyCode() && ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)){ - boolean status = ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); - ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, !status); - } - - else if (key == key_show.getKeyCode() && !ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)){ - ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); - } - - else if (key == key_liquid.getKeyCode()){ - boolean status = ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, true); - ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, !status); - } - - else if (key == key_recipe.getKeyCode()){ - if (Loader.isModLoaded("NotEnoughItems")){ - try{ - Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler").getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, true); - } catch (Exception e){} + } else if (key_show.isPressed() && ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)) { + boolean status = ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, !status); + } else if (key_show.isPressed() && !ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_MODE, false)) { + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_SHOW, true); + } else if (key_liquid.isPressed()) { + boolean status = ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, true); + ConfigHandler.instance().setConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_LIQUID, !status); + } else if (key_recipe.isPressed()) { + if (Loader.isModLoaded("NotEnoughItems")) { + try { + Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler").getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, true); + } catch (Exception ignored) { } } - - else if (key == key_usage.getKeyCode()){ - if (Loader.isModLoaded("NotEnoughItems")){ - try{ - Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler").getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, false); - } catch (Exception e){} + } else if (key_usage.isPressed()) { + if (Loader.isModLoaded("NotEnoughItems")) { + try { + Class.forName("mcp.mobius.waila.handlers.nei.NEIHandler").getDeclaredMethod("openRecipeGUI", boolean.class).invoke(null, false); + } catch (Exception ignored) { } - } - } + } + } } - - public KeyEvent(){ - KeyEvent.key_cfg = new KeyBinding(Constants.BIND_WAILA_CFG, Keyboard.KEY_NUMPAD0, "Waila"); - KeyEvent.key_show = new KeyBinding(Constants.BIND_WAILA_SHOW, Keyboard.KEY_NUMPAD1, "Waila"); - KeyEvent.key_liquid = new KeyBinding(Constants.BIND_WAILA_LIQUID, Keyboard.KEY_NUMPAD2, "Waila"); - KeyEvent.key_recipe = new KeyBinding(Constants.BIND_WAILA_RECIPE, Keyboard.KEY_NUMPAD3, "Waila"); - KeyEvent.key_usage = new KeyBinding(Constants.BIND_WAILA_USAGE, Keyboard.KEY_NUMPAD4, "Waila"); - - ClientRegistry.registerKeyBinding(KeyEvent.key_cfg); - ClientRegistry.registerKeyBinding(KeyEvent.key_show); - ClientRegistry.registerKeyBinding(KeyEvent.key_liquid); - ClientRegistry.registerKeyBinding(KeyEvent.key_recipe); - ClientRegistry.registerKeyBinding(KeyEvent.key_usage); - /* - Minecraft.getMinecraft().gameSettings.keyBindings = (KeyBinding[])ArrayUtils.addAll( - new KeyBinding[] {KeyHandler.key_cfg, KeyHandler.key_show, KeyHandler.key_liquid}, - Minecraft.getMinecraft().gameSettings.keyBindings); - */ - } } diff --git a/src/main/resources/assets/waila/lang/nl_NL.lang b/src/main/resources/assets/waila/lang/nl_NL.lang index d0d5e3e..59f48bd 100644 --- a/src/main/resources/assets/waila/lang/nl_NL.lang +++ b/src/main/resources/assets/waila/lang/nl_NL.lang @@ -26,12 +26,12 @@ enchant.title.maxlvl=Max lvl enchant.title.weight=Gewicht enchant.label.enchantability=Enchantbaarheid -keybind.configscreen=[Waila] Configuratiescherm -keybind.showhide=[Waila] Toon/Verberg -keybind.showliquid=[Waila] Toon vloeistoffen -keybind.showrecipe=[Waila] Toon recepten -keybind.showusage=[Waila] Toon gebruik -keybind.testing=[Waila] Testen +waila.keybind.wailaconfig=[Waila] Configuratiescherm +waila.keybind.wailadisplay=[Waila] Toon/Verberg +waila.keybind.liquid=[Waila] Toon vloeistoffen +waila.keybind.recipe=[Waila] Toon recepten +waila.keybind.usage=[Waila] Toon gebruik +waila.keybind.testing=[Waila] Testen client.msg.norecipe=Geen recept gevonden. client.msg.nousage=Geen gebruik gevonden. @@ -57,7 +57,7 @@ hud.msg.frequency=Frequentie hud.msg.owner=Eigenaar hud.msg.public=Publiek hud.msg.restricted=Begrensd -hud.msg.private=Privé +hud.msg.private=Priv� hud.msg.white=Wit hud.msg.orange=Oranje