Skip to content

Commit

Permalink
Update ArmorControls.java
Browse files Browse the repository at this point in the history
Updates for NeK 2.0.1, and in the process fixing mod-warriors/NotEnoughKeys#34
Requires testing.
  • Loading branch information
TheTemportalist committed Sep 8, 2015
1 parent ba18f02 commit 74b70e2
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/java/tconstruct/client/ArmorControls.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 74b70e2

Please sign in to comment.