Package codechicken.lib.packet
Class PacketCustomChannelBuilder
java.lang.Object
codechicken.lib.packet.PacketCustomChannelBuilder
Used to build a network channel for use with
PacketCustom.
Similar in design to NetworkRegistry.ChannelBuilder.
Created by covers1624 on 28/10/19.
-
Method Summary
Modifier and TypeMethodDescriptionassignClientHandler(Supplier<Supplier<ICustomPacketHandler.IClientPacketHandler>> clientHandler) Register a double Supplier, to construct theICustomPacketHandler.IClientPacketHandlerfor the client side.assignLoginHandler(Supplier<Supplier<ICustomPacketHandler.ILoginPacketHandler>> loginHandler) Register a double Supplier, to construct theICustomPacketHandler.ILoginPacketHandlerfor sending packets to the client during handshake.assignServerHandler(Supplier<Supplier<ICustomPacketHandler.IServerPacketHandler>> serverHandler) Register a double Supplier, to construct theICustomPacketHandler.IServerPacketHandlerfor the client side.net.minecraftforge.network.event.EventNetworkChannelbuild()Actually build and register the channel with Forge.clientAcceptedVersions(Predicate<String> clientAcceptedVersions) Register a Predicate to check the Server side protocol version on the Client.static PacketCustomChannelBuildernamed(net.minecraft.resources.ResourceLocation channelName) Create a newPacketCustomChannelBuilderwith the given channel name.networkProtocolVersion(Supplier<String> networkProtocolVersion) Register a Supplier that provides the protocol version associated with this channel.serverAcceptedVersions(Predicate<String> serverAcceptedVersions) Register a Predicate to check the Client side protocol version on the Server.
-
Method Details
-
named
public static PacketCustomChannelBuilder named(net.minecraft.resources.ResourceLocation channelName) Create a newPacketCustomChannelBuilderwith the given channel name. Channel names are global and must be unique per mod. Just use this format: "mod_id:network_name". For example: 'codechickenlib:internal'- Parameters:
channelName- The Channel name.- Returns:
- The builder.
-
networkProtocolVersion
Register a Supplier that provides the protocol version associated with this channel. You are able to compare this value each side of the connection against its local version, if you wish to talk across protocol versions. The default is to provide '1' as the version.- Parameters:
networkProtocolVersion- The version Supplier.- Returns:
- The same builder.
-
clientAcceptedVersions
Register a Predicate to check the Server side protocol version on the Client. The default will accept any remote versions.- Parameters:
clientAcceptedVersions- The Predicate.- Returns:
- The same builder.
-
serverAcceptedVersions
Register a Predicate to check the Client side protocol version on the Server. The default will accept any remote versions.- Parameters:
serverAcceptedVersions- The Predicate.- Returns:
- The same builder.
-
assignClientHandler
public PacketCustomChannelBuilder assignClientHandler(Supplier<Supplier<ICustomPacketHandler.IClientPacketHandler>> clientHandler) Register a double Supplier, to construct theICustomPacketHandler.IClientPacketHandlerfor the client side. The double Supplier is used to avoid class loading issues on the server side, you do NOT need any external sided checks if you call using the following example:
builder.assignClientHandler(() -> ClientPacketHandler::new);- Parameters:
clientHandler- The Supplier.- Returns:
- The same builder.
-
assignServerHandler
public PacketCustomChannelBuilder assignServerHandler(Supplier<Supplier<ICustomPacketHandler.IServerPacketHandler>> serverHandler) Register a double Supplier, to construct theICustomPacketHandler.IServerPacketHandlerfor the client side. The double Supplier is used to avoid confusion withassignClientHandler(java.util.function.Supplier<java.util.function.Supplier<codechicken.lib.packet.ICustomPacketHandler.IClientPacketHandler>>). Example usage:builder.assignClientHandler(() -> ServerPacketHandler::new);- Parameters:
serverHandler- The Supplier.- Returns:
- The same builder.
-
assignLoginHandler
public PacketCustomChannelBuilder assignLoginHandler(Supplier<Supplier<ICustomPacketHandler.ILoginPacketHandler>> loginHandler) Register a double Supplier, to construct theICustomPacketHandler.ILoginPacketHandlerfor sending packets to the client during handshake. SeeICustomPacketHandler.ILoginPacketHandlerfor more information. Example usage:builder.assignClientHandler(() -> ServerPacketHandler::new);- Parameters:
loginHandler- The Supplier.- Returns:
- The same builder.
-
build
public net.minecraftforge.network.event.EventNetworkChannel build()Actually build and register the channel with Forge.- Returns:
- The underlying
EventNetworkChannel
-