Search in sources :

Example 41 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.

the class ClientLoginNetworkAddon method handlePacket.

private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf originalBuf) {
    this.logger.debug("Handling inbound login response with id {} and channel with name {}", queryId, channelName);
    if (this.firstResponse) {
        // Register global handlers
        for (Map.Entry<Identifier, ClientLoginNetworking.QueryRequestReceiver> entry : ClientNetworkingImpl.LOGIN.getReceivers().entrySet()) {
            ClientLoginNetworking.registerReceiver(entry.getKey(), entry.getValue());
        }
        ClientLoginConnectionEvents.QUERY_START.invoker().onLoginQueryStart(this.handler, this.client);
        this.firstResponse = false;
    }
    @Nullable ClientLoginNetworking.QueryRequestReceiver handler = this.getHandler(channelName);
    if (handler == null) {
        return false;
    }
    PacketByteBuf buf = PacketByteBufs.slice(originalBuf);
    var futureListeners = new ArrayList<GenericFutureListener<? extends Future<? super Void>>>();
    try {
        CompletableFuture<@Nullable PacketByteBuf> future = handler.receive(this.client, this.handler, buf, futureListeners::add);
        future.thenAccept(result -> {
            var packet = new LoginQueryResponseC2SPacket(queryId, result);
            GenericFutureListener<? extends Future<? super Void>> listener = null;
            for (GenericFutureListener<? extends Future<? super Void>> each : futureListeners) {
                listener = FutureListeners.union(listener, each);
            }
            this.handler.getConnection().send(packet, listener);
        });
    } catch (Throwable ex) {
        this.logger.error("Encountered exception while handling in channel with name \"{}\"", channelName, ex);
        throw ex;
    }
    return true;
}
Also used : LoginQueryResponseC2SPacket(net.minecraft.network.packet.c2s.login.LoginQueryResponseC2SPacket) ArrayList(java.util.ArrayList) Identifier(net.minecraft.util.Identifier) PacketByteBuf(net.minecraft.network.PacketByteBuf) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) ClientLoginNetworking(org.quiltmc.qsl.networking.api.client.ClientLoginNetworking)

Example 42 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.

the class AbstractChanneledNetworkAddon method handle.

// always supposed to handle async!
protected boolean handle(Identifier channelName, PacketByteBuf originalBuf) {
    this.logger.debug("Handling inbound packet from channel with name \"{}\"", channelName);
    // Handle reserved packets
    if (NetworkingImpl.REGISTER_CHANNEL.equals(channelName)) {
        this.receiveRegistration(true, PacketByteBufs.slice(originalBuf));
        return true;
    }
    if (NetworkingImpl.UNREGISTER_CHANNEL.equals(channelName)) {
        this.receiveRegistration(false, PacketByteBufs.slice(originalBuf));
        return true;
    }
    @Nullable H handler = this.getHandler(channelName);
    if (handler == null) {
        return false;
    }
    PacketByteBuf buf = PacketByteBufs.slice(originalBuf);
    try {
        this.receive(handler, buf);
    } catch (Throwable ex) {
        this.logger.error("Encountered exception while handling in channel with name \"{}\"", channelName, ex);
        throw ex;
    }
    return true;
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.

the class NetworkingPlayPacketTest method sendToTestChannel.

public static void sendToTestChannel(ServerPlayerEntity player, String stuff) {
    PacketByteBuf buf = PacketByteBufs.create();
    buf.writeText(new LiteralText(stuff));
    ServerPlayNetworking.send(player, TEST_CHANNEL, buf);
    NetworkingTestMods.LOGGER.info("Sent custom payload packet in {}", TEST_CHANNEL);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) LiteralText(net.minecraft.text.LiteralText)

Example 44 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project Hypnotic-Client by Hypnotic-Development.

the class Criticals method getEntity.

public static Entity getEntity(PlayerInteractEntityC2SPacket packet) {
    PacketByteBuf packetBuf = new PacketByteBuf(Unpooled.buffer());
    packet.write(packetBuf);
    return mc.world.getEntityById(packetBuf.readVarInt());
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 45 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project Paradise-Lost by devs-immortal.

the class AetherNonLivingEntity method createSpawnPacket.

@Override
public final Packet<?> createSpawnPacket() {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    Identifier id = this.createSpawnPacket(buf);
    for (ServerPlayerEntity playerEntity : ((ServerWorld) this.world).getPlayers()) {
        ServerSidePacketRegistry.INSTANCE.sendToPlayer(playerEntity, id, buf);
    }
    return new EntitySpawnS2CPacket(this);
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Identifier(net.minecraft.util.Identifier) EntitySpawnS2CPacket(net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)158 PlayerEntity (net.minecraft.entity.player.PlayerEntity)40 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)18 Identifier (net.minecraft.util.Identifier)12 CustomPayloadS2CPacket (net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket)9 NbtCompound (net.minecraft.nbt.NbtCompound)7 CustomPayloadC2SPacket (net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)7 Inject (org.spongepowered.asm.mixin.injection.Inject)6 Environment (net.fabricmc.api.Environment)5 UUID (java.util.UUID)4 LivingEntity (net.minecraft.entity.LivingEntity)4 Nullable (org.jetbrains.annotations.Nullable)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 LiteralText (net.minecraft.text.LiteralText)3 GenderPlayer (com.wildfire.main.GenderPlayer)2 JSONSource (de.modprog.blockmeter.util.JSONSource)2 IHungerManager (de.siphalor.spiceoffabric.util.IHungerManager)2 HWGEntity (mod.azure.hwg.entity.HWGEntity)2 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)2