Views
Actions
Difference between revisions of "Sending Packets"
From Forge Community Wiki
(Inital Import dokuwiki) |
|||
Line 16: | Line 16: | ||
The two login packets are handled internally by forge itself. However, the other two need to be sent using <code>SimpleChannel#send</code> for <code>SimpleChannel#sendToServer</code>. Each method takes a new instance of the message to send. | The two login packets are handled internally by forge itself. However, the other two need to be sent using <code>SimpleChannel#send</code> for <code>SimpleChannel#sendToServer</code>. Each method takes a new instance of the message to send. | ||
− | == Client Packet Locations == | + | ==Client Packet Locations== |
− | It might not always be necessary to update every single client with a packet if they are not viewing the entity or are not affected by it. To specify which clients to send a packet from the server to, a <code>PacketDistributor$PacketTarget</code> must also be passed in as a parameter. There are many helpful fields that hold simple implementations of where to send which packet within <code>PacketDistributor</code>. However, they must be supplied with the required input either via <code>PacketDistributor#with</code> or <code>PacketDistributor#noArg</code> if it is going to all players. | + | * It might not always be necessary to update every single client with a packet if they are not viewing the entity or are not affected by it. To specify which clients to send a packet from the server to, a <code>PacketDistributor$PacketTarget</code> must also be passed in as a parameter. There are many helpful fields that hold simple implementations of where to send which packet within <code>PacketDistributor</code>. However, they must be supplied with the required input either via <code>PacketDistributor#with</code> or <code>PacketDistributor#noArg</code> if it is going to all players. |
+ | * | ||
Here is a list of distributors available: | Here is a list of distributors available: | ||
+ | |||
+ | <br /> | ||
+ | * <u>PLAYER:</u>Send to the specified Player. | ||
+ | * <u>DIMENSION:</u>Send to everyone in the specified dimension. | ||
+ | * <u>NEAR:</u>Send to everyone near the specified <code>PacketDistributor$TargetPoint</code> | ||
+ | * <u>ALL:</u>Send to everyone | ||
+ | * <u>SERVER:</u>Send to the server(from client) | ||
+ | * <u>TRACKING_ENTITY:</u>Send to all tracking the specified Entity<br /> | ||
+ | * <u>TRACKING_ENTITY_AND_SELF:</u>Send to all tracking the specified Entity and Player | ||
+ | * <u>TRACKING_CHUNK:</u>Send to all tracking the specified Chunk | ||
+ | * <u>NMLIST:</u>Send to each NetworkManager instance in the specified List |
Revision as of 15:50, 27 May 2023
Once a packet has been added to the network, it can be called to send a message to the side it refers to. Usually there are four different directions a packet can be sent:
Direction | Description |
---|---|
PLAY_TO_CLIENT |
A packet is sent from the server to the client during gameplay. |
PLAY_TO_SERVER |
A packet is sent from the client to the server during gameplay. |
LOGIN_TO_CLIENT |
A packet is sent to the client on initial login. |
LOGIN_TO_SERVER |
A packet is sent to the server on initial login. |
The two login packets are handled internally by forge itself. However, the other two need to be sent using SimpleChannel#send
for SimpleChannel#sendToServer
. Each method takes a new instance of the message to send.
Client Packet Locations
- It might not always be necessary to update every single client with a packet if they are not viewing the entity or are not affected by it. To specify which clients to send a packet from the server to, a
PacketDistributor$PacketTarget
must also be passed in as a parameter. There are many helpful fields that hold simple implementations of where to send which packet withinPacketDistributor
. However, they must be supplied with the required input either viaPacketDistributor#with
orPacketDistributor#noArg
if it is going to all players.
Here is a list of distributors available:
- PLAYER:Send to the specified Player.
- DIMENSION:Send to everyone in the specified dimension.
- NEAR:Send to everyone near the specified
PacketDistributor$TargetPoint
- ALL:Send to everyone
- SERVER:Send to the server(from client)
- TRACKING_ENTITY:Send to all tracking the specified Entity
- TRACKING_ENTITY_AND_SELF:Send to all tracking the specified Entity and Player
- TRACKING_CHUNK:Send to all tracking the specified Chunk
- NMLIST:Send to each NetworkManager instance in the specified List