Class SimpleChannel
java.lang.Object
net.neoforged.neoforge.network.simple.SimpleChannel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final recordstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IndexedMessageCodecprivate final NetworkInstanceprivate final List<SimpleChannel.LoginPacketEntry>private final Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionSimpleChannel(NetworkInstance instance) SimpleChannel(NetworkInstance instance, Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify) privateSimpleChannel(NetworkInstance instance, Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify) -
Method Summary
Modifier and TypeMethodDescription<MSG> intencodeMessage(MSG message, FriendlyByteBuf target) booleanisRemotePresent(Connection manager) Returnstrueif 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 voidnetworkEventListener(NetworkEvent networkEvent) private voidnetworkLoginGather(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> voidreply(MSG msgToReply, NetworkEvent.Context context) <MSG> voidsend(PacketDistributor.PacketTarget target, MSG message) Send a message to thePacketDistributor.PacketTargetfrom aPacketDistributorinstance.<MSG> voidsendTo(MSG message, Connection manager, PlayNetworkDirection direction) <MSG> voidsendToServer(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.PacketDatatoBuffer(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.PacketTargetfrom aPacketDistributorinstance.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
Returnstrueif the channel is present in the given connection.- Returns:
trueif the channel is present in the given connection
-
messageBuilder
Build a new MessageBuilder. The type should implementIntSupplierif 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 implementIntSupplierif 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 theencoderand 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 theencoderand 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
-