Search in sources :

Example 1 with ClientPacketListener

use of net.minecraft.client.multiplayer.ClientPacketListener in project MinecraftForge by MinecraftForge.

the class VanillaPacketSplitter method onClientPacket.

@SuppressWarnings("unchecked")
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event) {
    NetworkEvent.Context ctx = event.getSource().get();
    PacketFlow direction = ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT ? PacketFlow.CLIENTBOUND : PacketFlow.SERVERBOUND;
    ConnectionProtocol protocol = ConnectionProtocol.PLAY;
    ctx.setPacketHandled(true);
    FriendlyByteBuf buf = event.getPayload();
    byte state = buf.readByte();
    if (state == STATE_FIRST) {
        if (!receivedBuffers.isEmpty()) {
            LOGGER.warn("forge:split received out of order - inbound buffer not empty when receiving first");
            receivedBuffers.clear();
        }
    }
    // retain the buffer, it is released after this handler otherwise
    buf.retain();
    receivedBuffers.add(buf);
    if (state == STATE_LAST) {
        FriendlyByteBuf full = new FriendlyByteBuf(Unpooled.wrappedBuffer(receivedBuffers.toArray(new FriendlyByteBuf[0])));
        int packetId = full.readVarInt();
        Packet<?> packet = protocol.createPacket(direction, packetId, full);
        if (packet == null) {
            LOGGER.error("Received invalid packet ID {} in forge:split", packetId);
        } else {
            receivedBuffers.clear();
            full.release();
            ctx.enqueueWork(() -> ((Packet<ClientPacketListener>) packet).handle(Minecraft.getInstance().getConnection()));
        }
    }
}
Also used : ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener) PacketFlow(net.minecraft.network.protocol.PacketFlow)

Example 2 with ClientPacketListener

use of net.minecraft.client.multiplayer.ClientPacketListener in project MinecraftForge by MinecraftForge.

the class ForgeIngameGui method renderPlayerList.

protected void renderPlayerList(int width, int height, PoseStack mStack) {
    Objective scoreobjective = this.minecraft.level.getScoreboard().getDisplayObjective(0);
    ClientPacketListener handler = minecraft.player.connection;
    if (minecraft.options.keyPlayerList.isDown() && (!minecraft.isLocalServer() || handler.getOnlinePlayers().size() > 1 || scoreobjective != null)) {
        this.tabList.setVisible(true);
        if (pre(PLAYER_LIST, mStack))
            return;
        this.tabList.render(mStack, width, this.minecraft.level.getScoreboard(), scoreobjective);
        post(PLAYER_LIST, mStack);
    } else {
        this.tabList.setVisible(false);
    }
}
Also used : Objective(net.minecraft.world.scores.Objective) ClientPacketListener(net.minecraft.client.multiplayer.ClientPacketListener)

Aggregations

ClientPacketListener (net.minecraft.client.multiplayer.ClientPacketListener)2 PacketFlow (net.minecraft.network.protocol.PacketFlow)1 Objective (net.minecraft.world.scores.Objective)1