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, context) -> {
       	ModPacketHandler.createExplosion(context.player(), payload.fire());
       });
       

      The network handler can be accessed via ServerPlayerEntity.networkHandler.

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