Skip to content

Instantly share code, notes, and snippets.

@kevingoos
Created August 9, 2014 13:07
Show Gist options
  • Select an option

  • Save kevingoos/68639bdd168232d98c6d to your computer and use it in GitHub Desktop.

Select an option

Save kevingoos/68639bdd168232d98c6d to your computer and use it in GitHub Desktop.
public class MessageKeyPressed implements IMessage, IMessageHandler<MessageKeyPressed, IMessage> {
private byte keyPressed;
public MessageKeyPressed() {
}
public MessageKeyPressed(Key key) {
if (key == Key.TRADE) {
this.keyPressed = (byte) key.TRADE.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) {
LogHelper.info("Keypressed!");
EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity;
if (entityPlayer != null)
{
if (message.keyPressed == Key.TRADE.ordinal())
{
LogHelper.info("Starting GUI!");
entityPlayer.openGui(TradeMC.instance, GuiId.TRADE_PLAYER.ordinal(), Minecraft.getMinecraft().theWorld, 0, 0, 0);
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment