Working on keybindings, going to test a FML fix for SimpleNetworkWrapper later

This commit is contained in:
pahimar 2014-05-24 15:52:23 -05:00
parent 99527d35a8
commit d18a1c2f3c
3 changed files with 90 additions and 1 deletions

View file

@ -55,7 +55,7 @@ public class KeyInputEventHandler
{
if (entityPlayer.worldObj.isRemote)
{
PacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(Key.CHARGE));
PacketHandler.INSTANCE.sendToServer(new MessageKeyPressed(Key.CHARGE)); // TODO Pass in the proper key pressed, but need to confirm FML SimpleNetworkWrapper fix first
}
else
{

View file

@ -0,0 +1,83 @@
package com.pahimar.ee3.network.message;
import com.pahimar.ee3.reference.Key;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class MessageKeyPressed implements IMessage, IMessageHandler<MessageKeyPressed, IMessage>
{
private byte keyPressed;
public MessageKeyPressed()
{
}
public MessageKeyPressed(Key key)
{
if (key == Key.CHARGE)
{
this.keyPressed = (byte) Key.CHARGE.ordinal();
}
else if (key == Key.EXTRA)
{
this.keyPressed = (byte) Key.EXTRA.ordinal();
}
else if (key == Key.RELEASE)
{
this.keyPressed = (byte) Key.RELEASE.ordinal();
}
else if (key == Key.TOGGLE)
{
this.keyPressed = (byte) Key.TOGGLE.ordinal();
}
else
{
this.keyPressed = (byte) Key.UNKNOWN.ordinal();
}
}
@Override
public void fromBytes(ByteBuf buf)
{
this.keyPressed = buf.readByte();
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeByte(keyPressed);
}
@Override
public IMessage onMessage(MessageKeyPressed message, MessageContext ctx)
{
/**
* Yes I know that the entityPlayer is not correct. It appears that MessageContext never gets a nethandler set for it so
* there isn't an easy way to grab the player that sent the packet until that's resolved.
*/
// if (entityPlayer != null && entityPlayer.getCurrentEquippedItem() != null && entityPlayer.getCurrentEquippedItem().getItem() instanceof IKeyBound)
// {
// if (keyPressed == Key.CHARGE.ordinal())
// {
// ((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.CHARGE);
// }
// else if (keyPressed == Key.EXTRA.ordinal())
// {
// ((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.EXTRA);
// }
// else if (keyPressed == Key.RELEASE.ordinal())
// {
// ((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.RELEASE);
// }
// else if (keyPressed == Key.TOGGLE.ordinal())
// {
// ((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.TOGGLE);
// }
// }
return null;
}
}

View file

@ -0,0 +1,6 @@
package com.pahimar.ee3.reference;
public enum Key
{
UNKNOWN, CHARGE, EXTRA, RELEASE, TOGGLE;
}