FunctionKey.java 861 B

123456789101112131415161718192021222324252627282930313233
  1. package me.km.networking;
  2. import java.util.function.Supplier;
  3. import me.km.Server;
  4. import net.minecraft.network.PacketBuffer;
  5. import net.minecraftforge.fml.network.NetworkEvent;
  6. public class FunctionKey {
  7. private final byte key;
  8. public FunctionKey() {
  9. key = -1;
  10. }
  11. public FunctionKey(int key) {
  12. this.key = (byte) key;
  13. }
  14. public static void writeBytes(FunctionKey fk, PacketBuffer buf) {
  15. buf.writeByte(fk.key);
  16. }
  17. public static FunctionKey fromBytes(PacketBuffer buf) {
  18. return new FunctionKey(buf.readByte());
  19. }
  20. public static void handle(FunctionKey fk, Supplier<NetworkEvent.Context> context) {
  21. context.get().enqueueWork(() -> {
  22. Server.scriptEvents.onFunctionKey(context.get().getSender(), fk.key);
  23. });
  24. context.get().setPacketHandled(true);
  25. }
  26. }