tModLoader v2025.03
A mod to make and play Terraria mods
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
ModPacket Class Reference

Used to send data between the server and client. Syncing data is essential for keeping clients up to date with changes to the game state. ModPacket is used to sync arbitrary data, most commonly data corresponding to this mod. The Intermediate netcode wiki pageexplains more about this concept. Initialize a ModPacket using the Mod.GetPacket(int) method. This class inherits from BinaryWriter. This means that you can use all of its writing functions to send information between client and server. This class also comes with a Send(int, int) method that's used to actually send everything you've written between client and server. ModPacket has all the same methods as BinaryWriter, and some additional ones. More...

Inherits BinaryWriter.

Public Member Functions

void Send (int toClient=-1, int ignoreClient=-1)
 Sends all the information you've written to this ModPacket over the network to clients or the server. When called on a client, the data will be sent to the server and the optional parameters are ignored. When called on a server, the data will be sent to either all clients, all clients except a specific client, or just a specific client: More...
 

Detailed Description

Used to send data between the server and client. Syncing data is essential for keeping clients up to date with changes to the game state. ModPacket is used to sync arbitrary data, most commonly data corresponding to this mod. The Intermediate netcode wiki page

explains more about this concept.

Initialize a ModPacket using the Mod.GetPacket(int) method.

This class inherits from BinaryWriter. This means that you can use all of its writing functions to send information between client and server. This class also comes with a Send(int, int) method that's used to actually send everything you've written between client and server.

ModPacket has all the same methods as BinaryWriter, and some additional ones.

See also
System.IO.BinaryWriter

Member Function Documentation

◆ Send()

void ModPacket.Send ( int  toClient = -1,
int  ignoreClient = -1 
)

Sends all the information you've written to this ModPacket over the network to clients or the server. When called on a client, the data will be sent to the server and the optional parameters are ignored. When called on a server, the data will be sent to either all clients, all clients except a specific client, or just a specific client:

// Sends to all connected clients packet.Send();

// Sends to a specific client only packet.Send(toClient: somePlayer.whoAmI);

// Sends to all other clients except a specific client packet.Send(ignoreClient: somePlayer.whoAmI); Typically if data is sent from a client to the server, the server will then need to relay this to all other clients to keep them in sync. This is when the ignoreClient option will be used.