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 mg) throws IOException {
        this.transactionId = mg.readVarInt();
        this.identifier = mg.readResourceLocation();
        final int integer3 = mg.readableBytes();
        if (integer3 < 0 || integer3 > 1048576) {
            throw new IOException("Payload may not be larger than 1048576 bytes");
        }
        this.data = new FriendlyByteBuf(mg.readBytes(integer3));
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.transactionId);
        mg.writeResourceLocation(this.identifier);
        mg.writeBytes(this.data.copy());
    }
    
    @Override
    public void handle(final ClientLoginPacketListener sw) {
        sw.handleCustomQuery(this);
    }
    
    public int getTransactionId() {
        return this.transactionId;
    }
}
