Interface PacketContext

All Known Subinterfaces:
ClientPacketContext, ServerPacketContext

public interface PacketContext
Common context for packet handling.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.network.protocol.Packet<?>
    createPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
    Creates a packet from a packet payload.
    void
    disconnect(net.minecraft.network.chat.Component disconnectReason)
    Disconnects the player.
    default @Nullable net.minecraft.world.level.Level
     
    @Nullable net.minecraft.world.entity.player.Player
     
    default void
    sendPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
    Sends a packet to the other side.
    default void
    sendPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload, @Nullable net.minecraft.network.PacketSendListener callback)
    Sends a packet to the other side.
    default void
    sendPacket(net.minecraft.network.protocol.Packet<?> packet)
    Sends a packet.
    void
    sendPacket(net.minecraft.network.protocol.Packet<?> packet, @Nullable net.minecraft.network.PacketSendListener callback)
    Sends a packet.
  • Method Details

    • player

      @Nullable @Nullable net.minecraft.world.entity.player.Player player()
      Returns:
      The player that received the payload
    • level

      @Nullable default @Nullable net.minecraft.world.level.Level level()
      Returns:
      The level the context player is on
    • createPacket

      net.minecraft.network.protocol.Packet<?> createPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
      Creates a packet from a packet payload.
      Parameters:
      payload - the packet payload
    • sendPacket

      default void sendPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
      Sends a packet to the other side.
      Parameters:
      payload - the payload to create a packet from
    • sendPacket

      default void sendPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload, @Nullable @Nullable net.minecraft.network.PacketSendListener callback)
      Sends a packet to the other side.
      Parameters:
      payload - the payload to create a packet from
      callback - an optional callback to execute after the packet is sent, may be null.
    • sendPacket

      default void sendPacket(net.minecraft.network.protocol.Packet<?> packet)
      Sends a packet.
      Parameters:
      packet - the payload
    • sendPacket

      void sendPacket(net.minecraft.network.protocol.Packet<?> packet, @Nullable @Nullable net.minecraft.network.PacketSendListener callback)
      Sends a packet.
      Parameters:
      packet - the payload
      callback - an optional callback to execute after the packet is sent, may be null.
    • disconnect

      void disconnect(net.minecraft.network.chat.Component disconnectReason)
      Disconnects the player.
      Parameters:
      disconnectReason - the reason for disconnection