123456789101112131415161718192021222324252627282930313233 |
- package me.km.networking;
- import java.util.function.Supplier;
- import me.km.Server;
- import net.minecraft.network.PacketBuffer;
- import net.minecraftforge.fml.network.NetworkEvent;
- public class FunctionKey {
- private final byte key;
- public FunctionKey() {
- key = -1;
- }
- public FunctionKey(int key) {
- this.key = (byte) key;
- }
- public static void writeBytes(FunctionKey fk, PacketBuffer buf) {
- buf.writeByte(fk.key);
- }
- public static FunctionKey fromBytes(PacketBuffer buf) {
- return new FunctionKey(buf.readByte());
- }
- public static void handle(FunctionKey fk, Supplier<NetworkEvent.Context> context) {
- context.get().enqueueWork(() -> {
- Server.scriptEvents.onFunctionKey(context.get().getSender(), fk.key);
- });
- context.get().setPacketHandled(true);
- }
- }
|