2014-05-02 22:06:56 +02:00
|
|
|
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;
|
2014-07-18 21:55:10 +02:00
|
|
|
import com.pahimar.ee3.util.IKeyBound;
|
2014-05-02 22:06:56 +02:00
|
|
|
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;
|
2014-05-02 22:06:56 +02:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class KeyInputEventHandler
|
|
|
|
{
|
2014-05-23 00:35:31 +02:00
|
|
|
private static Key getPressedKeybinding()
|
|
|
|
{
|
|
|
|
if (Keybindings.charge.isPressed())
|
|
|
|
{
|
|
|
|
return Key.CHARGE;
|
|
|
|
}
|
|
|
|
else if (Keybindings.extra.isPressed())
|
|
|
|
{
|
|
|
|
return Key.EXTRA;
|
|
|
|
}
|
|
|
|
else if (Keybindings.release.isPressed())
|
|
|
|
{
|
|
|
|
return Key.RELEASE;
|
|
|
|
}
|
|
|
|
else if (Keybindings.toggle.isPressed())
|
|
|
|
{
|
|
|
|
return Key.TOGGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Key.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2014-05-02 22:06:56 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public void handleKeyInputEvent(InputEvent.KeyInputEvent event)
|
|
|
|
{
|
2015-02-05 05:48:07 +01:00
|
|
|
if (getPressedKeybinding() == Key.UNKNOWN)
|
|
|
|
{
|
2014-11-10 10:18:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-05 05:48:07 +01:00
|
|
|
|
2014-05-02 22:06:56 +02:00
|
|
|
if (FMLClientHandler.instance().getClient().inGameHasFocus)
|
|
|
|
{
|
2014-05-23 00:35:31 +02:00
|
|
|
if (FMLClientHandler.instance().getClientPlayerEntity() != null)
|
|
|
|
{
|
|
|
|
EntityPlayer entityPlayer = FMLClientHandler.instance().getClientPlayerEntity();
|
|
|
|
|
|
|
|
if (entityPlayer.getCurrentEquippedItem() != null)
|
|
|
|
{
|
|
|
|
ItemStack currentlyEquippedItemStack = entityPlayer.getCurrentEquippedItem();
|
2014-05-02 22:06:56 +02:00
|
|
|
|
2014-05-23 00:35:31 +02:00
|
|
|
if (currentlyEquippedItemStack.getItem() instanceof IKeyBound)
|
|
|
|
{
|
|
|
|
if (entityPlayer.worldObj.isRemote)
|
|
|
|
{
|
2014-05-25 16:55:50 +02:00
|
|
|
PacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(getPressedKeybinding()));
|
2014-05-23 00:35:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((IKeyBound) currentlyEquippedItemStack.getItem()).doKeyBindingAction(entityPlayer, currentlyEquippedItemStack, getPressedKeybinding());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-02 22:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|