Class SimpleChannel
java.lang.Object
net.minecraftforge.network.simple.SimpleChannel
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate final IndexedMessageCodec
private final NetworkInstance
private List<Function<Boolean,
? extends List<? extends org.apache.commons.lang3.tuple.Pair<String, ?>>>> 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) Returns true 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, NetworkDirection 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, BiConsumer<MSG, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> messageConsumer) <MSG> IndexedMessageCodec.MessageHandler<MSG>
registerMessage
(int index, Class<MSG> messageType, BiConsumer<MSG, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> messageConsumer, Optional<NetworkDirection> 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, NetworkDirection direction) <MSG> void
sendToServer
(MSG message) private <MSG> org.apache.commons.lang3.tuple.Pair<FriendlyByteBuf,
Integer> toBuffer
(MSG msg) <MSG> Packet<?>
toVanillaPacket
(MSG message, NetworkDirection direction)
-
Field Details
-
instance
-
indexedCodec
-
registryChangeConsumer
private final Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeConsumer -
loginPackets
-
packetsNeedResponse
-
-
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, BiConsumer<MSG, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> messageConsumer) -
registerMessage
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, Class<MSG> messageType, BiConsumer<MSG, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> messageConsumer, Optional<NetworkDirection> 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
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, NetworkDirection 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
-