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

75 lines
2.4 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)
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;
}
@SubscribeEvent
public void handleKeyInputEvent(InputEvent.KeyInputEvent event)
{
if (getPressedKeybinding() == Key.UNKNOWN)
{
return;
}
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-23 00:35:31 +02:00
if (currentlyEquippedItemStack.getItem() instanceof IKeyBound)
{
if (entityPlayer.worldObj.isRemote)
{
PacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(getPressedKeybinding()));
2014-05-23 00:35:31 +02:00
}
else
{
((IKeyBound) currentlyEquippedItemStack.getItem()).doKeyBindingAction(entityPlayer, currentlyEquippedItemStack, getPressedKeybinding());
}
}
}
}
}
}
}