Interface ServerPlayNetworking.PlayPayloadHandler<T extends CustomPayload>

Type Parameters:
T - the type of the packet
Enclosing class:
ServerPlayNetworking
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface ServerPlayNetworking.PlayPayloadHandler<T extends CustomPayload>
A thread-safe packet handler utilizing CustomPayload.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Handles the incoming packet.
  • Method Details

    • receive

      void receive(T payload, ServerPlayNetworking.Context context)
      Handles the incoming packet. This is called on the server thread, and can safely manipulate the world.

      An example usage of this is to create an explosion where the player is looking:

      
       // use PayloadTypeRegistry for registering the payload
       ServerPlayNetworking.registerReceiver(BoomPayload.ID, (payload, player, responseSender) -> {
       	ModPacketHandler.createExplosion(player, payload.fire());
       });
       

      The server and the network handler can be accessed via ServerPlayerEntity.server and ServerPlayerEntity.networkHandler, respectively.

      Parameters:
      payload - the packet payload
      context - the play networking context
      See Also: