Package codechicken.lib.packet
Class StreamNetworkChannel
java.lang.Object
codechicken.lib.packet.StreamNetworkChannel
A simple Stream based network channel, very similar to the NeoForge api, however
provides raw, stream-based packets.
You would construct one of these and store it statically, see CCLNetwork for inspiration.
Created by covers1624 on 10/26/25.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA handle for constructing a packet bound for a client or the server.static interfaceA handle for constructing client-bound packets.static interfaceThe context available when executing a configuration task.static interfaceA helpful interface for the configuration phase packet handler type.static interfacestatic interfaceA factory for constructingICustomConfigurationTaskinstances.static interfaceA helpful interface for the gameplay packet handler type.static interfaceA handle for constructing server-bound packets. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassignClientHandler(StreamNetworkChannel.ClientPacketHandle handle, StreamNetworkChannel.PlayHandler handler) Assign the client-side handler for a packet.voidassignClientHandler(StreamNetworkChannel.ConfigurationPacketHandle handle, StreamNetworkChannel.ConfigurationHandler handler) Assign the client-side handler for a configuration task packet.Register a packet to configure a connecting client.voidinit(net.neoforged.bus.api.IEventBus bus, net.neoforged.fml.ModContainer container) Called with your mod event bus and mod container.optional()Mark this network channel as optional, not required on the client/server.playBidirectional(String name, StreamNetworkChannel.PlayHandler serverHandler) Register a packet to be set to either the client or the server during gameplay.playToClient(String name) Register a packet to be set to the client during gameplay.playToServer(String name, StreamNetworkChannel.PlayHandler handler) Register a packet to be set to the server during gameplay.
-
Constructor Details
-
StreamNetworkChannel
Create a new network channel.- Parameters:
namespace- The namespace, usually your mod id.
-
-
Method Details
-
init
public void init(net.neoforged.bus.api.IEventBus bus, net.neoforged.fml.ModContainer container) Called with your mod event bus and mod container.- Parameters:
bus- Your mod event bus.container- Your mod container.
-
optional
Mark this network channel as optional, not required on the client/server.- Returns:
- The same channel.
-
playToClient
Register a packet to be set to the client during gameplay.The packet handle must be assigned via
assignClientHandler(codechicken.lib.packet.StreamNetworkChannel.ClientPacketHandle, codechicken.lib.packet.StreamNetworkChannel.PlayHandler)on the client-side only.- Parameters:
name- The name of the packet.- Returns:
- A handle to construct packets.
- See Also:
-
playToServer
public StreamNetworkChannel.ServerPacketHandle playToServer(String name, StreamNetworkChannel.PlayHandler handler) Register a packet to be set to the server during gameplay.- Parameters:
name- The name of the packet.handler- The handler for the packet.- Returns:
- A handle to construct packets.
-
playBidirectional
public StreamNetworkChannel.BidirectionalPacketHandle playBidirectional(String name, StreamNetworkChannel.PlayHandler serverHandler) Register a packet to be set to either the client or the server during gameplay.The packet's client handle must be assigned via
assignClientHandler(codechicken.lib.packet.StreamNetworkChannel.ClientPacketHandle, codechicken.lib.packet.StreamNetworkChannel.PlayHandler)on the client-side only.- Parameters:
name- The name of the packet.serverHandler- The handler for the packet server-side.- Returns:
- A handle to construct packets.
- See Also:
-
assignClientHandler
public void assignClientHandler(StreamNetworkChannel.ClientPacketHandle handle, StreamNetworkChannel.PlayHandler handler) Assign the client-side handler for a packet.- Parameters:
handle- The packet handle to attach to.handler- The handler.
-
configurationToClient
public StreamNetworkChannel.ConfigurationPacketHandle configurationToClient(String name, StreamNetworkChannel.ConfigurationTaskFactory factory) Register a packet to configure a connecting client.- Parameters:
name- The name of the packet.factory- The factory to construct aICustomConfigurationTask.- Returns:
- The packet handle.
-
assignClientHandler
public void assignClientHandler(StreamNetworkChannel.ConfigurationPacketHandle handle, StreamNetworkChannel.ConfigurationHandler handler) Assign the client-side handler for a configuration task packet.- Parameters:
handle- The packet handle to attach to.handler- The handler.
-