package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import javax.annotation.Nullable;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.Registry;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;

public class ClientboundOpenScreenPacket implements Packet<ClientGamePacketListener> {
    private int containerId;
    private int type;
    private Component title;
    
    public ClientboundOpenScreenPacket() {
    }
    
    public ClientboundOpenScreenPacket(final int integer, final MenuType<?> bbo, final Component lf) {
        this.containerId = integer;
        this.type = Registry.MENU.getId(bbo);
        this.title = lf;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.containerId = kv.readVarInt();
        this.type = kv.readVarInt();
        this.title = kv.readComponent();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.containerId);
        kv.writeVarInt(this.type);
        kv.writeComponent(this.title);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleOpenScreen(this);
    }
    
    public int getContainerId() {
        return this.containerId;
    }
    
    @Nullable
    public MenuType<?> getType() {
        return Registry.MENU.byId(this.type);
    }
    
    public Component getTitle() {
        return this.title;
    }
}
