What are you searching for?

puzzle-piece

Client-Server Communication API

Communication API for Fabric client and Paper server

download 4 Downloads · favorite 0 Followers · Updated 3 days ago
Fabric Paper 1.21.8 1.21.11

Versions

inventory_2
Client-Server Communication API 1.0

1.0 · 3 days ago · 14.27 KB

Release download
Paper 1.21.8
inventory_2
Client-Server Communication API 1.0

1.0 · 3 days ago · 13.46 KB

Release download
Fabric 1.21.8
inventory_2
Client-Server Communication API 1.0

1.0 · 3 days ago · 13.46 KB

Release download
Fabric 1.21.11
inventory_2
Client-Server Communication API 1.0

1.0 · 3 days ago · 14.27 KB

Release download
Paper 1.21.11

About

Client-Server Communication API

how to use for developer:

  • Register packet in common code:
public class FooBarPacket implements CscPacket{
    
    public FooBarPacket(ByteBuf buf) {
        read(buf);
    }

    private int foo;

    @Override
    public void read(ByteBuf buf) {
        foo = buf.readInt();
    }

    @Override
    public void write(ByteBuf buf) {
        buf.writeInt(foo);
    }
}
public static CscPacketType<FooBarPacket> FOO_BAR_PACKET = CscApi.registerPacket(
  "foo_bar", 
  FooBarPacket.class, 
  FooBarPacket::new
);
  • Use it on Server:
public class ServerClass {
    private static final Logger log = LoggerFactory.getLogger(ServerClass.class);

    public void init() {
        CscServer.getService().registerListener((packet, player) -> {
            log.info("Received packet {} from player {}", packet.getClass().getSimpleName(), player.getName());
        }, ModPackets.FOO_BAR_PACKET);
    }
    
    public void sendFooBarPacket(Player player) {
        CscServer.getService().sendPacket(new FooBarPacket(), player);
    }
}
  • Use it on Client:
public class ClientClass {
    private static final Logger log = LoggerFactory.getLogger(ClientClass.class);

    public void init() {
        CscClient.getService().registerListener(packet -> {
            log.info("Received packet: {}", packet);
        }, ModPackets.FOO_BAR_PACKET);
    }
    
    public void sendFooBarPacket() {
        CscClient.getService().sendPacket(new FooBarPacket());
    }
}
open_in_new View on Modrinth
Compatibility
Client: Required Server: Unsupported
gavel MIT

Conversation

What are your thoughts?

lock Cookie consent

SkinMC uses cookies to provide functionality and features.