2014-05-24 22:52:23 +02:00
|
|
|
package com.pahimar.ee3.network.message;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.reference.Key;
|
2014-07-18 21:55:10 +02:00
|
|
|
import com.pahimar.ee3.util.IKeyBound;
|
2014-05-24 22:52:23 +02:00
|
|
|
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;
|
2014-05-25 16:55:50 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-05-24 22:52:23 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2014-05-25 16:55:50 +02:00
|
|
|
EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity;
|
2014-05-24 22:52:23 +02:00
|
|
|
|
2014-05-25 16:55:50 +02:00
|
|
|
if (entityPlayer != null && entityPlayer.getCurrentEquippedItem() != null && entityPlayer.getCurrentEquippedItem().getItem() instanceof IKeyBound)
|
|
|
|
{
|
|
|
|
if (message.keyPressed == Key.CHARGE.ordinal())
|
|
|
|
{
|
|
|
|
((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.CHARGE);
|
|
|
|
}
|
|
|
|
else if (message.keyPressed == Key.EXTRA.ordinal())
|
|
|
|
{
|
|
|
|
((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.EXTRA);
|
|
|
|
}
|
|
|
|
else if (message.keyPressed == Key.RELEASE.ordinal())
|
|
|
|
{
|
|
|
|
((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.RELEASE);
|
|
|
|
}
|
|
|
|
else if (message.keyPressed == Key.TOGGLE.ordinal())
|
|
|
|
{
|
|
|
|
((IKeyBound) entityPlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(entityPlayer, entityPlayer.getCurrentEquippedItem(), Key.TOGGLE);
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 22:52:23 +02:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|