Class ActiveConnection

java.lang.Object
alexiil.mc.lib.net.ActiveConnection
Direct Known Subclasses:
BufferedConnection

public abstract class ActiveConnection extends Object
An active game connection to a single receiver (and with a single sender).
  • Constructor Details

    • ActiveConnection

      public ActiveConnection(ParentNetId rootId)
  • Method Details

    • isDebuggingConnection

      protected boolean isDebuggingConnection()
    • postConstruct

      public final void postConstruct()
    • getMinecraftContext

      @Deprecated public abstract net.fabricmc.fabric.api.network.PacketContext getMinecraftContext()
      Deprecated.
      Replaced by the specific methods getPlayer() and getNetSide().
      Returns:
      The Fabric API PacketContext for this connection. Throws an error if this is not a ActiveMinecraftConnection. (Although mods will *never* need to worry about that unless they create their own netty layer for a completely different connection).
    • getNetSide

      public EnumNetSide getNetSide()
      Returns:
      The "side" of this connection. If this is an ActiveMinecraftConnection then this will be CLIENT both when writing client to server packets, and when reading packets sent from the server. (And SERVER both when writing server to client packets, and when reading client to server packets). Other connection types might throw an exception if they reuse LNS for a non-standard minecraft connection.
    • getPlayer

      public net.minecraft.entity.player.PlayerEntity getPlayer()
      Returns:
      The Minecraft PlayerEntity for this connection. Throws an error if this is not a ActiveMinecraftConnection.
    • sendPacket

      protected abstract void sendPacket(NetByteBuf data, int packetId, @Nullable NetIdBase netId, int priority)
      Parameters:
      packetId - The packet ID that has been written out to the first int of the given buffer.
      netId - The NetIdBase that is being written out. Will be null if the packet ID is one of the internal packets.
      priority - The priority for the packet. Will be either 0 or a negative number.
    • onReceiveRawData

      public void onReceiveRawData(NetByteBuf data) throws InvalidInputDataException
      Throws:
      InvalidInputDataException
    • allocBuffer

      public NetByteBuf allocBuffer()
    • allocBuffer

      public NetByteBuf allocBuffer(int initialCapacity)