Package net.minecraftforge.network
Class ChannelBuilder
java.lang.Object
net.minecraftforge.network.ChannelBuilder
Builder for constructing impl channels using a builder style API.
-
Field Summary
Modifier and TypeFieldDescriptionprivate Map
<io.netty.util.AttributeKey<?>, Function<Connection, ?>> private Channel.VersionTest
private Consumer
<Connection> private final ResourceLocation
private int
private boolean
private Channel.VersionTest
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionA predicate run on both sides, with thenetworkProtocolVersion(int)
from the server, the channel on the remote side.<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.<T> ChannelBuilder
Registers a AttributeKey to be filled when a new connection is created.<C> C
channel
(Function<NetworkInstance, C> factory) Registers this channel with theinvalid reference
NetworkManager
A predicate run on the client, with thenetworkProtocolVersion(int)
from the server, the channel on the remote side.connectionHandler
(Consumer<Connection> handler) Registers a function that will be called when a new connection is established.private NetworkInstance
Create the impl instanceBuild a newEventNetworkChannel
with this builder's configuration.private Channel.VersionTest
private Channel.VersionTest
static ChannelBuilder
Creates a new channel builder, The name of the channel must be unique.static ChannelBuilder
named
(ResourceLocation channelName) Creates a new channel builder, The name of the channel must be unique.networkProtocolVersion
(int version) The impl protocol version for this channel.optional()
Allows a client to connect to a server that is missing this channel.Tells the server to accept clients that are missing this channel.Allows a client to connect to a server that is missing this channel.Build a newPayloadChannel
with this builder's configuration.A predicate run on the server, with thenetworkProtocolVersion(int)
from the server, the channel on the remote side.Build a newSimpleChannel
with this builder's configuration.
-
Field Details
-
name
-
networkProtocolVersion
private int networkProtocolVersion -
clientAcceptedVersions
-
serverAcceptedVersions
-
attributes
-
connectionHandler
-
registerSelf
private boolean registerSelf
-
-
Constructor Details
-
ChannelBuilder
-
-
Method Details
-
named
Creates a new channel builder, The name of the channel must be unique.- Parameters:
channelName
- The name of the channel
-
named
Creates a new channel builder, The name of the channel must be unique.- Parameters:
channelName
- The name of the channel
-
networkProtocolVersion
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 invalid input: '<' 0- See Also:
-
acceptedVersions
A predicate run on both sides, with thenetworkProtocolVersion(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
A predicate run on the client, with thenetworkProtocolVersion(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
A predicate run on the server, with thenetworkProtocolVersion(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
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
Allows a client to connect to a server that is missing this channel. -
optionalClient
Tells the server to accept clients that are missing this channel. -
attribute
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 assignfactory
- 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 assignfactory
- A factory that creates a new instance of the context data
-
connectionHandler
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 theConnectionStartEvent
-
createNetworkInstance
Create the impl instance- Returns:
- the
NetworkInstance
-
getClientAcceptedVersions
-
getServerAcceptedVersions
-
simpleChannel
Build a newSimpleChannel
with this builder's configuration.- Returns:
- A new
SimpleChannel
-
eventNetworkChannel
Build a newEventNetworkChannel
with this builder's configuration.- Returns:
- A new
EventNetworkChannel
-
payloadChannel
Build a newPayloadChannel
with this builder's configuration.- Returns:
- A new
PayloadConnection<CustomPacketPayloadinvalid input: '>'
-
channel
Registers this channel with theinvalid reference
NetworkManager
-