Class ChannelBuilder

java.lang.Object
net.minecraftforge.network.ChannelBuilder

public class ChannelBuilder extends Object
Builder for constructing impl channels using a builder style API.
  • Field Details

  • Constructor Details

  • Method Details

    • named

      public static ChannelBuilder named(String channelName)
      Creates a new channel builder, The name of the channel must be unique.
      Parameters:
      channelName - The name of the channel
    • named

      public static ChannelBuilder named(ResourceLocation channelName)
      Creates a new channel builder, The name of the channel must be unique.
      Parameters:
      channelName - The name of the channel
    • networkProtocolVersion

      public ChannelBuilder networkProtocolVersion(int version)
      The impl protocol version for this channel. This will be gathered during login and sent to the remote partner, where it will be tested with against the relevant predicate.
      Defaults to 0
      Throws:
      IllegalArgumentException - if version is < 0
      See Also:
      • #serverAcceptedVersions(Predicate)
      • #clientAcceptedVersions(Predicate)
    • acceptedVersions

      public ChannelBuilder acceptedVersions(Channel.VersionTest test)
      A predicate run on both sides, with the networkProtocolVersion(int) from the server, the channel on the remote side.
      Defaults to only accepting current version and requiring it to be present.
      Parameters:
      test - A predicate for testing
      See Also:
    • clientAcceptedVersions

      public ChannelBuilder clientAcceptedVersions(Channel.VersionTest test)
      A predicate run on the client, with the networkProtocolVersion(int) from the server, the channel on the remote side.
      Defaults to only accepting current version.
      Parameters:
      test - A predicate for testing
      See Also:
    • serverAcceptedVersions

      public ChannelBuilder serverAcceptedVersions(Channel.VersionTest test)
      A predicate run on the server, with the networkProtocolVersion(int) from the server, the channel on the remote side.
      Defaults to only accepting current version.
      Parameters:
      test - A predicate for testing
      See Also:
    • optional

      public ChannelBuilder optional()
      Allows a client to connect to a server that is missing this channel. And allows a server to accept a client missing this channel. This includes vanilla connections.
    • optionalServer

      public ChannelBuilder optionalServer()
      Allows a client to connect to a server that is missing this channel.
    • optionalClient

      public ChannelBuilder optionalClient()
      Tells the server to accept clients that are missing this channel.
    • attribute

      public <T> ChannelBuilder attribute(io.netty.util.AttributeKey<T> key, Supplier<T> factory)
      Registers a AttributeKey to be filled when a new connection is created. This is meant as a simple way to attach data on a per-connection bases.
      Parameters:
      key - The key to assign
      factory - A factory that creates a new instance of the context data
    • attribute

      public <T> ChannelBuilder attribute(io.netty.util.AttributeKey<T> key, Function<Connection,T> factory)
      Registers a AttributeKey to be filled when a new connection is created. This is meant as a simple way to attach data on a per-connection bases.
      Parameters:
      key - The key to assign
      factory - A factory that creates a new instance of the context data
    • connectionHandler

      public ChannelBuilder connectionHandler(Consumer<Connection> handler)
      Registers a function that will be called when a new connection is established. This is meant to allow you to do basic configuration and add context objects. This is equivalent to the ConnectionStartEvent
    • createNetworkInstance

      private NetworkInstance createNetworkInstance()
      Create the impl instance
      Returns:
      the NetworkInstance
    • getClientAcceptedVersions

      private Channel.VersionTest getClientAcceptedVersions()
    • getServerAcceptedVersions

      private Channel.VersionTest getServerAcceptedVersions()
    • simpleChannel

      public SimpleChannel simpleChannel()
      Build a new SimpleChannel with this builder's configuration.
      Returns:
      A new SimpleChannel
    • eventNetworkChannel

      public EventNetworkChannel eventNetworkChannel()
      Build a new EventNetworkChannel with this builder's configuration.
      Returns:
      A new EventNetworkChannel