CCBlueX / LiquidBounce

A free mixin-based injection hacked client for Minecraft using the Fabric API
https://liquidbounce.net/
GNU General Public License v3.0
1.52k stars 488 forks source link

[FEATURE] Handling of BundlePacketS2C (git-a3dead3) #2553

Closed mumy-255 closed 8 months ago

mumy-255 commented 8 months ago

LiquidBounce Branch

Nextgen

Describe your feature request.

Due to optimizations in 1.20.2 (23w32a) on the network protocol, in some cases, multiple packets are bundled together and sent to the client at once to save bandwidth.

BundlePacket.java

public abstract class BundlePacket<T extends PacketListener> implements Packet<T> {
    private final Iterable<Packet<T>> packets;

    protected BundlePacket(Iterable<Packet<T>> packets) {
        this.packets = packets;
    }

    public final Iterable<Packet<T>> getPackets() {
        return this.packets;
    }

    public final void write(PacketByteBuf buf) {
    }
}

BundleS2CPacket.java


public class BundleS2CPacket extends BundlePacket<ClientPlayPacketListener> {
    public BundleS2CPacket(Iterable<Packet<ClientPlayPacketListener>> iterable) {
        super(iterable);
    }

    public void apply(ClientPlayPacketListener clientPlayPacketListener) {
        clientPlayPacketListener.onBundle(this);
    }
}

ClientPlayNetworkHandler.java

public class ClientPlayNetworkHandler extends ClientCommonNetworkHandler implements TickablePacketListener, ClientPlayPacketListener {

    //code...

    public void onBundle(BundleS2CPacket packet) {
         NetworkThreadUtils.forceMainThread(packet, this, this.client);
         Iterator var2 = packet.getPackets().iterator();

         while(var2.hasNext()) {
             Packet<ClientPlayPacketListener> packet2 = (Packet)var2.next();
             packet2.apply(this);
         }
     }

    //code...
}

However, PacketEvent still treats it as a single packet and does not trigger an event for each individual packet inside, which can lead to uncertainty and increase coding complexity in certain situations.

Therefore, it is recommended to adapt PacketEvent to handle this, and add a field to identify the BundlePacketS2C object to which this packet belongs. If there is none, it should be null.

Additional context

No response

1zun4 commented 8 months ago

I hope it should now handle the packets. :)