package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.LevelType;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.GameType;
import net.minecraft.network.protocol.Packet;

public class ClientboundLoginPacket implements Packet<ClientGamePacketListener> {
    private int playerId;
    private long seed;
    private boolean hardcore;
    private GameType gameType;
    private DimensionType dimension;
    private int maxPlayers;
    private LevelType levelType;
    private int chunkRadius;
    private boolean reducedDebugInfo;
    private boolean showDeathScreen;
    
    public ClientboundLoginPacket() {
    }
    
    public ClientboundLoginPacket(final int integer1, final GameType bjt, final long long3, final boolean boolean4, final DimensionType cbi, final int integer6, final LevelType bkd, final int integer8, final boolean boolean9, final boolean boolean10) {
        this.playerId = integer1;
        this.dimension = cbi;
        this.seed = long3;
        this.gameType = bjt;
        this.maxPlayers = integer6;
        this.hardcore = boolean4;
        this.levelType = bkd;
        this.chunkRadius = integer8;
        this.reducedDebugInfo = boolean9;
        this.showDeathScreen = boolean10;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.playerId = kv.readInt();
        int integer3 = kv.readUnsignedByte();
        this.hardcore = ((integer3 & 0x8) == 0x8);
        integer3 &= 0xFFFFFFF7;
        this.gameType = GameType.byId(integer3);
        this.dimension = DimensionType.getById(kv.readInt());
        this.seed = kv.readLong();
        this.maxPlayers = kv.readUnsignedByte();
        this.levelType = LevelType.getLevelType(kv.readUtf(16));
        if (this.levelType == null) {
            this.levelType = LevelType.NORMAL;
        }
        this.chunkRadius = kv.readVarInt();
        this.reducedDebugInfo = kv.readBoolean();
        this.showDeathScreen = kv.readBoolean();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeInt(this.playerId);
        int integer3 = this.gameType.getId();
        if (this.hardcore) {
            integer3 |= 0x8;
        }
        kv.writeByte(integer3);
        kv.writeInt(this.dimension.getId());
        kv.writeLong(this.seed);
        kv.writeByte(this.maxPlayers);
        kv.writeUtf(this.levelType.getName());
        kv.writeVarInt(this.chunkRadius);
        kv.writeBoolean(this.reducedDebugInfo);
        kv.writeBoolean(this.showDeathScreen);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleLogin(this);
    }
    
    public int getPlayerId() {
        return this.playerId;
    }
    
    public long getSeed() {
        return this.seed;
    }
    
    public boolean isHardcore() {
        return this.hardcore;
    }
    
    public GameType getGameType() {
        return this.gameType;
    }
    
    public DimensionType getDimension() {
        return this.dimension;
    }
    
    public LevelType getLevelType() {
        return this.levelType;
    }
    
    public int getChunkRadius() {
        return this.chunkRadius;
    }
    
    public boolean isReducedDebugInfo() {
        return this.reducedDebugInfo;
    }
    
    public boolean shouldShowDeathScreen() {
        return this.showDeathScreen;
    }
}
