Class CTNetwork

java.lang.Object
com.blamejared.crafttweaker.api.network.CTNetwork

@ZenRegister public class CTNetwork extends Object
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): // 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 Details

  • Method Details

    • sendTo

      public void sendTo(net.minecraft.server.level.ServerPlayer player, String id, IData data)
      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

      public void onData(String id, CTNetworkReceiver receiver)
      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

      public void receive(String id, IData data, net.minecraft.world.entity.player.Player player)