Class SimpleChannel
java.lang.Object
net.neoforged.neoforge.network.simple.SimpleChannel
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static final record
static class
-
Field Summary
Modifier and TypeFieldDescriptionprivate final IndexedMessageCodec
private final NetworkInstance
private final List<SimpleChannel.LoginPacketEntry>
private final Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>>
-
Constructor Summary
ModifierConstructorDescriptionSimpleChannel
(NetworkInstance instance) SimpleChannel
(NetworkInstance instance, Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify) private
SimpleChannel
(NetworkInstance instance, Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify) -
Method Summary
Modifier and TypeMethodDescription<MSG> int
encodeMessage
(MSG message, FriendlyByteBuf target) boolean
isRemotePresent
(Connection manager) Returnstrue
if the channel is present in the given connection.<M> SimpleChannel.MessageBuilder<M>
messageBuilder
(Class<M> type, int id) Build a new MessageBuilder.<M> SimpleChannel.MessageBuilder<M>
messageBuilder
(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder.private void
networkEventListener
(NetworkEvent networkEvent) private void
networkLoginGather
(NetworkEvent.GatherLoginPayloadsEvent gatherEvent) <MSG> IndexedMessageCodec.MessageHandler<MSG>
registerMessage
(int index, Class<MSG> messageType, MessageFunctions.MessageEncoder<MSG> encoder, MessageFunctions.MessageDecoder<MSG> decoder, MessageFunctions.MessageConsumer<MSG> messageConsumer) <MSG> IndexedMessageCodec.MessageHandler<MSG>
registerMessage
(int index, Class<MSG> messageType, MessageFunctions.MessageEncoder<MSG> encoder, MessageFunctions.MessageDecoder<MSG> decoder, MessageFunctions.MessageConsumer<MSG> messageConsumer, Optional<INetworkDirection<?>> networkDirection) <MSG> void
reply
(MSG msgToReply, NetworkEvent.Context context) <MSG> void
send
(PacketDistributor.PacketTarget target, MSG message) Send a message to thePacketDistributor.PacketTarget
from aPacketDistributor
instance.<MSG> void
sendTo
(MSG message, Connection manager, PlayNetworkDirection direction) <MSG> void
sendToServer
(MSG message) <M extends SimpleLoginMessage>
SimpleChannel.MessageBuilder<M>simpleLoginMessageBuilder
(Class<M> type, int id) Build a new MessageBuilder for a login message that implementsSimpleLoginMessage
.<M extends SimpleLoginMessage>
SimpleChannel.MessageBuilder<M>simpleLoginMessageBuilder
(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder for a login message that implementsSimpleLoginMessage
.<M extends SimpleMessage>
SimpleChannel.MessageBuilder<M>simpleMessageBuilder
(Class<M> type, int id) Build a new MessageBuilder for a message that implementsSimpleMessage
.<M extends SimpleMessage>
SimpleChannel.MessageBuilder<M>simpleMessageBuilder
(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder for a message that implementsSimpleMessage
.private <MSG> INetworkDirection.PacketData
toBuffer
(MSG msg) <MSG> Packet<?>
toVanillaPacket
(MSG message, PlayNetworkDirection direction)
-
Field Details
-
instance
-
indexedCodec
-
registryChangeConsumer
private final Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeConsumer -
loginPackets
-
-
Constructor Details
-
SimpleChannel
-
SimpleChannel
private SimpleChannel(NetworkInstance instance, Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify) -
SimpleChannel
public SimpleChannel(NetworkInstance instance, Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify)
-
-
Method Details
-
networkLoginGather
-
networkEventListener
-
encodeMessage
-
registerMessage
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, Class<MSG> messageType, MessageFunctions.MessageEncoder<MSG> encoder, MessageFunctions.MessageDecoder<MSG> decoder, MessageFunctions.MessageConsumer<MSG> messageConsumer) -
registerMessage
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, Class<MSG> messageType, MessageFunctions.MessageEncoder<MSG> encoder, MessageFunctions.MessageDecoder<MSG> decoder, MessageFunctions.MessageConsumer<MSG> messageConsumer, Optional<INetworkDirection<?>> networkDirection) -
toBuffer
-
sendToServer
public <MSG> void sendToServer(MSG message) -
sendTo
-
send
Send a message to thePacketDistributor.PacketTarget
from aPacketDistributor
instance.channel.send(PacketDistributor.PLAYER.with(() -> player), message)
- Type Parameters:
MSG
- The type of the message- Parameters:
target
- The curried target from a PacketDistributormessage
- The message to send
-
toVanillaPacket
-
reply
-
isRemotePresent
Returnstrue
if the channel is present in the given connection.- Returns:
true
if the channel is present in the given connection
-
messageBuilder
Build a new MessageBuilder. The type should implementIntSupplier
if it is a login packet.- Type Parameters:
M
- Type of type- Parameters:
type
- Type of messageid
- id in the indexed codec- Returns:
- a MessageBuilder
-
messageBuilder
public <M> SimpleChannel.MessageBuilder<M> messageBuilder(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder. The type should implementIntSupplier
if it is a login packet.- Type Parameters:
M
- Type of type- Parameters:
type
- Type of messageid
- id in the indexed codecdirection
- a impl direction which will be asserted before any processing of this message occurs. Use to enforce strict sided handling to prevent spoofing.- Returns:
- a MessageBuilder
-
simpleMessageBuilder
public <M extends SimpleMessage> SimpleChannel.MessageBuilder<M> simpleMessageBuilder(Class<M> type, int id) Build a new MessageBuilder for a message that implementsSimpleMessage
. This will automatically set theencoder
and the handler.- Type Parameters:
M
- the type of the message- Parameters:
type
- the type of messageid
- the id in the indexed codec- Returns:
- a MessageBuilder
-
simpleMessageBuilder
public <M extends SimpleMessage> SimpleChannel.MessageBuilder<M> simpleMessageBuilder(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder for a message that implementsSimpleMessage
. This will automatically set theencoder
and the handler.- Type Parameters:
M
- the type of the message- Parameters:
type
- the type of messageid
- the id in the indexed codecdirection
- a impl direction which will be asserted before any processing of this message occurs. Use to enforce strict sided handling to prevent spoofing.- Returns:
- a MessageBuilder
-
simpleLoginMessageBuilder
public <M extends SimpleLoginMessage> SimpleChannel.MessageBuilder<M> simpleLoginMessageBuilder(Class<M> type, int id) Build a new MessageBuilder for a login message that implementsSimpleLoginMessage
. This will automatically set theencoder
, the handler and thelogin index setter and getter
.- Type Parameters:
M
- the type of the message- Parameters:
type
- the type of messageid
- the id in the indexed codec- Returns:
- a MessageBuilder
-
simpleLoginMessageBuilder
public <M extends SimpleLoginMessage> SimpleChannel.MessageBuilder<M> simpleLoginMessageBuilder(Class<M> type, int id, INetworkDirection<?> direction) Build a new MessageBuilder for a login message that implementsSimpleLoginMessage
. This will automatically set theencoder
, the handler and thelogin index setter and getter
.- Type Parameters:
M
- the type of the message- Parameters:
type
- the type of messageid
- the id in the indexed codecdirection
- a impl direction which will be asserted before any processing of this message occurs. Use to enforce strict sided handling to prevent spoofing.- Returns:
- a MessageBuilder
-