Interface IPacket<T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>

Type Parameters:
T - The type of the payload.
All Known Implementing Classes:
AbstractPacket

public interface IPacket<T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
Defines a custom payload packet. These packets must be registered using an IContentProvider.
  • Method Summary

    Modifier and Type
    Method
    Description
    Defines how the packet is meant to be sent and where it should be handled.
    void
    handle(@Nullable net.minecraft.server.level.ServerPlayer sender, boolean isServer, T payload)
    This method will be called when the custom payload is received.
    net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T>
    Gets a stream codec that can serialize the payload across the network.
    default void
    toAllPlayers(net.minecraft.server.level.ServerLevel level, T payload)
    Sends the packet from the server to all connected players.
    default void
    toAllPlayers(net.minecraft.server.MinecraftServer server, T payload)
    Sends the packet from the server to all connected players.
    default void
    toAllPlayers(net.minecraft.server.players.PlayerList playerList, T payload)
    Sends the packet from the server to all connected players.
    default void
    toPlayer(net.minecraft.server.level.ServerPlayer recipient, T payload)
    Sends the packet from the server to a specific player.
    default void
    toServer(T payload)
    Sends a packet from a client to the server.
    net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T>
    Gets the payload type.
  • Method Details

    • type

      net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type()
      Gets the payload type.
      Returns:
      The payload type.
    • streamCodec

      net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,T> streamCodec()
      Gets a stream codec that can serialize the payload across the network.
      Returns:
      The stream coded used to serialize the payload.
    • destination

      Destination destination()
      Defines how the packet is meant to be sent and where it should be handled.
      Returns:
      The intended destination of the packet.
    • handle

      void handle(@Nullable @Nullable net.minecraft.server.level.ServerPlayer sender, boolean isServer, T payload)
      This method will be called when the custom payload is received. This method can be called on both the client and server, depending on the destination type defined by destination().
      Parameters:
      sender - The sender of the packet. This will always be null for packets handled on the client.
      isServer - True when the packet is being handled on the server.
      payload - The payload that was received.
    • toPlayer

      default void toPlayer(net.minecraft.server.level.ServerPlayer recipient, T payload)
      Sends the packet from the server to a specific player.
      Parameters:
      recipient - The intended recipient of the payload.
      payload - The payload to send.
    • toAllPlayers

      default void toAllPlayers(net.minecraft.server.level.ServerLevel level, T payload)
      Sends the packet from the server to all connected players.
      Parameters:
      level - A serverside level, used to access the player list.
      payload - The payload to send.
    • toAllPlayers

      default void toAllPlayers(net.minecraft.server.MinecraftServer server, T payload)
      Sends the packet from the server to all connected players.
      Parameters:
      server - The server instance, used to access the player list.
      payload - The payload to send.
    • toAllPlayers

      default void toAllPlayers(net.minecraft.server.players.PlayerList playerList, T payload)
      Sends the packet from the server to all connected players.
      Parameters:
      playerList - The player list.
      payload - The payload to send.
    • toServer

      default void toServer(T payload)
      Sends a packet from a client to the server.
      Parameters:
      payload - The payload to send.