Class CTNetwork
java.lang.Object
com.blamejared.crafttweaker.api.network.CTNetwork
Allows scripts to send data from the server to the client.
This system provides a way for server side scripts to send data to client side only scripts, and trigger events from the server.
An example of this would be (neoforge only):
This system provides a way for server side scripts to send data to client side only scripts, and trigger events from the server.
An example of this would be (neoforge only):
// Listens to the ItemTossEvent
events.register(event => {
if event.player is ServerPlayer {
// If the player is a ServerPlayer, send data to the client using the "toss" id
network.sendTo(event.player as ServerPlayer, "toss", {custom: "data"});
}
});
// Using the 'onlyif side client' preprocessor, we can ensure script lines are only ran on the Client distribution.
#onlyif side client
// Listen for data sent to the "toss" id
network.onData("toss", (data, context) => {
// Prints the data that was received
println(data.getAsString());
});
#endif
- DocParam:
- this network
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Map<String, List<CTNetworkReceiver>> static final CTNetworkGets the global network instance -
Method Summary
Modifier and TypeMethodDescriptionvoidonData(String id, CTNetworkReceiver receiver) Receives data on the client.voidvoidSends the given data to the specified player on the specified id.
-
Field Details
-
INSTANCE
Gets the global network instance -
clientReceivers
-
-
Method Details
-
sendTo
Sends the given data to the specified player on the specified id.- Parameters:
player- The player to send the data to.id- A string that connects data receivers with data senders.data- The data to send to the client- DocParam:
- player player, id my_notification, data { custom: "data" }
-
onData
Receives data on the client.- Parameters:
id- A string that connects data receivers with data senders.receiver- A receiver that is run when the data is received from the server.- DocParam:
- id my_notification, receiver (data, context) => println(data.getAsString());
-
receive
-