Fzzy Config

Networking

Fzzy Config (as of 0.4.x) includes a lightweight cross-loader networking API for play-phase networking. This API was designed to facilitate implementation of Fzzy Configs internal networking, but works perfectly well for third party applications that need a no-fuss API they can use on all mod loaders.

Registration

Fzzy Config works via the Payload concept introduced in recent Minecraft versions. For older versions of Fzzy Config, there is a FzzyPayload class used to take the place of the vanilla CustomPayload.

Register a networking interaction on both server and client (in common initializer) using either:

  • ConfigApi.network().registerS2C - client-bound packets originated on the server and handled on a client
  • ConfigApi.network().registerC2S - server-bound packets originated on a client and handled by the server

(For java users)

  • ConfigApiJava.INSTANCE.network().registerS2C
  • ConfigApiJava.INSTANCE.network().registerC2S

The handler parameter uses a custom Context wrapper that will have the lowest common denominator of methods between Fabric and Forge for that version. If some context you are used to is missing, blame the other loader.

Sending

To send a payload, simply use ConfigApi.network().canSend and ConfigApi.Network().send.

  • The player parameter determines which direction the sending will send. If the player instance is a ServerPlayerEntity, it will check/send for an S2C/client-bound direction. For a null player or a ClientPlayerEntity, it will send C2S/server-bound.

Example

// the custom payload class. Includes its ID and Codec. In practice the data won't be "Object"; just for illustration.
public class MyCustomPayload implements CustomPayload {
public MyCustomPayload(Object data1, Object data2){ /* implementation */ }
/* payload implementation here */
}
// registration of the payload for a server to client channel
// note that ClientPacketReceiver wouldn't have any client-only code in it. It's a go-between that would insulate the client code to another class during
// note the INSTANCE, required for java calls in this case
ConfigApiJava.INSTANCE.network().registerS2C(MyCustomPayload.TYPE, MyCustomPayload.CODEC, ClientPacketReceiver::handleMyCustomPayload);
//Handler example
class ClientPacketReceiver {
//insulating any client code that might be in ClientClassThatNeedsPayload
public static void handleMyCustomPayload(MyCustomPayload payload , ClientPlayNetworkContext context) {
ClientClassThatNeedsPayload.handle(payload.data1, payload.data2, context);
}
}
// example method for sending a payload to be received by the registered handler.
// note the INSTANCE, required for java calls in this case
public void myPayloadSender(ServerPlayerEntity player, Object data1, Object data2) {
if (ConfigApi.INSTANCE.network().canSend(MyCustomPayload.TYPE.id, player)) {
ConfigApi.INSTANCE.network().send(new MyCustomPayload(data1, data2), player);
}
}