Class Networking
java.lang.Object
net.timtaran.interactivemc.network.Networking
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
VxByteBuffor convenient reading of custom types.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinit()Initializes the networking system.static <T extends net.xmx.velthoric.network.IVxNetPacket>
voidregister(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 voidsendToAll(net.xmx.velthoric.network.IVxNetPacket packet) Sends a packet from the Server to all connected players.static voidsendToDimension(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 voidsendToPlayer(net.minecraft.server.level.ServerPlayer player, net.xmx.velthoric.network.IVxNetPacket packet) Sends a packet from the Server to a specific Player.static voidsendToServer(net.xmx.velthoric.network.IVxNetPacket packet) Sends a packet from the Client to the Server.
-
Constructor Details
-
Networking
public Networking()
-
-
Method Details
-
init
public static void init()Initializes the networking system.This method registers the single
RawPayloadtype 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 implementIVxNetPacket.- 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 aVxByteBuf.- 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.
-