Class SimpleChannel
- java.lang.Object
-
- net.minecraftforge.fml.network.simple.SimpleChannel
-
public class SimpleChannel extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SimpleChannel.MessageBuilder<MSG>
-
Field Summary
Fields Modifier and Type Field Description private IndexedMessageCodec
indexedCodec
private NetworkInstance
instance
private java.util.List<java.util.function.Function<java.lang.Boolean,? extends java.util.List<? extends org.apache.commons.lang3.tuple.Pair<java.lang.String,?>>>>
loginPackets
private java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>>
registryChangeConsumer
-
Constructor Summary
Constructors Modifier Constructor Description SimpleChannel(NetworkInstance instance)
SimpleChannel(NetworkInstance instance, java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify)
private
SimpleChannel(NetworkInstance instance, java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <MSG> int
encodeMessage(MSG message, PacketBuffer target)
boolean
isRemotePresent(NetworkManager manager)
Returns true if the channel is present in the given connection.<M> SimpleChannel.MessageBuilder<M>
messageBuilder(java.lang.Class<M> type, int id)
Build a new MessageBuilder.<M> SimpleChannel.MessageBuilder<M>
messageBuilder(java.lang.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, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer)
<MSG> IndexedMessageCodec.MessageHandler<MSG>
registerMessage(int index, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer, java.util.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, NetworkManager manager, NetworkDirection direction)
<MSG> void
sendToServer(MSG message)
private <MSG> org.apache.commons.lang3.tuple.Pair<PacketBuffer,java.lang.Integer>
toBuffer(MSG msg)
<MSG> IPacket<?>
toVanillaPacket(MSG message, NetworkDirection direction)
-
-
-
Field Detail
-
instance
private final NetworkInstance instance
-
indexedCodec
private final IndexedMessageCodec indexedCodec
-
registryChangeConsumer
private final java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeConsumer
-
loginPackets
private java.util.List<java.util.function.Function<java.lang.Boolean,? extends java.util.List<? extends org.apache.commons.lang3.tuple.Pair<java.lang.String,?>>>> loginPackets
-
-
Constructor Detail
-
SimpleChannel
public SimpleChannel(NetworkInstance instance)
-
SimpleChannel
private SimpleChannel(NetworkInstance instance, java.util.Optional<java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> registryChangeNotify)
-
SimpleChannel
public SimpleChannel(NetworkInstance instance, java.util.function.Consumer<NetworkEvent.ChannelRegistrationChangeEvent> registryChangeNotify)
-
-
Method Detail
-
networkLoginGather
private void networkLoginGather(NetworkEvent.GatherLoginPayloadsEvent gatherEvent)
-
networkEventListener
private void networkEventListener(NetworkEvent networkEvent)
-
encodeMessage
public <MSG> int encodeMessage(MSG message, PacketBuffer target)
-
registerMessage
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer)
-
registerMessage
public <MSG> IndexedMessageCodec.MessageHandler<MSG> registerMessage(int index, java.lang.Class<MSG> messageType, java.util.function.BiConsumer<MSG,PacketBuffer> encoder, java.util.function.Function<PacketBuffer,MSG> decoder, java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> messageConsumer, java.util.Optional<NetworkDirection> networkDirection)
-
toBuffer
private <MSG> org.apache.commons.lang3.tuple.Pair<PacketBuffer,java.lang.Integer> toBuffer(MSG msg)
-
sendToServer
public <MSG> void sendToServer(MSG message)
-
sendTo
public <MSG> void sendTo(MSG message, NetworkManager manager, NetworkDirection direction)
-
send
public <MSG> void send(PacketDistributor.PacketTarget target, MSG message)
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
public <MSG> IPacket<?> toVanillaPacket(MSG message, NetworkDirection direction)
-
reply
public <MSG> void reply(MSG msgToReply, NetworkEvent.Context context)
-
isRemotePresent
public boolean isRemotePresent(NetworkManager manager)
Returns true if the channel is present in the given connection.
-
messageBuilder
public <M> SimpleChannel.MessageBuilder<M> messageBuilder(java.lang.Class<M> type, int id)
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(java.lang.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 network direction which will be asserted before any processing of this message occurs. Use to enforce strict sided handling to prevent spoofing.- Returns:
- a MessageBuilder
-
-