Guest User

PacketHandler

a guest
Oct 27th, 2020
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PacketHandler {
  2.  
  3. public static int networkId = 0;
  4.  
  5. private static final String NETWORK_PROTOCOL_VERSION = "1";
  6. public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(
  7. new ResourceLocation(Main.MOD_ID, "main"),
  8. () -> NETWORK_PROTOCOL_VERSION,
  9. NETWORK_PROTOCOL_VERSION::equals,
  10. NETWORK_PROTOCOL_VERSION::equals
  11. );
  12.  
  13. public static void register() {
  14. CHANNEL.registerMessage(networkId++,
  15. PacketUpdateContainer.class,
  16. PacketUpdateContainer::encode,
  17. PacketUpdateContainer::decode,
  18. PacketUpdateContainer::handle,
  19. Optional.of(NetworkDirection.PLAY_TO_SERVER)
  20. );
  21. }
  22.  
  23. public static void sendToServer(Object message) {
  24. CHANNEL.sendToServer(message);
  25. }
  26. }
  27.  
RAW Paste Data