Class Networking

java.lang.Object
net.timtaran.interactivemc.network.Networking

public class Networking extends Object
Central networking controller for InteractiveMC.

This class serves as the core communication bridge between the mod and the underlying networking API. Instead of registering dozens of separate packet types, it manages a single "Raw Payload" channel.

Architecture:

  • All packets are serialized into a single RawPayload.
  • The first byte of the payload determines the Packet ID.
  • The ID is resolved based on the receiving side (Env.SERVER = C2S, Env.CLIENT = S2C).
  • The payload is wrapped in a VxByteBuf for convenient reading of custom types.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Initializes the networking system.
    static <T extends net.xmx.velthoric.network.IVxNetPacket>
    void
    register(dev.architectury.networking.NetworkManager.Side side, int id, Class<T> clazz, Function<net.xmx.velthoric.network.VxByteBuf,T> decoder)
    Registers a packet implementation with the network system.
    static void
    sendToAll(net.xmx.velthoric.network.IVxNetPacket packet)
    Sends a packet from the Server to all connected players.
    static void
    sendToDimension(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension, net.xmx.velthoric.network.IVxNetPacket packet)
    Sends a packet to all players in a specific dimension (Level).
    static void
    sendToPlayer(net.minecraft.server.level.ServerPlayer player, net.xmx.velthoric.network.IVxNetPacket packet)
    Sends a packet from the Server to a specific Player.
    static void
    sendToServer(net.xmx.velthoric.network.IVxNetPacket packet)
    Sends a packet from the Client to the Server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Networking

      public Networking()
  • Method Details

    • init

      public static void init()
      Initializes the networking system.

      This method registers the single RawPayload type with the Architectury NetworkManager. It must be called during the mod's initialization phase (common init).

    • register

      public static <T extends net.xmx.velthoric.network.IVxNetPacket> void register(dev.architectury.networking.NetworkManager.Side side, int id, Class<T> clazz, Function<net.xmx.velthoric.network.VxByteBuf,T> decoder)
      Registers a packet implementation with the network system.
      Type Parameters:
      T - The type of the packet, must implement IVxNetPacket.
      Parameters:
      side - The network side that receives this packet.
      id - The unique byte ID (0-255) for this packet on the given side.
      clazz - The class of the packet.
      decoder - The function used to decode the packet from a VxByteBuf.
      Throws:
      IllegalArgumentException - if the ID is already registered for the specified side.
    • sendToServer

      public static void sendToServer(net.xmx.velthoric.network.IVxNetPacket packet)
      Sends a packet from the Client to the Server.
      Parameters:
      packet - The packet to send.
    • sendToPlayer

      public static void sendToPlayer(net.minecraft.server.level.ServerPlayer player, net.xmx.velthoric.network.IVxNetPacket packet)
      Sends a packet from the Server to a specific Player.
      Parameters:
      player - The target player.
      packet - The packet to send.
    • sendToAll

      public static void sendToAll(net.xmx.velthoric.network.IVxNetPacket packet)
      Sends a packet from the Server to all connected players.
      Parameters:
      packet - The packet to send.
    • sendToDimension

      public static void sendToDimension(net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dimension, net.xmx.velthoric.network.IVxNetPacket packet)
      Sends a packet to all players in a specific dimension (Level).
      Parameters:
      dimension - The resource key of the target dimension.
      packet - The packet to send.