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<?> bhk, final Component mr) {
        this.containerId = integer;
        this.type = Registry.MENU.getId(bhk);
        this.title = mr;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.containerId = mg.readVarInt();
        this.type = mg.readVarInt();
        this.title = mg.readComponent();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.containerId);
        mg.writeVarInt(this.type);
        mg.writeComponent(this.title);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleOpenScreen(this);
    }
    
    public int getContainerId() {
        return this.containerId;
    }
    
    @Nullable
    public MenuType<?> getType() {
        return Registry.MENU.byId(this.type);
    }
    
    public Component getTitle() {
        return this.title;
    }
}
