Search in sources :

Example 1 with PacketTransformer

use of dev.architectury.networking.transformers.PacketTransformer 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);
}
Also used : NetworkReceiver(dev.architectury.networking.NetworkManager.NetworkReceiver) PacketTransformer(dev.architectury.networking.transformers.PacketTransformer)

Example 2 with PacketTransformer

use of dev.architectury.networking.transformers.PacketTransformer 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);
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation) NetworkReceiver(dev.architectury.networking.NetworkManager.NetworkReceiver) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) Environment(net.fabricmc.api.Environment) HashMap(java.util.HashMap) BlockableEventLoop(net.minecraft.util.thread.BlockableEventLoop) ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) NetworkManager(dev.architectury.networking.NetworkManager) List(java.util.List) Entity(net.minecraft.world.entity.Entity) Minecraft(net.minecraft.client.Minecraft) Map(java.util.Map) Env(dev.architectury.utils.Env) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketSink(dev.architectury.networking.transformers.PacketSink) EnvType(net.fabricmc.api.EnvType) Packet(net.minecraft.network.protocol.Packet) PacketTransformer(dev.architectury.networking.transformers.PacketTransformer) NetworkReceiver(dev.architectury.networking.NetworkManager.NetworkReceiver) PacketTransformer(dev.architectury.networking.transformers.PacketTransformer) ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) Minecraft(net.minecraft.client.Minecraft) Environment(net.fabricmc.api.Environment)

Example 3 with PacketTransformer

use of dev.architectury.networking.transformers.PacketTransformer in project architectury-api by architectury.

the class NetworkManagerImpl method registerS2CReceiver.

@OnlyIn(Dist.CLIENT)
public static void registerS2CReceiver(ResourceLocation id, List<PacketTransformer> packetTransformers, NetworkReceiver receiver) {
    S2C.put(id, receiver);
    PacketTransformer transformer = PacketTransformer.concat(packetTransformers);
    S2C_TRANSFORMERS.put(id, transformer);
}
Also used : PacketTransformer(dev.architectury.networking.transformers.PacketTransformer) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with PacketTransformer

use of dev.architectury.networking.transformers.PacketTransformer in project architectury-api by architectury.

the class NetworkManagerImpl method registerC2SReceiver.

public static void registerC2SReceiver(ResourceLocation id, List<PacketTransformer> packetTransformers, NetworkReceiver receiver) {
    C2S.put(id, receiver);
    PacketTransformer transformer = PacketTransformer.concat(packetTransformers);
    C2S_TRANSFORMERS.put(id, transformer);
}
Also used : PacketTransformer(dev.architectury.networking.transformers.PacketTransformer)

Aggregations

PacketTransformer (dev.architectury.networking.transformers.PacketTransformer)4 NetworkReceiver (dev.architectury.networking.NetworkManager.NetworkReceiver)2 NetworkManager (dev.architectury.networking.NetworkManager)1 PacketSink (dev.architectury.networking.transformers.PacketSink)1 Env (dev.architectury.utils.Env)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 EnvType (net.fabricmc.api.EnvType)1 Environment (net.fabricmc.api.Environment)1 ClientPlayNetworking (net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking)1 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)1 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)1 Minecraft (net.minecraft.client.Minecraft)1 ClientPacketListener (net.minecraft.client.multiplayer.ClientPacketListener)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 Packet (net.minecraft.network.protocol.Packet)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 BlockableEventLoop (net.minecraft.util.thread.BlockableEventLoop)1