2021-01-11 22:50:37 +01:00

50 lines
1.2 KiB
Java

package com.hbm.packet;
import com.hbm.extprop.HbmPlayerProps;
import com.hbm.handler.HbmKeybinds.EnumKeybind;
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;
import net.minecraft.entity.player.EntityPlayer;
public class KeybindPacket implements IMessage {
int key;
boolean pressed;
public KeybindPacket() { }
public KeybindPacket(EnumKeybind key, boolean pressed) {
this.key = key.ordinal();
this.pressed = pressed;
}
@Override
public void fromBytes(ByteBuf buf) {
key = buf.readInt();
pressed = buf.readBoolean();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(key);
buf.writeBoolean(pressed);
}
public static class Handler implements IMessageHandler<KeybindPacket, IMessage> {
@Override
public IMessage onMessage(KeybindPacket m, MessageContext ctx) {
EntityPlayer p = ctx.getServerHandler().playerEntity;
HbmPlayerProps props = HbmPlayerProps.getData(p);
props.setKeyPressed(EnumKeybind.values()[m.key], m.pressed);
return null;
}
}
}