use of dev.architectury.networking.NetworkManager.NetworkReceiver in project architectury-api by architectury.
the class NetworkManagerImpl method registerC2SReceiver.
private static void registerC2SReceiver(ResourceLocation id, List<PacketTransformer> packetTransformers, NetworkReceiver receiver) {
C2S_RECEIVER.put(id, receiver);
PacketTransformer transformer = PacketTransformer.concat(packetTransformers);
ServerPlayNetworking.registerGlobalReceiver(id, (server, player, handler, buf, sender) -> {
var context = context(player, server, false);
transformer.inbound(NetworkManager.Side.C2S, id, buf, context, (side, id1, buf1) -> {
NetworkReceiver networkReceiver = side == NetworkManager.Side.C2S ? C2S_RECEIVER.get(id1) : S2C_RECEIVER.get(id1);
if (networkReceiver == null) {
throw new IllegalArgumentException("Network Receiver not found! " + id1);
}
networkReceiver.receive(buf1, context);
});
});
C2S_TRANSFORMERS.put(id, transformer);
}
use of dev.architectury.networking.NetworkManager.NetworkReceiver in project architectury-api by architectury.
the class NetworkManagerImpl method registerS2CReceiver.
@SuppressWarnings("Convert2Lambda")
@Environment(EnvType.CLIENT)
private static void registerS2CReceiver(ResourceLocation id, List<PacketTransformer> packetTransformers, NetworkReceiver receiver) {
S2C_RECEIVER.put(id, receiver);
PacketTransformer transformer = PacketTransformer.concat(packetTransformers);
ClientPlayNetworking.registerGlobalReceiver(id, new ClientPlayNetworking.PlayChannelHandler() {
@Override
public void receive(Minecraft client, ClientPacketListener handler, FriendlyByteBuf buf, PacketSender sender) {
var context = context(client.player, client, true);
transformer.inbound(NetworkManager.Side.S2C, id, buf, context, (side, id1, buf1) -> {
NetworkReceiver networkReceiver = side == NetworkManager.Side.C2S ? C2S_RECEIVER.get(id1) : S2C_RECEIVER.get(id1);
if (networkReceiver == null) {
throw new IllegalArgumentException("Network Receiver not found! " + id1);
}
networkReceiver.receive(buf1, context);
});
}
});
S2C_TRANSFORMERS.put(id, transformer);
}
Aggregations