From 74b70e212280873c1624c92a9b90da71b668ae84 Mon Sep 17 00:00:00 2001 From: The Temportalist Date: Tue, 8 Sep 2015 13:17:39 -0400 Subject: [PATCH] Update ArmorControls.java Updates for NeK 2.0.1, and in the process fixing https://github.com/mod-warriors/NotEnoughKeys/issues/34 Requires testing. --- .../java/tconstruct/client/ArmorControls.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/tconstruct/client/ArmorControls.java b/src/main/java/tconstruct/client/ArmorControls.java index ce72ed12481..205bdb5553d 100644 --- a/src/main/java/tconstruct/client/ArmorControls.java +++ b/src/main/java/tconstruct/client/ArmorControls.java @@ -4,12 +4,13 @@ import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.InputEvent; +import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; import mantle.common.network.AbstractPacket; import modwarriors.notenoughkeys.api.Api; import modwarriors.notenoughkeys.api.KeyBindingPressedEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.client.event.MouseEvent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; @@ -85,30 +86,35 @@ private static KeyBinding[] getVanillaKeyBindings() { } @SubscribeEvent - public void mouseEvent(InputEvent.MouseInputEvent event) { - if (!Loader.isModLoaded("notenoughkeys")) - this.checkKeys(); + public void mouseEvent(MouseEvent event) { + if (!Loader.isModLoaded("notenoughkeys")) this.checkKeys(event.button + 100); } @SubscribeEvent - public void keyEvent(InputEvent.KeyInputEvent event) { - if (!Loader.isModLoaded("notenoughkeys")) - this.checkKeys(); + public void keyEvent(KeyInputEvent event) { + if (!Loader.isModLoaded("notenoughkeys")) this.checkKeys(-1); } @Optional.Method(modid = "notenoughkeys") @SubscribeEvent public void keyEventSpecial(KeyBindingPressedEvent event) { - this.keyPressed(event.keyBinding); + this.sendPressed(event.keyBinding, event.isKeyBindingPressed); } - private void checkKeys() { + private void checkKeys(int keycode) { for (KeyBinding key : this.keys) { - if (key != null && this.isKeyActive(key.getKeyCode())) { - this.keyPressed(key); - } + if (keycode < 0 || key.getKeyCode() == keycode) + this.checkKeyAndSendPress(key); } } + + private void checkKeyAndSendPress(KeyBinding key) { + this.sendPress(key, this.isKeyActive(key.getKeyCode())); + } + + private void sendPress(KeyBinding key, boolean isPressed) { + if (isPressed) this.keyPressed(key); + } private boolean isKeyActive(int keyCode) { if (keyCode < 0)