package net.minecraft.network.protocol.login;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ClientboundCustomQueryPacket implements Packet<ClientLoginPacketListener> {
    private int transactionId;
    private ResourceLocation identifier;
    private FriendlyByteBuf data;
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.transactionId = kv.readVarInt();
        this.identifier = kv.readResourceLocation();
        final int integer3 = kv.readableBytes();
        if (integer3 < 0 || integer3 > 1048576) {
            throw new IOException("Payload may not be larger than 1048576 bytes");
        }
        this.data = new FriendlyByteBuf(kv.readBytes(integer3));
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.transactionId);
        kv.writeResourceLocation(this.identifier);
        kv.writeBytes(this.data.copy());
    }
    
    @Override
    public void handle(final ClientLoginPacketListener rh) {
        rh.handleCustomQuery(this);
    }
    
    public int getTransactionId() {
        return this.transactionId;
    }
}
