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.item.IKeyBound ;
import com.pahimar.ee3.network.PacketHandler ;
import com.pahimar.ee3.network.message.MessageKeyPressed ;
import com.pahimar.ee3.reference.Key ;
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 )
{
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-24 22:52:23 +02:00
PacketHandler . INSTANCE . sendToServer ( new MessageKeyPressed ( Key . CHARGE ) ) ; // TODO Pass in the proper key pressed, but need to confirm FML SimpleNetworkWrapper fix first
2014-05-23 00:35:31 +02:00
}
else
{
( ( IKeyBound ) currentlyEquippedItemStack . getItem ( ) ) . doKeyBindingAction ( entityPlayer , currentlyEquippedItemStack , getPressedKeybinding ( ) ) ;
}
}
}
}
2014-05-02 22:06:56 +02:00
}
}
}