equivalent-exchange-3/src/main/java/com/pahimar/ee3/client/handler/KeyInputEventHandler.java

66 lines
2.5 KiB
Java
Raw Normal View History

package com.pahimar.ee3.client.handler;
2014-05-23 00:35:31 +02:00
import com.pahimar.ee3.client.settings.Keybindings;
import com.pahimar.ee3.network.PacketHandler;
import com.pahimar.ee3.network.message.MessageKeyPressed;
import com.pahimar.ee3.reference.Key;
import com.pahimar.ee3.util.IKeyBound;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2014-05-23 00:35:31 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@SideOnly(Side.CLIENT)
2023-01-03 17:47:36 +01:00
public class KeyInputEventHandler {
private static Key getPressedKeybinding() {
if (Keybindings.charge.getIsKeyPressed()) {
2014-05-23 00:35:31 +02:00
return Key.CHARGE;
2023-01-03 17:47:36 +01:00
} else if (Keybindings.extra.getIsKeyPressed()) {
2014-05-23 00:35:31 +02:00
return Key.EXTRA;
2023-01-03 17:47:36 +01:00
} else if (Keybindings.release.getIsKeyPressed()) {
2014-05-23 00:35:31 +02:00
return Key.RELEASE;
2023-01-03 17:47:36 +01:00
} else if (Keybindings.toggle.getIsKeyPressed()) {
2014-05-23 00:35:31 +02:00
return Key.TOGGLE;
}
return Key.UNKNOWN;
}
@SubscribeEvent
2023-01-03 17:47:36 +01:00
public void handleKeyInputEvent(InputEvent.KeyInputEvent event) {
if (getPressedKeybinding() == Key.UNKNOWN) {
return;
}
2023-01-03 17:47:36 +01:00
if (FMLClientHandler.instance().getClient().inGameHasFocus) {
if (FMLClientHandler.instance().getClientPlayerEntity() != null) {
EntityPlayer entityPlayer
= FMLClientHandler.instance().getClientPlayerEntity();
2014-05-23 00:35:31 +02:00
2023-01-03 17:47:36 +01:00
if (entityPlayer.getCurrentEquippedItem() != null) {
ItemStack currentlyEquippedItemStack
= entityPlayer.getCurrentEquippedItem();
2023-01-03 17:47:36 +01:00
if (currentlyEquippedItemStack.getItem() instanceof IKeyBound) {
if (entityPlayer.worldObj.isRemote) {
PacketHandler.INSTANCE.sendToServer(
new MessageKeyPressed(getPressedKeybinding())
);
} else {
((IKeyBound) currentlyEquippedItemStack.getItem())
.doKeyBindingAction(
entityPlayer,
currentlyEquippedItemStack,
getPressedKeybinding()
);
2014-05-23 00:35:31 +02:00
}
}
}
}
}
}
}