ModularPowersuits/src/main/java/net/machinemuse/powersuits/control/KeybindKeyHandler.java

75 lines
3.6 KiB
Java
Raw Normal View History

package net.machinemuse.powersuits.control;
2014-09-09 01:32:28 +02:00
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
2013-04-23 23:36:50 +02:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2013-01-27 22:07:19 +01:00
import net.machinemuse.powersuits.common.ModularPowersuits;
import net.machinemuse.powersuits.item.ModeChangingModularItem$;
2013-01-22 18:12:40 +01:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
2014-09-09 01:32:28 +02:00
public class KeybindKeyHandler {
2014-09-09 15:29:37 +02:00
public static final String mps = "Modular Powersuits";
2014-09-09 01:32:28 +02:00
public static KeyBinding openKeybindGUI = new KeyBinding("Open MPS Keybind GUI", -1, mps);
public static KeyBinding goDownKey = new KeyBinding("Go Down (MPS Flight Control)", Keyboard.KEY_Z, mps);
public static KeyBinding cycleToolBackward = new KeyBinding("Cycle Tool Backward (MPS)", -1, mps);
public static KeyBinding cycleToolForward = new KeyBinding("Cycle Tool Forward (MPS)", -1, mps);
public static KeyBinding zoom = new KeyBinding("Zoom (MPS)", Keyboard.KEY_Y, mps);
public static KeyBinding openCosmeticGUI = new KeyBinding("Cosmetic (MPS)", -1, mps);
public static KeyBinding[] keybindArray = new KeyBinding[]{openKeybindGUI, goDownKey, cycleToolBackward, cycleToolForward, zoom, openCosmeticGUI};
public static boolean[] repeats = new boolean[keybindArray.length];
2013-04-23 23:36:50 +02:00
public KeybindKeyHandler() {
2014-09-09 01:32:28 +02:00
for (KeyBinding key : keybindArray) {
ClientRegistry.registerKeyBinding(key);
}
2013-04-23 23:36:50 +02:00
}
2014-09-09 01:32:28 +02:00
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent e) {
int key = Keyboard.getEventKey();
boolean pressed = Keyboard.getEventKeyState();
2013-04-23 23:36:50 +02:00
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
2014-09-09 01:32:28 +02:00
// Only activate if there is a player to work with
if (player == null) {
2013-04-23 23:36:50 +02:00
return;
}
2014-09-09 15:29:37 +02:00
if (pressed) {
2014-09-09 01:32:28 +02:00
if (key == openKeybindGUI.getKeyCode()) {
World world = Minecraft.getMinecraft().theWorld;
if (Minecraft.getMinecraft().inGameHasFocus) {
2014-09-09 15:29:37 +02:00
player.openGui(ModularPowersuits.INSTANCE(), 1, world, 0, 0, 0);
2014-09-09 01:32:28 +02:00
}
2013-04-23 23:36:50 +02:00
}
2014-09-09 01:32:28 +02:00
if (key == openCosmeticGUI.getKeyCode()) {
World world = Minecraft.getMinecraft().theWorld;
if (Minecraft.getMinecraft().inGameHasFocus) {
2014-09-09 15:29:37 +02:00
player.openGui(ModularPowersuits.INSTANCE(), 3, world, 0, 0, 0);
2014-09-09 01:32:28 +02:00
}
}
if (key == goDownKey.getKeyCode()) {
PlayerInputMap.getInputMapFor(player.getCommandSenderName()).downKey = true;
}
if (key == cycleToolBackward.getKeyCode()) {
Minecraft.getMinecraft().playerController.updateController();
ModeChangingModularItem$.MODULE$.cycleModeForItem(player.inventory.getStackInSlot(player.inventory.currentItem), player, 1);
}
if (key == cycleToolForward.getKeyCode()) {
Minecraft.getMinecraft().playerController.updateController();
ModeChangingModularItem$.MODULE$.cycleModeForItem(player.inventory.getStackInSlot(player.inventory.currentItem), player, -1);
}
} else {
if (Minecraft.getMinecraft().thePlayer != null && key == goDownKey.getKeyCode()) {
PlayerInputMap.getInputMapFor(Minecraft.getMinecraft().thePlayer.getCommandSenderName()).downKey = false;
}
}
2013-04-23 23:36:50 +02:00
}
}